This repository has been archived by the owner on Oct 15, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
install2.pl
347 lines (281 loc) · 9.62 KB
/
install2.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
#!/usr/bin/env perl
#
# This script installs anything required to contribute Zero-click Info to DuckDuckGo
# In general:
#
# It installs local::lib if not one is already active (or perlbrew)
# It installs App::cpanminus and App::DuckPAN
# It uses duckpan to install DDG (duckpan DDG)
# It runs: duckpan check
#
$|=1;
use strict;
use warnings;
use 5.008;
use CPAN;
use Cwd;
use File::Spec;
use File::Temp qw/ tempfile tempdir /;
use HTTP::Tiny;
if (lc($^O) eq 'mswin32') {
print_text(
"",
"[ERROR] We dont support Win32.. sorry :(",
""
);
exit 1;
} elsif (lc($^O) ne 'linux') {
print_text(
"",
"[WARNING] We don't support anything other than Linux, but you can try if you're determined. Please consider getting some sort of Linux system, e.g. a virtual machine with VMware or VirtualBox, or a cloud server at linode or amazon (amazon has a free micro instance for a year). You can stop the installation with Ctrl-C now if you don't want to try the install. If you're having a lot of trouble getting duckpan to work with other operating systems, ask us on IRC at #duckduckgo",
""
);
print_wait(10);
}
if (getpwnam($ENV{USER}) == 0) {
print_text(
"",
"[ERROR] DO NOT DO THIS AS ROOT! PLEASE USE A NORMAL USER ACCOUNT!",
""
);
exit 1;
}
print "\n";
print ' ____ _ ____ _ ____'."\n";
print '| _ \\ _ _ ___| | _| _ \\ _ _ ___| | __/ ___| ___'."\n";
print '| | | | | | |/ __| |/ / | | | | | |/ __| |/ / | _ / _ \\'."\n";
print '| |_| | |_| | (__| <| |_| | |_| | (__| <| |_| | (_) |'."\n";
print '|____/ \\__,_|\\___|_|\\_\\____/ \\__,_|\\___|_|\\_\\\\____|\\___/'."\n";
print '========================================================='."\n";
my $_cpanm;
my $_cpanm_filename;
my $set_locallib;
my $extraline = 'eval $(perl -I${HOME}/perl5/lib/perl5 -Mlocal::lib)';
my $bash_conf_file = lc($^O) eq "darwin" ? '.bash_profile' : '.bashrc';
my $bashrc = File::Spec->catfile($ENV{HOME}, $bash_conf_file);
if ($ENV{PERL_LOCAL_LIB_ROOT} || $ENV{PERL_MM_OPT} || $ENV{PERL_MB_OPT}) {
print_text(
"Found running local::lib...",
"We don't use local::lib anymore, and require you to remove the local::lib calls from your shell startup file, so that we can replace it with perlbrew.",
);
if ($ENV{SHELL} eq '/bin/bash') {
open(my $bfh_read,'<', $bashrc);
open(my $bfh_write,'>>', $bashrc);
my @found = grep { chomp($_); $_ eq $extraline } <$bfh_read>;
if (@found) {
print_text(
"Found entry for local::lib in $bash_conf_file",
"Edit this file and remove the line",
"",
$extraline,
"",
"from it, then restart this script!",
);
exit 1;
} else {
print_text(
"You use bash, but we weren't able to find the local::lib startup line in your $bash_conf_file",
);
}
close($bfh_read);
close($bfh_write);
}
print_text(
"We consider you know what you do, and so please restart this script, after you removed local::lib from your startup file.",
);
exit 1;
} elsif (!defined $ENV{PERLBREW_PATH}) {
print_text(
"",
"Installing perlbrew...",
""
);
cpanminus_install_error() if (system("perl ".cpanminus()." -n -l ".$set_locallib." local::lib App::cpanminus"));
my $bash_conf_file = lc($^O) eq "darwin" ? '.bash_profile' : '.bashrc';
my $bashrc = File::Spec->catfile($ENV{HOME}, $bash_conf_file);
if ($ENV{SHELL} eq '/bin/bash') {
open(my $bfh_read,'<', $bashrc);
open(my $bfh_write,'>>', $bashrc);
my @found = grep { chomp($_); $_ eq $extraline } <$bfh_read>;
if (@found) {
print_text("Found entry for local::lib in $bash_conf_file");
} else {
print_text("Adding entry for local::lib to $bash_conf_file");
print $bfh_write "\n\n";
print $bfh_write "# added by duckpan installer\n";
print $bfh_write $extraline;
print $bfh_write "\n\n";
}
close($bfh_read);
close($bfh_write);
} else {
print_text(
"",
"You don't use bash, so we assume that you know what you're doing -- please add this line to the startup script of your shell:",
$extraline,
"so that local::lib is active after you relogin.",
""
);
print_wait(5);
}
}
unless ($ENV{PERLBREW_PATH}) {
print_text(
"============================================================",
"local::lib (or perlbrew) is not active. If you ran this script for the first time, please re-login to your user account or reload your shell configuration and run it again!",
"",
);
exit 1;
}
my $cpanm = `which cpanm`;
unless ($cpanm) {
print_text("Installing cpanminus ...","");
cpanminus_install_error() if (system("perl ".cpanminus()." -n App::cpanminus"));
}
print_text(
"Installing App::DuckPAN...",
"[WARNING] This may take a while :-)",
"",
);
cpanminus_install_error() if (system('cpanm Module::Finder Module::Extract::VERSION'));
cpanminus_install_error() if (system('cpanm -n namespace::autoclean Moose'));
if ( eval { system('cpanm NANIS/Crypt-SSLeay-0.59_03.tar.gz') } ) {
print_text(
"",
"--------------------------------------",
"",
"[ERROR] There was an error installing Crypt::SSLeay.",
"Crypt::SSLeay needs the package libssl-dev to install properly. If you don't have this package installed on your system, it could be why you're seeing this error. To install it on Debian or Ubuntu, run:",
"sudo apt-get install libssl-dev",
"This may have just been a download error. If you're unsure, try running this script again.",
"",
"--------------------------------------",
""
);
exit 1;
}
cpanminus_install_error() if (system('cpanm App::DuckPAN'));
print_text(
"Installing DDG...",
"[WARNING] This may take a while :-)",
"",
);
cpanminus_install_error() if (system('duckpan DDG'));
print_text("Checking other requirements ...","");
if (system("duckpan check")) {
print_text(
"",
"[ERROR] Failure on requirement check!",
"Please fix the problem, or email us at open\@duckduckgo.com with the screen output attached",
""
);
exit 1;
}
print_text(
"============================================================",
"Read our other tutorials for the next steps.",
""
);
sub cpanminus_install_error {
print_text(
"[ERROR] Failure on install of modules!",
"This could have several reasons, for first you can just restart this installer, cause it could be a pure download problem. If this isnt the case, please read the build.log mentioned on the errors and see if you can fix the problem yourself. Otherwise, please report the problem via email to use at open\@duckduckgo.com with the build.log attached. If there is no build.log mentioned, just attach the output you see.",
""
);
exit 1;
}
sub print_wait {
my $no = shift;
print "Please wait ".$no." sec.: ";
for (1..$no) {
print "."; sleep 1;
}
print "\n\n";
}
sub print_text {
for (@_) {
print "\n";
my @words = split(/\s+/,$_);
my $current_line = "";
for (@words) {
if ((length $current_line) + (length $_) < 79) {
$current_line .= " " if length $current_line;
$current_line .= $_;
} else {
print $current_line."\n";
$current_line = $_;
}
}
print $current_line."\n" if length $current_line;
}
}
sub cpanminus {
unless ($_cpanm) {
my $cpanm_url = 'http://duckpan.org/cpanm';
print "\nFetching cpanminus from ".$cpanm_url." ...\n";
($_cpanm, $_cpanm_filename) = tempfile();
my $http = HTTP::Tiny->new;
my $response = $http->get($cpanm_url);
unless ($response->{success}) {
print "\nDownloading of cpanminus failed! Please try again later!\n";
exit 1;
}
my $content = $response->{content};
print $_cpanm $content;
chmod 0755, $_cpanm_filename;
close($_cpanm);
}
return $_cpanm_filename;
}
1;
__END__
my $github = prompt("Your GitHub username?");
print "\n";
unless (length $github) {
print_text("This is not a valid GitHub username, please restart the installer.", "");
exit 1;
}
if (<$ENV{HOME}/.ssh/id_*.pub>) {
print_text("Found a public ssh key, I assume you know what you are doing.");
} else {
print_text("Can't find a public ssh key, assuming that you don't have one yet","");
my $genkey = prompt("Do you want me to generate a key for you?","yes");
if (lc($genkey) eq 'yes') {
print_text(
"",
"Follow the instructions of the ssh key generator. We suggest that you don't set a passphrase and dont change the suggestion filename for the generated key",
""
);
if (system('ssh-keygen')) {
print_text("There was a failure on during the generation of the ssh key -- if you can't solve it, please email us at open\@duckduckgo.com");
exit 1;
}
print_text(
"",
"Now add the generated key to your GitHub account at the URL:",
"https://github.com/settings/ssh",
"Your key is:",
`cat $ENV{HOME}/.ssh/id_rsa.pub`,
""
);
}
}
print "\n";
my $zcig = prompt("Clone to which directory?",$ENV{HOME}.'/zeroclickinfo-goodies');
print "\n";
my $giturl = "git\@github.com:".$github."/zeroclickinfo-goodies.git";
if (-d $zcig) {
print "\nDirectory already exist, assuming you have cloned already...\n";
} else {
print "\nCloning zeroclickinfo-goodies...\n";
if (system('git clone '.$giturl.' '.$zcig)) {
print "\n\nFailure on cloning! Please fix the problem, or email us";
print "\nat open\@duckduckgo.com with the screen output attached\n";
exit 1;
}
}
chdir($zcig);
print "\nInstalling Distribution requirements...\n";
print "\n[WARNING] This may take a while :-)\n\n";
cpanminus_install_error() if (system('dzil authordeps --missing | cpanm'));
cpanminus_install_error() if (system('dzil listdeps --missing | cpanm'));