line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#!/usr/bin/env perl |
2
|
2
|
|
|
2
|
|
1392
|
use 5.010001; |
|
2
|
|
|
|
|
6
|
|
3
|
2
|
|
|
2
|
|
8
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
76
|
|
4
|
2
|
|
|
2
|
|
8
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
35
|
|
5
|
2
|
|
|
2
|
|
1236
|
use utf8; |
|
2
|
|
|
|
|
19
|
|
|
2
|
|
|
|
|
12
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = 'v2.3.6'; |
8
|
|
|
|
|
|
|
|
9
|
2
|
|
|
2
|
|
85
|
use FindBin; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
103
|
|
10
|
2
|
|
|
2
|
|
905
|
use lib "$FindBin::Bin/../lib/perl5"; |
|
2
|
|
|
|
|
1242
|
|
|
2
|
|
|
|
|
14
|
|
11
|
2
|
|
|
2
|
|
1129
|
use Narada; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
60
|
|
12
|
2
|
|
|
2
|
|
1049
|
use Narada::Config qw( get_config set_config ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
8
|
|
13
|
2
|
|
|
2
|
|
1181
|
use File::Temp qw( tempfile ); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
101
|
|
14
|
2
|
|
|
2
|
|
9
|
use Cwd qw( cwd ); |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
74
|
|
15
|
2
|
|
|
2
|
|
8
|
use Path::Tiny; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
1931
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
main(@ARGV) if !caller; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
|
21
|
4
|
|
|
4
|
|
42
|
sub err { die "narada-setup-qmail: @_\n" } |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
sub main { |
24
|
17
|
100
|
100
|
17
|
|
2814851
|
die "Usage: narada-setup-qmail [--clean|--lock]\n" |
|
|
|
100
|
|
|
|
|
|
|
|
66
|
|
|
|
|
25
|
|
|
|
|
|
|
if (@_ > 1) |
26
|
|
|
|
|
|
|
|| (@_ == 1 && $_[0] ne '--clean' && $_[0] ne '--lock'); |
27
|
13
|
|
100
|
|
|
118
|
my $clean = @_ && $_[0] eq '--clean'; |
28
|
13
|
|
100
|
|
|
88
|
my $lock = @_ && $_[0] eq '--lock'; |
29
|
|
|
|
|
|
|
|
30
|
13
|
100
|
|
|
|
51
|
if ($clean) { |
31
|
5
|
|
|
|
|
50
|
path('var/use/qmail')->remove; |
32
|
5
|
|
|
|
|
666
|
for my $file (ls_qmail()) { |
33
|
7
|
50
|
|
|
|
498
|
unlink $file or err "unlink($file): $!"; |
34
|
|
|
|
|
|
|
} |
35
|
5
|
|
|
|
|
131
|
unlink '.lock.qmail'; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
else { |
38
|
8
|
100
|
|
|
|
55
|
if (Narada::detect() eq 'narada') { |
39
|
7
|
|
|
|
|
38
|
path('var/use/qmail')->touch; |
40
|
|
|
|
|
|
|
} |
41
|
8
|
100
|
|
|
|
1348
|
if ($lock) { |
42
|
4
|
|
|
|
|
13
|
lock_qmail(); |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
else { |
45
|
4
|
|
|
|
|
28
|
setup_qmail(); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
13
|
|
|
|
|
111
|
return; |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
sub lock_qmail { |
53
|
4
|
|
|
4
|
|
8025
|
my $cwd = cwd(); |
54
|
4
|
|
|
|
|
28
|
my $lock = "$cwd/.lock.qmail"; |
55
|
4
|
|
|
|
|
39
|
replacefile($lock, '|false'); |
56
|
|
|
|
|
|
|
|
57
|
4
|
|
|
|
|
13
|
my $temp = 'tmp/.qmail.symlink'; |
58
|
4
|
|
|
|
|
54
|
unlink $temp; |
59
|
4
|
|
|
|
|
13
|
for my $qmail (ls_qmail()) { |
60
|
5
|
50
|
|
|
|
175
|
symlink $lock, $temp or err "symlink($lock,$temp): $!"; |
61
|
5
|
50
|
|
|
|
233
|
rename $temp, $qmail or err "rename($temp,$qmail): $!"; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
4
|
|
|
|
|
29
|
return; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub setup_qmail { |
68
|
4
|
|
|
4
|
|
8900
|
my $cwd = cwd(); |
69
|
4
|
|
|
|
|
32
|
my $lock = "$cwd/.lock.qmail"; |
70
|
4
|
|
|
|
|
15
|
my $temp = 'tmp/.qmail.symlink'; |
71
|
4
|
|
|
|
|
87
|
unlink $temp; |
72
|
|
|
|
|
|
|
|
73
|
4
|
|
|
|
|
34
|
for my $file (ls('config/qmail')) { |
74
|
|
|
|
|
|
|
# read from config/qmail/ |
75
|
5
|
|
|
|
|
55
|
my $data = get_config("qmail/$file"); |
76
|
5
|
|
|
|
|
3537
|
$data =~ s/^[|]/|cd \Q$cwd\E || exit(100); /gmxs; |
77
|
|
|
|
|
|
|
# write to var/qmail/ |
78
|
5
|
|
|
|
|
16
|
my $path = "$cwd/var/qmail/$file"; |
79
|
5
|
|
|
|
|
19
|
replacefile($path, $data); |
80
|
|
|
|
|
|
|
# symlink at ~/.qmail- |
81
|
5
|
|
|
|
|
21
|
my $qmail = "$ENV{HOME}/.qmail-$file"; |
82
|
5
|
100
|
33
|
|
|
128
|
if (! -e $qmail) { |
|
|
50
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
83
|
4
|
50
|
|
|
|
124
|
symlink $path, $qmail or err "symlink($path,$qmail): $!"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
elsif (-l $qmail && _readlink($qmail) eq $lock) { |
86
|
1
|
50
|
|
|
|
88
|
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
|
|
|
|
|
22
|
for my $file (grep {! -f "config/qmail/$_"} ls('var/qmail')) { |
|
10
|
|
|
|
|
113
|
|
96
|
5
|
50
|
|
|
|
205
|
unlink "var/qmail/$file" or err "unlink(var/qmail/$file): $!"; |
97
|
|
|
|
|
|
|
} |
98
|
4
|
|
|
|
|
103
|
unlink $lock; |
99
|
4
|
|
|
|
|
14
|
for my $file (grep {! -f} ls_qmail()) { |
|
10
|
|
|
|
|
187
|
|
100
|
5
|
50
|
|
|
|
219
|
unlink $file or err "unlink($file): $!"; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
4
|
|
|
|
|
27
|
return; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub ls_qmail { |
107
|
26
|
|
|
26
|
|
334102
|
my $cwd = cwd(); |
108
|
|
|
|
|
|
|
my @files = |
109
|
104
|
100
|
|
|
|
1435
|
grep {-l && _readlink($_) =~ m{\A\Q$cwd\E/}xms} |
110
|
104
|
|
|
|
|
260
|
map {"$ENV{HOME}/$_"} |
111
|
106
|
|
|
|
|
450
|
grep { m/\A[.]qmail-/xms } |
112
|
26
|
|
|
|
|
297
|
ls($ENV{HOME}); |
113
|
26
|
|
|
|
|
285
|
return @files; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub replacefile { |
117
|
23
|
|
|
23
|
|
9095
|
my ($file, $data) = @_; |
118
|
23
|
|
|
|
|
174
|
(my $dir = $file) =~ s{/[^/]+\z}{}xms; |
119
|
23
|
|
|
|
|
125
|
my ($fh, $temp) = tempfile(DIR => $dir); |
120
|
23
|
|
|
|
|
6463
|
print {$fh} $data; |
|
23
|
|
|
|
|
109
|
|
121
|
23
|
50
|
|
|
|
543
|
close $fh or err "close($temp): $!"; |
122
|
23
|
50
|
|
|
|
1148
|
rename $temp, $file or err "rename($temp,$file): $!"; |
123
|
23
|
|
|
|
|
113
|
return; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub ls { |
127
|
44
|
|
|
44
|
|
4703
|
my ($dir) = @_; |
128
|
44
|
100
|
|
|
|
1711
|
opendir my $d, $dir or err "opendir($dir): $!"; |
129
|
42
|
100
|
|
|
|
939
|
my @files = grep { $_ ne q{.} && $_ ne q{..} } readdir $d; |
|
231
|
|
|
|
|
1057
|
|
130
|
42
|
50
|
|
|
|
347
|
closedir $d or err "closedir($dir): $!"; |
131
|
42
|
|
|
|
|
309
|
return @files; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub _readlink { |
135
|
89
|
|
|
89
|
|
2561
|
my ($link) = @_; |
136
|
89
|
100
|
|
|
|
908
|
my $path = readlink $link or err "readlink($link): $!"; |
137
|
87
|
|
|
|
|
905
|
return $path; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
142
|
|
|
|
|
|
|
__END__ |