mv netinstaller to bp_* and change docs accordingly
[bioperl-live.git] / scripts / utilities / bp_netinstall.pl
blob6ccf7db21009bfbba4065b549dd3209a6e791783
1 #!/usr/bin/perl
3 =head1 NAME
5 bp_netinstall.pl
7 =head1 SYNOPSIS
9 bp_netinstall.pl -b|--build_param_str BUILD_STRING [options]
11 options:
13 -h|--help Show this message
14 -d|--dev Use the developement version of bioperl from git
15 --build_param_str=<args> Parameters that are passed in at 'perl Build.PL'
16 --install_param_str=<args>
17 Use this string to predefine './Build install'
18 parameters such as 'install_base' for
19 bioperl installation
20 --bioperl_path Path to BioPerl tarball (will not download BioPerl)
21 --skip_start Don't wait for 'Enter' at program start
23 =head1 DESCRIPTION
25 Net-based installer of BioPerl; this is based on the GBrowse netinstaller
26 and hopefully all references to GBrowse have been removed. Let me know if not.
28 Save this to disk as "bp_netinstall.pl" and run:
30 [sudo] perl bp_netinstall.pl
32 =head1 AUTHOR
34 Scott Cain scain@cpan.org
36 =head1 COPYRIGHT
38 2010. This script may be distributed under the same license as perl.
40 =cut
44 # Universal Net-based installer
45 # Save this to disk as "bp_netinstall.pl" and run:
46 # perl bp_netinstall.pl
48 use warnings;
49 use strict;
50 use CPAN '!get';
51 use Config;
52 use Getopt::Long;
53 use Pod::Usage;
54 use File::Copy qw( cp move );
55 use File::Temp qw(tempdir);
56 use LWP::Simple;
57 use Cwd;
59 use constant NMAKE => 'http://download.microsoft.com/download/vc15/patch/1.52/w95/en-us/nmake15.exe';
61 my ( $show_help, $get_from_cvs, $build_param_string, $working_dir,
62 $get_bioperl_svn, $is_cygwin, $windows,
63 $binaries, $make, $tmpdir, $bioperl_path,
64 $skip_start, $install_param_string, $perl_path);
66 BEGIN {
68 GetOptions(
69 'h|help' => \$show_help, # Show help and exit
70 'd|dev' => \$get_from_cvs, # Use the dev svn
71 'build_param_str=s' => \$build_param_string, # Build parameters
72 'bioperl_dev' => \$get_bioperl_svn,
73 'bioperl_path=s' => \$bioperl_path,
74 'install_param_str=s' => \$install_param_string,
75 'skip_start' => \$skip_start,
77 or pod2usage(2);
78 pod2usage(2) if $show_help;
80 $perl_path = $Config{perlpath};
82 print STDERR "\nAbout to install BioPerl and all its prerequisites.\n";
83 print STDERR "\nYou will be asked various questions during this process. You can almost always";
84 print STDERR "\naccept the default answer.\n";
85 print STDERR "The whole process will take several minutes and will generate lots of messages.\n";
86 print STDERR "\nPress return when you are ready to start!\n";
87 my $h = <> unless $skip_start;
88 print STDERR "*** Installing Perl files needed for a net-based install ***\n";
90 $windows = $Config{osname} =~ /mswin/i;
93 # MAY not be necessary--we'll have to see.
94 # if ($windows and $] == 5.010) {
95 # print STDERR "\n\nActiveState Perl 5.10 is not compatible with GBrowse due to problems\n";
96 # print STDERR "with the AS implementation. Please remove it and install Perl 5.8 instead.\n\n\n";
97 # exit(0);
98 # }
100 # Also MAY not be necessary
101 # if ($windows) {
102 # print STDERR "\n\nInstalling Win32 perl module\n\n";
103 # system("ppm install Win32");
106 eval "CPAN::Config->load";
107 eval "CPAN::Config->commit";
109 $working_dir = getcwd;
111 $tmpdir = tempdir(CLEANUP=>1)
112 or die "Could not create temporary directory: $!";
114 $binaries = $Config{'binexp'};
115 $make = $Config{'make'};
117 if ($windows) {
118 system("ppm install YAML");
120 else {
121 CPAN::Shell->install('YAML');
123 CPAN::Shell->install('Archive::Zip');
124 CPAN::Shell->install('HTML::Tagset');
125 CPAN::Shell->install('LWP::Simple');
126 eval "use Archive::Zip ':ERROR_CODES',':CONSTANTS'";
128 if ($windows && !-e "$binaries/${make}.exe") {
130 print STDERR "Installing make utility...\n";
131 -w $binaries or die "$binaries directory is not writeable. Please re-login as Admin.\n";
132 chdir $tmpdir;
134 my $rc = mirror(NMAKE,"nmake.zip");
135 die "Could not download nmake executable from Microsoft web site."
136 unless $rc == RC_OK() or $rc == RC_NOT_MODIFIED();
138 my $zip = Archive::Zip->new('nmake.zip') or die "Couldn't open nmake zip file for decompression: $!";
139 $zip->extractTree == AZ_OK() or die "Couldn't unzip file: $!";
140 -e 'NMAKE.EXE' or die "Couldn't extract nmake.exe";
142 cp('NMAKE.EXE',"$binaries/${make}.EXE") or die "Couldn't install nmake.exe: $!";
143 cp('NMAKE.ERR',"$binaries/${make}.ERR"); # or die "Couldn't install nmake.err: $!"; # not fatal
146 CPAN::Shell->install('Archive::Tar');
147 #print STDERR $@;
148 #print STDERR "at end of BEGIN{}\n";
152 #print STDERR "here i am\n";
153 #print STDERR $@;
155 use Archive::Tar;
156 #use CPAN '!get';
158 $is_cygwin = 1 if ( $^O eq 'cygwin' );
160 if ($get_from_cvs) {
161 $get_bioperl_svn = 1;
164 #if ($wincvs or ($windows and $get_from_cvs)) {
165 # die "\n\nGBrowse is now in svn and fetching from svn on Windows\nis not currently supported\n ";
168 #if ($windows and !$wincvs and $get_gbrowse_cvs ) {
169 # die "\n\nThe development/cvs tags are not supported on Windows when\n"
170 # ."WinCVS is not installed; exiting...\n";
173 $build_param_string ||="";
174 $install_param_string ||="";
176 use constant BIOPERL_VERSION => 'BioPerl-1.6.1';
177 use constant BIOPERL_REQUIRES => '1.006001'; # sorry for the redundancy
178 use constant BIOPERL_LIVE_URL => 'http://github.com/bioperl/bioperl-live/tarball/master';
179 use constant BIOPERL => 'http://bioperl.org/DIST/'.BIOPERL_VERSION.'.tar.gz';
181 my %REPOSITORIES = (
182 #'BioPerl-Release-Candidates' => 'http://bioperl.org/DIST/RC',
183 'BioPerl-Regular-Releases' => 'http://bioperl.org/DIST',
184 'Kobes' => 'http://theoryx5.uwinnipeg.ca/ppms',
185 'Bribes' => 'http://www.Bribes.org/perl/ppm',
186 'tcool' => 'http://ppm.tcool.org/archives/',
190 # this is so that ppm can be called in a pipe
191 $ENV{COLUMNS} = 80; # why do we have to do this?
192 $ENV{LINES} = 24;
194 setup_ppm() if $windows;
196 unless ( eval "use GD 2.31; 1" ) {
197 if ($windows) {
198 print STDERR "Installing GD via ppm.\n";
199 print STDERR "(This may take a while...\n";
200 system("ppm install GD");
202 else {
203 print STDERR "Installing GD via CPAN...\n";
204 CPAN::Shell->install('GD') unless eval "use GD 2.31; 1";
208 print STDERR "\n*** Installing prerequisites for BioPerl ***\n";
210 if ($windows and !eval "use DB_File; 1") {
211 print STDERR "Installing DB_File for BioPerl.\n";
213 # GBrowse doesn't like DB_File 1.820, so we explicitly get DB_File by url
214 system("ppm install http://ppm.tcool.org/archives/DB_File.ppd");
216 #system("ppm install SVG") if $windows;
217 #CPAN::Shell->install('GD::SVG');
219 #needed?
220 CPAN::Shell->install('IO::String');
221 #CPAN::Shell->install('Text::Shellwords');
222 #if ($windows) {
223 # #CGI::Session and Digest::MD5 both fail to install via cpan on windows
224 # system("ppm install CGI-Session");
225 # system("ppm install Digest-MD5");
227 #else {
228 # CPAN::Shell->install('CGI::Session');
229 # CPAN::Shell->install('Digest::MD5');
231 #CPAN::Shell->install('File::Temp');
232 #CPAN::Shell->install('Class::Base');
233 #CPAN::Shell->install('Statistics::Descriptive');
234 #CPAN::Shell->install('Data::Stag');
236 my $version = BIOPERL_REQUIRES;
237 if (!(eval "use Bio::Perl $version; 1") or $get_bioperl_svn or $bioperl_path) {
238 print STDERR "\n*** Installing BioPerl ***\n";
240 #would like to use ppm, but ppm won't install 1.6
241 #if ($windows and !$get_bioperl_svn and !$bioperl_path) {
242 # my $bioperl_index = find_bioperl_ppm();
243 # system("ppm install --force $bioperl_index");
244 #} else {
245 # recent versions of Module::Build fail to install without force!
246 CPAN::Shell->force('Module::Build') unless eval "require Module::Build; 1";
247 do_install(BIOPERL,
248 'bioperl.tgz',
249 BIOPERL_VERSION,
250 'Build',
251 $get_bioperl_svn ? 'svn' : '',
252 $build_param_string,
253 $bioperl_path,
254 $install_param_string,
255 $perl_path);
258 else {
259 print STDERR "BioPerl is up to date.\n";
262 print STDERR "\n *** Installing Bio::Graphics ***\n";
265 #install biographics?
266 CPAN::Shell->install('Bio::Graphics');
268 exit 0;
270 END {
271 open STDERR,">/dev/null"; # windows has an annoying message when cleaning up temp file
274 sub do_install {
275 my ($download,$local_name,$distribution,$method,
276 $from_cvs,$build_param_string,$file_path,$install_param_string,
277 $perl_path) = @_;
279 $install_param_string ||= '';
280 chdir $tmpdir;
282 do_get_distro($download,$local_name,$distribution,$from_cvs,$file_path);
284 my $build_str = $windows ? "Build" : "./Build";
286 if ($method eq 'make') {
287 system("$perl_path Makefile.PL $build_param_string") == 0
288 or die "Couldn't run perl Makefile.PL command\n";
289 system("$make install UNINST=1 $install_param_string") == 0 ;
291 elsif ($method eq 'Build') {
292 system("$perl_path $build_str.PL --yes=1 $build_param_string") == 0
293 or die "Couldn't run perl Build.PL command\n";
294 system("$build_str install --uninst 1 $install_param_string") == 0;
298 sub do_get_distro {
299 my ($download,$local_name,$distribution,$distribution_method,$file_path) = @_;
301 if ($file_path) {
302 chdir $working_dir;
303 if (-e $file_path) { #must be an absolute path
304 cp($file_path, "$tmpdir/$local_name");
306 elsif (-e "$working_dir/$file_path") { #assume it's a rel path from the original directory
307 cp("$working_dir/$file_path", "$tmpdir/$local_name");
309 else {
310 print "Couldn't find $file_path; nothing to do so quitting...\n";
311 exit(-1);
313 $distribution = ($local_name =~ /gbrowse/)
314 ? "Generic-Genome-Browser" : "bioperl-live";
315 chdir $tmpdir;
316 extract_tarball($local_name,$distribution);
318 elsif ($distribution_method) {
319 my $distribution_dir;
320 print STDERR "Downloading bioperl-live...\n";
321 $distribution_dir = 'bioperl-live';
323 my $filename = 'bioperl-live.tar.gz'; # =determine_filename();
324 my $url = BIOPERL_LIVE_URL."/$filename";
326 my $rc = mirror($url, $filename);
327 unless ($rc == RC_OK or $rc == RC_NOT_MODIFIED){
328 print STDERR "Failed to get nightly bioperl-live file: $rc\n";
329 return undef;
331 extract_tarball($filename,$distribution_dir);
332 return 1;
333 chdir $distribution_dir
334 or die "Couldn't enter $distribution_dir directory: $@";
336 else {
337 print STDERR "Downloading $download...\n";
338 my $rc = mirror($download,$local_name);
339 die "Could not download $distribution distribution from $download."
340 unless $rc == RC_OK or $rc == RC_NOT_MODIFIED;
342 extract_tarball($local_name,$distribution);
344 return 1;
347 #this is probably not going to be needed again, as the nightly
348 #bioperl build names have been simplified
349 sub determine_filename {
350 my $listing = "dirlisting.html";
351 my $rc = mirror(BIOPERL_LIVE_URL, $listing);
352 die "Could not get directory listing of bioperl nightly build url: $rc\n"
353 unless ($rc == RC_OK or $rc == RC_NOT_MODIFIED);
355 my $filename;
356 open LIST, $listing or die "unable to open $listing: $!\n";
357 while (<LIST>) {
358 if (/href="(bioperl-live.*?\.tar\.gz)"/) {
359 $filename = $1;
360 last;
363 close LIST;
364 unlink $listing;
365 return $filename;
368 sub extract_tarball {
369 my ($local_name,$distribution) = @_;
371 print STDERR "Unpacking $local_name...\n";
372 my $z = Archive::Tar->new($local_name,1)
373 or die "Couldn't open $distribution archive: $@";
374 my @extracted = $z->extract()
375 or die "Couldn't extract $distribution archive: $@";
377 if ($extracted[0]->{'name'} =~ /^(bioperl.*?)\//) {
378 my $bioperl_dir = $1;
379 move($bioperl_dir, $distribution) or die "couldn't move bioperl dir: $@";
382 chdir $distribution
383 or die "Couldn't enter $distribution directory: $@";
384 return;
387 # make sure ppm repositories are correct!
388 sub setup_ppm {
389 open S,"ppm repo list --csv|" or die "Couldn't open ppm for listing: $!";
390 my %repository;
391 while (<S>) {
392 chomp;
393 my($index,$package_count,$name) = split /,/;
394 $repository{$name} = $index;
396 close S;
397 print STDERR "Adding needed PPM repositories. This may take a while....\n";
398 for my $name (keys %REPOSITORIES) {
399 next if $repository{$name};
400 system("ppm rep add $name $REPOSITORIES{$name}");
404 sub find_bioperl_ppm {
405 print STDERR "Finding most recent bioperl...";
406 open S,"ppm search bioperl |" or die "Couldn't open ppm for listing: $!";
407 local $/ = ''; # paragraph mode
408 my ($blessed_one,$blessed_version);
409 my $best = 0;
410 while (<S>) {
411 chomp;
412 my ($number) = /^(\d+): bioperl/m;
413 my ($version) = /^\s+Version: (.+)/m;
414 my ($repository) = /^\s+Repo: (.+)/m;
415 my $multiplier = 10000000;
416 my $magnitude = 0;
417 # this dumb thing converts 1.5.1 into a real number
418 foreach (split /[._]/,$version) {
419 $magnitude += $_ * ($multiplier/=10);
421 ($blessed_one,$best,$blessed_version) = ($number,$magnitude,$version) if $best < $magnitude;
423 close S;
424 print STDERR $blessed_version ? "found $blessed_version\n" : "not found\n";
425 return $blessed_one;