line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
2
|
|
|
2
|
|
1307
|
use 5.010001; |
|
2
|
|
|
|
|
8
|
|
3
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
50
|
|
4
|
2
|
|
|
2
|
|
9
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
43
|
|
5
|
2
|
|
|
2
|
|
1090
|
use utf8; |
|
2
|
|
|
|
|
26
|
|
|
2
|
|
|
|
|
9
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 'v2.3.8'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
83
|
use FindBin; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
112
|
|
10
|
2
|
|
|
2
|
|
12
|
use lib "$FindBin::Bin/../lib/perl5"; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
12
|
|
11
|
2
|
|
|
2
|
|
1205
|
use Narada; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
56
|
|
12
|
2
|
|
|
2
|
|
887
|
use Narada::Config qw( get_config set_config ); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
8
|
|
13
|
2
|
|
|
2
|
|
1130
|
use File::Temp qw( tempfile ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
84
|
|
14
|
2
|
|
|
2
|
|
11
|
use Cwd qw( cwd ); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
71
|
|
15
|
2
|
|
|
2
|
|
10
|
use Path::Tiny; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
2194
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
main(@ARGV) if !caller; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
4
|
|
|
4
|
|
34
|
sub err { die "narada-setup-qmail: @_\n" } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub main { |
24
|
17
|
100
|
100
|
17
|
|
2998512
|
die "Usage: narada-setup-qmail [--clean|--lock]\n" |
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
25
|
|
|
|
|
|
|
if (@_ > 1) |
26
|
|
|
|
|
|
|
|| (@_ == 1 && $_[0] ne '--clean' && $_[0] ne '--lock'); |
27
|
13
|
|
100
|
|
|
199
|
my $clean = @_ && $_[0] eq '--clean'; |
28
|
13
|
|
100
|
|
|
135
|
my $lock = @_ && $_[0] eq '--lock'; |
29
|
|
|
|
|
|
|
|
30
|
13
|
100
|
|
|
|
80
|
if ($clean) { |
31
|
5
|
|
|
|
|
112
|
path('var/use/qmail')->remove; |
32
|
5
|
|
|
|
|
1066
|
for my $file (ls_qmail()) { |
33
|
7
|
50
|
|
|
|
446
|
unlink $file or err "unlink($file): $!"; |
34
|
|
|
|
|
|
|
} |
35
|
5
|
|
|
|
|
128
|
unlink '.lock.qmail'; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
8
|
100
|
|
|
|
136
|
if (Narada::detect() eq 'narada') { |
39
|
7
|
|
|
|
|
78
|
path('var/use/qmail')->touch; |
40
|
|
|
|
|
|
|
} |
41
|
8
|
100
|
|
|
|
2176
|
if ($lock) { |
42
|
4
|
|
|
|
|
38
|
lock_qmail(); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
4
|
|
|
|
|
44
|
setup_qmail(); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
13
|
|
|
|
|
217
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub lock_qmail { |
53
|
4
|
|
|
4
|
|
9007
|
my $cwd = cwd(); |
54
|
4
|
|
|
|
|
74
|
my $lock = "$cwd/.lock.qmail"; |
55
|
4
|
|
|
|
|
87
|
replacefile($lock, '|false'); |
56
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
28
|
my $temp = 'tmp/.qmail.symlink'; |
58
|
4
|
|
|
|
|
66
|
unlink $temp; |
59
|
4
|
|
|
|
|
23
|
for my $qmail (ls_qmail()) { |
60
|
5
|
50
|
|
|
|
175
|
symlink $lock, $temp or err "symlink($lock,$temp): $!"; |
61
|
5
|
50
|
|
|
|
198
|
rename $temp, $qmail or err "rename($temp,$qmail): $!"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
4
|
|
|
|
|
41
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub setup_qmail { |
68
|
4
|
|
|
4
|
|
13217
|
my $cwd = cwd(); |
69
|
4
|
|
|
|
|
86
|
my $lock = "$cwd/.lock.qmail"; |
70
|
4
|
|
|
|
|
38
|
my $temp = 'tmp/.qmail.symlink'; |
71
|
4
|
|
|
|
|
105
|
unlink $temp; |
72
|
|
|
|
|
|
|
|
73
|
4
|
|
|
|
|
91
|
for my $file (ls('config/qmail')) { |
74
|
|
|
|
|
|
|
# read from config/qmail/ |
75
|
5
|
|
|
|
|
111
|
my $data = get_config("qmail/$file"); |
76
|
5
|
|
|
|
|
4706
|
$data =~ s/^[|]/|cd \Q$cwd\E || exit(100); /gmxs; |
77
|
|
|
|
|
|
|
# write to var/qmail/ |
78
|
5
|
|
|
|
|
20
|
my $path = "$cwd/var/qmail/$file"; |
79
|
5
|
|
|
|
|
33
|
replacefile($path, $data); |
80
|
|
|
|
|
|
|
# symlink at ~/.qmail- |
81
|
5
|
|
|
|
|
23
|
my $qmail = "$ENV{HOME}/.qmail-$file"; |
82
|
5
|
100
|
33
|
|
|
160
|
if (! -e $qmail) { |
|
|
50
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
83
|
4
|
50
|
|
|
|
118
|
symlink $path, $qmail or err "symlink($path,$qmail): $!"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif (-l $qmail && _readlink($qmail) eq $lock) { |
86
|
1
|
50
|
|
|
|
37
|
symlink $path, $temp or err "symlink($path,$temp): $!"; |
87
|
1
|
50
|
|
|
|
51
|
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
|
|
|
|
|
121
|
for my $file (grep {! -f "config/qmail/$_"} ls('var/qmail')) { |
|
10
|
|
|
|
|
164
|
|
96
|
5
|
50
|
|
|
|
213
|
unlink "var/qmail/$file" or err "unlink(var/qmail/$file): $!"; |
97
|
|
|
|
|
|
|
} |
98
|
4
|
|
|
|
|
108
|
unlink $lock; |
99
|
4
|
|
|
|
|
31
|
for my $file (grep {! -f} ls_qmail()) { |
|
10
|
|
|
|
|
196
|
|
100
|
5
|
50
|
|
|
|
212
|
unlink $file or err "unlink($file): $!"; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
4
|
|
|
|
|
56
|
return; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub ls_qmail { |
107
|
26
|
|
|
26
|
|
440277
|
my $cwd = cwd(); |
108
|
|
|
|
|
|
|
my @files = |
109
|
104
|
100
|
|
|
|
1706
|
grep {-l && _readlink($_) =~ m{\A\Q$cwd\E/}xms} |
110
|
104
|
|
|
|
|
343
|
map {"$ENV{HOME}/$_"} |
111
|
106
|
|
|
|
|
723
|
grep { m/\A[.]qmail-/xms } |
112
|
26
|
|
|
|
|
923
|
ls($ENV{HOME}); |
113
|
26
|
|
|
|
|
550
|
return @files; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub replacefile { |
117
|
23
|
|
|
23
|
|
11477
|
my ($file, $data) = @_; |
118
|
23
|
|
|
|
|
275
|
(my $dir = $file) =~ s{/[^/]+\z}{}xms; |
119
|
23
|
|
|
|
|
244
|
my ($fh, $temp) = tempfile(DIR => $dir); |
120
|
23
|
|
|
|
|
8521
|
print {$fh} $data; |
|
23
|
|
|
|
|
156
|
|
121
|
23
|
50
|
|
|
|
539
|
close $fh or err "close($temp): $!"; |
122
|
23
|
50
|
|
|
|
1355
|
rename $temp, $file or err "rename($temp,$file): $!"; |
123
|
23
|
|
|
|
|
166
|
return; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub ls { |
127
|
44
|
|
|
44
|
|
6537
|
my ($dir) = @_; |
128
|
44
|
100
|
|
|
|
2566
|
opendir my $d, $dir or err "opendir($dir): $!"; |
129
|
42
|
100
|
|
|
|
1174
|
my @files = grep { $_ ne q{.} && $_ ne q{..} } readdir $d; |
|
231
|
|
|
|
|
1273
|
|
130
|
42
|
50
|
|
|
|
562
|
closedir $d or err "closedir($dir): $!"; |
131
|
42
|
|
|
|
|
494
|
return @files; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub _readlink { |
135
|
89
|
|
|
89
|
|
3193
|
my ($link) = @_; |
136
|
89
|
100
|
|
|
|
1274
|
my $path = readlink $link or err "readlink($link): $!"; |
137
|
87
|
|
|
|
|
1128
|
return $path; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
142
|
|
|
|
|
|
|
__END__ |