line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
2
|
|
|
2
|
|
1598
|
use 5.010001; |
|
2
|
|
|
|
|
4
|
|
3
|
2
|
|
|
2
|
|
7
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
63
|
|
4
|
2
|
|
|
2
|
|
6
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
33
|
|
5
|
2
|
|
|
2
|
|
1138
|
use utf8; |
|
2
|
|
|
|
|
17
|
|
|
2
|
|
|
|
|
10
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 'v2.3.7'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
77
|
use FindBin; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
106
|
|
10
|
2
|
|
|
2
|
|
780
|
use lib "$FindBin::Bin/../lib/perl5"; |
|
2
|
|
|
|
|
1183
|
|
|
2
|
|
|
|
|
13
|
|
11
|
2
|
|
|
2
|
|
1020
|
use Narada; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
49
|
|
12
|
2
|
|
|
2
|
|
951
|
use Narada::Config qw( get_config set_config ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
9
|
|
13
|
2
|
|
|
2
|
|
1112
|
use File::Temp qw( tempfile ); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
102
|
|
14
|
2
|
|
|
2
|
|
7
|
use Cwd qw( cwd ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
90
|
|
15
|
2
|
|
|
2
|
|
8
|
use Path::Tiny; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2071
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
main(@ARGV) if !caller; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
4
|
|
|
4
|
|
33
|
sub err { die "narada-setup-qmail: @_\n" } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub main { |
24
|
17
|
100
|
100
|
17
|
|
2653088
|
die "Usage: narada-setup-qmail [--clean|--lock]\n" |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
25
|
|
|
|
|
|
|
if (@_ > 1) |
26
|
|
|
|
|
|
|
|| (@_ == 1 && $_[0] ne '--clean' && $_[0] ne '--lock'); |
27
|
13
|
|
100
|
|
|
96
|
my $clean = @_ && $_[0] eq '--clean'; |
28
|
13
|
|
100
|
|
|
63
|
my $lock = @_ && $_[0] eq '--lock'; |
29
|
|
|
|
|
|
|
|
30
|
13
|
100
|
|
|
|
48
|
if ($clean) { |
31
|
5
|
|
|
|
|
50
|
path('var/use/qmail')->remove; |
32
|
5
|
|
|
|
|
492
|
for my $file (ls_qmail()) { |
33
|
7
|
50
|
|
|
|
275
|
unlink $file or err "unlink($file): $!"; |
34
|
|
|
|
|
|
|
} |
35
|
5
|
|
|
|
|
92
|
unlink '.lock.qmail'; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
8
|
100
|
|
|
|
59
|
if (Narada::detect() eq 'narada') { |
39
|
7
|
|
|
|
|
46
|
path('var/use/qmail')->touch; |
40
|
|
|
|
|
|
|
} |
41
|
8
|
100
|
|
|
|
1189
|
if ($lock) { |
42
|
4
|
|
|
|
|
19
|
lock_qmail(); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
4
|
|
|
|
|
21
|
setup_qmail(); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
13
|
|
|
|
|
72
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub lock_qmail { |
53
|
4
|
|
|
4
|
|
6993
|
my $cwd = cwd(); |
54
|
4
|
|
|
|
|
27
|
my $lock = "$cwd/.lock.qmail"; |
55
|
4
|
|
|
|
|
32
|
replacefile($lock, '|false'); |
56
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
11
|
my $temp = 'tmp/.qmail.symlink'; |
58
|
4
|
|
|
|
|
53
|
unlink $temp; |
59
|
4
|
|
|
|
|
12
|
for my $qmail (ls_qmail()) { |
60
|
5
|
50
|
|
|
|
151
|
symlink $lock, $temp or err "symlink($lock,$temp): $!"; |
61
|
5
|
50
|
|
|
|
213
|
rename $temp, $qmail or err "rename($temp,$qmail): $!"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
4
|
|
|
|
|
22
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub setup_qmail { |
68
|
4
|
|
|
4
|
|
7486
|
my $cwd = cwd(); |
69
|
4
|
|
|
|
|
23
|
my $lock = "$cwd/.lock.qmail"; |
70
|
4
|
|
|
|
|
12
|
my $temp = 'tmp/.qmail.symlink'; |
71
|
4
|
|
|
|
|
75
|
unlink $temp; |
72
|
|
|
|
|
|
|
|
73
|
4
|
|
|
|
|
32
|
for my $file (ls('config/qmail')) { |
74
|
|
|
|
|
|
|
# read from config/qmail/ |
75
|
5
|
|
|
|
|
59
|
my $data = get_config("qmail/$file"); |
76
|
5
|
|
|
|
|
2994
|
$data =~ s/^[|]/|cd \Q$cwd\E || exit(100); /gmxs; |
77
|
|
|
|
|
|
|
# write to var/qmail/ |
78
|
5
|
|
|
|
|
17
|
my $path = "$cwd/var/qmail/$file"; |
79
|
5
|
|
|
|
|
14
|
replacefile($path, $data); |
80
|
|
|
|
|
|
|
# symlink at ~/.qmail- |
81
|
5
|
|
|
|
|
16
|
my $qmail = "$ENV{HOME}/.qmail-$file"; |
82
|
5
|
100
|
33
|
|
|
154
|
if (! -e $qmail) { |
|
|
50
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
83
|
4
|
50
|
|
|
|
129
|
symlink $path, $qmail or err "symlink($path,$qmail): $!"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif (-l $qmail && _readlink($qmail) eq $lock) { |
86
|
1
|
50
|
|
|
|
72
|
symlink $path, $temp or err "symlink($path,$temp): $!"; |
87
|
1
|
50
|
|
|
|
43
|
rename $temp, $qmail or err "rename($temp,$qmail): $!"; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
elsif (! (-l $qmail && _readlink($qmail) eq $path)) { |
90
|
0
|
|
|
|
|
0
|
err "Conflict detected on $qmail"; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# cleanup |
95
|
4
|
|
|
|
|
18
|
for my $file (grep {! -f "config/qmail/$_"} ls('var/qmail')) { |
|
10
|
|
|
|
|
99
|
|
96
|
5
|
50
|
|
|
|
198
|
unlink "var/qmail/$file" or err "unlink(var/qmail/$file): $!"; |
97
|
|
|
|
|
|
|
} |
98
|
4
|
|
|
|
|
93
|
unlink $lock; |
99
|
4
|
|
|
|
|
16
|
for my $file (grep {! -f} ls_qmail()) { |
|
10
|
|
|
|
|
160
|
|
100
|
5
|
50
|
|
|
|
182
|
unlink $file or err "unlink($file): $!"; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
4
|
|
|
|
|
19
|
return; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub ls_qmail { |
107
|
26
|
|
|
26
|
|
288723
|
my $cwd = cwd(); |
108
|
|
|
|
|
|
|
my @files = |
109
|
104
|
100
|
|
|
|
1167
|
grep {-l && _readlink($_) =~ m{\A\Q$cwd\E/}xms} |
110
|
104
|
|
|
|
|
199
|
map {"$ENV{HOME}/$_"} |
111
|
106
|
|
|
|
|
311
|
grep { m/\A[.]qmail-/xms } |
112
|
26
|
|
|
|
|
237
|
ls($ENV{HOME}); |
113
|
26
|
|
|
|
|
240
|
return @files; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub replacefile { |
117
|
23
|
|
|
23
|
|
7866
|
my ($file, $data) = @_; |
118
|
23
|
|
|
|
|
157
|
(my $dir = $file) =~ s{/[^/]+\z}{}xms; |
119
|
23
|
|
|
|
|
119
|
my ($fh, $temp) = tempfile(DIR => $dir); |
120
|
23
|
|
|
|
|
5758
|
print {$fh} $data; |
|
23
|
|
|
|
|
99
|
|
121
|
23
|
50
|
|
|
|
614
|
close $fh or err "close($temp): $!"; |
122
|
23
|
50
|
|
|
|
1180
|
rename $temp, $file or err "rename($temp,$file): $!"; |
123
|
23
|
|
|
|
|
100
|
return; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub ls { |
127
|
44
|
|
|
44
|
|
4024
|
my ($dir) = @_; |
128
|
44
|
100
|
|
|
|
1208
|
opendir my $d, $dir or err "opendir($dir): $!"; |
129
|
42
|
100
|
|
|
|
763
|
my @files = grep { $_ ne q{.} && $_ ne q{..} } readdir $d; |
|
231
|
|
|
|
|
821
|
|
130
|
42
|
50
|
|
|
|
314
|
closedir $d or err "closedir($dir): $!"; |
131
|
42
|
|
|
|
|
236
|
return @files; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub _readlink { |
135
|
89
|
|
|
89
|
|
2599
|
my ($link) = @_; |
136
|
89
|
100
|
|
|
|
736
|
my $path = readlink $link or err "readlink($link): $!"; |
137
|
87
|
|
|
|
|
720
|
return $path; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
142
|
|
|
|
|
|
|
__END__ |