/
gpg-debian
executable file
·78 lines (62 loc) · 1.43 KB
/
gpg-debian
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/perl -w
(my $email='ch%christianjaeger,ch')=~ tr/%,/@./;
use strict; use warnings FATAL => 'uninitialized';
my @keyrings= glob "/usr/share/keyrings/*.gpg";
$0=~ /(.*?)([^\/]+)\z/s or die "?";
my ($mydir, $myname)=($1,$2);
sub usage {
print STDERR map{"$_\n"} @_ if @_;
print "$myname $myname args...
Invoke gpg with all the keyrings that Debian (as of >etch) provides
and which are installed on the running system, which are:
".join("\n ", @keyrings)."
Options:
--verbose
(Christian Jaeger <$email>)
";
exit (@_ ? 1 : 0);
}
usage if (@ARGV and $ARGV[0] =~ /^--?h(elp)?$/);
my $verbose = (@ARGV and $ARGV[0] =~ /^--verbose$/);
shift @ARGV if $verbose;
use Chj::xperlfunc ':all';
use Chj::xhome;
sub path2copypath {
my ($path)=@_;
my $fn= basename $path;
xhome . "/.gnupg/".$fn
}
sub copy {
my ($from,$to,$exists)=@_;
if ($exists) {
xrename $to, $to."~";
}
xxsystem "cp","--",$from,$to
}
for my $path (@keyrings) {
my $cpath= path2copypath $path;
my $a= xstat $path;
if (my $b= Xlstat $cpath) {
$b->is_file or die "exists but is not a file: '$cpath'";
if ($a->mtime > $b->mtime
or
$a->ctime > $b->ctime) {
copy ($path,$cpath,1)
}
} else {
copy ($path,$cpath,0)
}
}
my @cmd = (
"gpg",
(
map {
("--keyring", path2copypath($_))
} @keyrings
),
@ARGV
);
if ($verbose) {
print STDERR "+ @cmd\n";
}
xexec @cmd;