forked from rafl/module-signature
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile.PL
180 lines (142 loc) · 4.24 KB
/
Makefile.PL
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
use inc::Module::Install 0.92;
$|++;
name 'Module-Signature';
license 'CC0';
all_from 'lib/Module/Signature.pm';
readme_from 'lib/Module/Signature.pm';
repository 'http://github.com/audreyt/module-signature';
install_script 'script/cpansign';
build_requires 'Test::More', 0, 'IPC::Run', 0;
# On Win32 (excluding cygwin) we know that IO::Socket::INET,
# which is needed for keyserver stuff, doesn't work. In fact
# it potentially hangs forever. So bail out with a N/A on
# Win32.
if ( $^O eq 'MSWin32' and 0 ) {
print "Keyserver behaviour is dangerous unreliable on Win32\n";
print "Not installing on this platform.\n";
exit(255);
} else {
requires 'IO::Socket::INET' => 0;
}
# We will need something to handle SHA1/256
unless (
can_use('Digest::SHA') or
can_use('Digest::SHA::PurePerl') or
(can_use('Digest::SHA1') and can_use('Digest::SHA256'))
) {
# Nothing installed, we need to install a digest module
if ( can_cc() ) {
requires 'Digest::SHA';
} else {
requires 'Digest::SHA::PurePerl';
}
}
# The list of OpenPGP dependencies (which we use in several places)
my @OPEN_PGP = qw{
MIME::Base64 0
Compress::Zlib 0
Crypt::CBC 0
Crypt::DES 0
Crypt::Blowfish 0
Crypt::RIPEMD160 0
Tie::EncryptedHash 0
Class::Loader 0
Convert::ASCII::Armour 0
Data::Buffer 0.04
Digest::MD2 0
Math::Pari 0
Crypt::Random 0
Crypt::Primes 0
Crypt::DES_EDE3 0
Crypt::DSA 0
Crypt::RSA 0
Convert::ASN1 0
Convert::PEM 0
Crypt::OpenPGP 1.00
};
# Is openpgp currently installed
if ( can_use('Crypt::OpenPGP') ) {
# If OpenPGP is already installed, so relist all the
# dependencies so they will upgrade as needed.
requires( @OPEN_PGP );
} elsif ( locate_gpg() ) {
# We SHOULD have gpg, double-check formally
requires_external_bin 'gpg';
} elsif ( can_cc() and $ENV{AUTOMATED_TESTING} ) {
# Dive headlong into a full Crypt::OpenPGP install.
requires( @OPEN_PGP );
} else {
# Ask the user what to do
ask_user();
}
unless ( can_run('diff') ) {
# We know Text::Diff fails on Cygwin (for now)
if ( $^O ne 'Cygwin' ) {
requires 'Algorithm::Diff';
requires 'Text::Diff';
}
}
sign; WriteAll;
#####################################################################
# Support Functions
sub locate_gpg {
print "Looking for GNU Privacy Guard (gpg), a cryptographic signature tool...\n";
my $gpg = can_run('gpg');
my $has_gpg = (
$gpg and
`gpg --version` =~ /GnuPG/
);
unless ( $has_gpg ) {
print "gpg not found.\n";
return;
}
print "GnuPG found ($gpg).\n";
return 1 if grep { /^--installdeps/} @ARGV;
if ( prompt("Import PAUSE and author keys to GnuPG?", 'y' ) =~ /^y/i) {
print 'Importing... ';
system 'gpg', '--quiet', '--import', glob('*.pub');
print "done.\n";
}
return 1;
}
sub ask_user {
# Defined the prompt messages
my $message1 = <<'END_MESSAGE';
Could not auto-detect a signature utility on your system.
What do you want me to do?
1) Let you install GnuPG manually while I'm waiting for your answer;
it is available at http://www.gnupg.org/download/ or may be available
from your platforms packaging system (for Open Source platforms).
END_MESSAGE
my $message2 = <<'END_MESSAGE';
2) Automatically install Crypt::OpenPGP and the 20 modules it requires
from CPAN, which will give the same functionality as GnuPG.
END_MESSAGE
# Present the options
print $message1;
my $option3 = 2;
if ( can_cc() ) {
$option3 = 3;
print $message2;
}
print <<"END_MESSAGE";
$option3) Forget this cryptographic signature stuff for now.
END_MESSAGE
my $choice;
foreach ( 1 .. 3 ) {
$choice = prompt("Your choice:", 3) || 3;
last if $choice =~ /^[123]$/;
print "Sorry, I cannot understand '$choice'.\n"
}
if ( $choice == 1 ) {
# They claim to have installed gpg
requires_external_bin 'gpg';
} elsif ( $choice == 2 and $option3 == 3 ) {
# They want to install Crypt::OpenPGP
requires( @OPEN_PGP );
} else {
# Forget about it...
print "Module::Signature is not wanted on this host.\n";
exit(0);
}
}