A test to ensure Bio::PrimarySeqI->trunc() doesn't use clone() for a Bio::Seq::RichSe...
[bioperl-live.git] / scripts / utilities / bp_netinstall.pl
blob0e69be2b7695201dbba3b96d0605ca443003b58a
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 development 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 my $null = ($^O =~ m/mswin/i) ? 'NUL' : '/dev/null';
272 open STDERR,">$null"; # windows has an annoying message when cleaning up temp file
275 sub do_install {
276 my ($download,$local_name,$distribution,$method,
277 $from_cvs,$build_param_string,$file_path,$install_param_string,
278 $perl_path) = @_;
280 $install_param_string ||= '';
281 chdir $tmpdir;
283 do_get_distro($download,$local_name,$distribution,$from_cvs,$file_path);
285 my $build_str = $windows ? "Build" : "./Build";
287 if ($method eq 'make') {
288 system("$perl_path Makefile.PL $build_param_string") == 0
289 or die "Couldn't run perl Makefile.PL command\n";
290 system("$make install UNINST=1 $install_param_string") == 0 ;
292 elsif ($method eq 'Build') {
293 system("$perl_path $build_str.PL --yes=1 $build_param_string") == 0
294 or die "Couldn't run perl Build.PL command\n";
295 system("$build_str install --uninst 1 $install_param_string") == 0;
299 sub do_get_distro {
300 my ($download,$local_name,$distribution,$distribution_method,$file_path) = @_;
302 if ($file_path) {
303 chdir $working_dir;
304 if (-e $file_path) { #must be an absolute path
305 cp($file_path, "$tmpdir/$local_name");
307 elsif (-e "$working_dir/$file_path") { #assume it's a rel path from the original directory
308 cp("$working_dir/$file_path", "$tmpdir/$local_name");
310 else {
311 print "Couldn't find $file_path; nothing to do so quitting...\n";
312 exit(-1);
314 $distribution = ($local_name =~ /gbrowse/)
315 ? "Generic-Genome-Browser" : "bioperl-live";
316 chdir $tmpdir;
317 extract_tarball($local_name,$distribution);
319 elsif ($distribution_method) {
320 my $distribution_dir;
321 print STDERR "Downloading bioperl-live...\n";
322 $distribution_dir = 'bioperl-live';
324 my $filename = 'bioperl-live.tar.gz'; # =determine_filename();
325 my $url = BIOPERL_LIVE_URL."/$filename";
327 my $rc = mirror($url, $filename);
328 unless ($rc == RC_OK or $rc == RC_NOT_MODIFIED){
329 print STDERR "Failed to get nightly bioperl-live file: $rc\n";
330 return undef;
332 extract_tarball($filename,$distribution_dir);
333 return 1;
334 chdir $distribution_dir
335 or die "Couldn't enter $distribution_dir directory: $@";
337 else {
338 print STDERR "Downloading $download...\n";
339 my $rc = mirror($download,$local_name);
340 die "Could not download $distribution distribution from $download."
341 unless $rc == RC_OK or $rc == RC_NOT_MODIFIED;
343 extract_tarball($local_name,$distribution);
345 return 1;
348 #this is probably not going to be needed again, as the nightly
349 #bioperl build names have been simplified
350 sub determine_filename {
351 my $listing = "dirlisting.html";
352 my $rc = mirror(BIOPERL_LIVE_URL, $listing);
353 die "Could not get directory listing of bioperl nightly build url: $rc\n"
354 unless ($rc == RC_OK or $rc == RC_NOT_MODIFIED);
356 my $filename;
357 open my $LIST, '<', $listing or die "Could not read file '$listing': $!\n";
358 while (my $line = <$LIST>) {
359 if ($line =~ /href="(bioperl-live.*?\.tar\.gz)"/) {
360 $filename = $1;
361 last;
364 close $LIST;
365 unlink $listing;
366 return $filename;
369 sub extract_tarball {
370 my ($local_name,$distribution) = @_;
372 print STDERR "Unpacking $local_name...\n";
373 my $z = Archive::Tar->new($local_name,1)
374 or die "Couldn't open $distribution archive: $@";
375 my @extracted = $z->extract()
376 or die "Couldn't extract $distribution archive: $@";
378 if ($extracted[0]->{'name'} =~ /^(bioperl.*?)\//) {
379 my $bioperl_dir = $1;
380 move($bioperl_dir, $distribution) or die "couldn't move bioperl dir: $@";
383 chdir $distribution
384 or die "Couldn't enter $distribution directory: $@";
385 return;
388 # make sure ppm repositories are correct!
389 sub setup_ppm {
390 open my $S, "ppm repo list --csv|" or die "Could not open ppm for listing: $!\n";
391 my %repository;
392 while (my $line = <$S>) {
393 chomp $line;
394 my ($index, $package_count, $name) = split /,/, $line;
395 $repository{$name} = $index;
397 close $S;
398 print STDERR "Adding needed PPM repositories. This may take a while....\n";
399 for my $name (keys %REPOSITORIES) {
400 next if $repository{$name};
401 system("ppm rep add $name $REPOSITORIES{$name}");
405 sub find_bioperl_ppm {
406 print STDERR "Finding most recent bioperl...";
407 open my $S,"ppm search bioperl |" or die "Could not open ppm for listing: $!\n";
408 local $/ = ''; # paragraph mode
409 my ($blessed_one, $blessed_version);
410 my $best = 0;
411 while (my $line = <$S>) {
412 chomp $line;
413 my ($number) = ($line =~ /^(\d+): bioperl/m);
414 my ($version) = ($line =~ /^\s+Version: (.+)/m);
415 my ($repository) = ($line =~ /^\s+Repo: (.+)/m);
416 my $multiplier = 10000000;
417 my $magnitude = 0;
418 # this dumb thing converts 1.5.1 into a real number
419 foreach my $piece (split /[._]/, $version) {
420 $magnitude += $piece * ($multiplier/=10);
422 ($blessed_one,$best,$blessed_version) = ($number,$magnitude,$version) if $best < $magnitude;
424 close $S;
425 print STDERR $blessed_version ? "found $blessed_version\n" : "not found\n";
426 return $blessed_one;