2 # BioPerl script for Bio::Installer
4 # Cared for by Albert Vilella
6 # based on the CPAN::FirstTime module
8 # Copyright Albert Vilella
10 # You may distribute this module under the same terms as perl itself
12 # POD documentation - main docs before the code
16 bioperl_application_installer - downloads and installs runnables
20 bioperl_application_installer
24 This script will ask the user which programs wants to install and
25 where. It will download the packages, decompress them (if necessary)
26 and compile/install them in the specified directory.
30 Albert Vilella, avilella-AT-gmail-DOT-com
34 Check if the programs are already installed in the computer and prompt
35 it so that the user is at least aware of it.
37 Check for the available installers, instead of hard-coding
38 $INSTALLERLIST in this script.
43 use ExtUtils
::MakeMaker
;
45 use Bio
::Factory
::ObjectFactory
;
47 use vars
qw($DEFAULT $CONFIG $INSTALLERLIST);
50 $DEFAULT = 'bioperl-runnables';
60 my $dir = shift @ARGV || $DEFAULT;
66 ################################################################################
83 This script will install the runnable programs associated with
86 Bioperl-run contain modules that provides a PERL interface to various
87 bioinformatics applications. This allows various applications to be
88 used with common bioperl objects.
90 If you do not want to enter a dialog now, you can answer 'no' to this
96 ExtUtils::MakeMaker::prompt("Are you ready for manual configuration?",
101 if ($manual_conf =~ /^\s*y/i) {
103 *prompt = \&ExtUtils::MakeMaker::prompt;
111 The following questions are intended to help you with the
116 $default = File::Spec->catdir( $ENV{'HOME'}, $configpm);
117 while ($ans = prompt("Where do you want to install the runnables in your computer?",$default)) {
118 unless (File::Spec->file_name_is_absolute($ans)) {
120 my $cwd = Cwd::cwd();
121 my $absans = File::Spec->catdir($cwd,$ans);
122 warn "The path '$ans' is not an absolute path. Please specify an absolute path\n";
126 eval { File::Path::mkpath($ans); }; # dies if it can't
128 warn "Couldn't create directory $ans.
132 if (-d $ans && -w _) {
134 Directory $ans successfully created.
140 warn "Couldn't find directory $ans
141 or directory is not writable. Please retry.\n";
147 The script will need a few external programs to work properly.
148 Please correct me, if I guess the wrong path for a program. Don\'t
149 panic if you do not have some of them, just press ENTER for those.
154 local $^W if $^O eq 'MacOS';
155 my(@path) = split /$Config{'path_sep'}/, $ENV{'PATH'};
156 local $^W = $old_warn;
158 for $progname (qw/gzip tar unzip make links wget ncftpget ncftp ftp gpg/) {
159 if ($^O eq 'MacOS') {
160 $CONFIG->{$progname} = 'not_here';
163 my $progcall = $progname;
164 # we don't need ncftp if we have ncftpget
165 next if $progname eq "ncftp" && $CONFIG->{ncftpget} gt " ";
166 my $path = $CONFIG->{$progname}
167 || $Config::Config{$progname}
169 if (File::Spec->file_name_is_absolute($path)) {
170 # testing existence is not good enough, some have these exe
173 # warn "Warning: configured $path does not exist\n" unless -e $path;
180 $progcall = $Config::Config{$progname} if $Config::Config{$progname};
183 $path ||= find_exe($progcall,[@path]);
184 warn "Warning: $progcall not found in PATH\n" unless
185 $path; # not -e $path, because find_exe already checked that
186 $ans = prompt("Where is your $progname program?",$path) || $path;
187 $CONFIG->{$progname} = $ans;
189 my $path = $CONFIG->{'pager'} ||
190 $ENV{PAGER} || find_exe("less",[@path]) ||
191 find_exe("more",[@path]) || ($^O eq 'MacOS' ? $ENV{EDITOR} : 0 )
193 $ans = prompt("What is your favorite pager program?",$path);
194 $CONFIG->{'pager'} = $ans;
195 $path = $CONFIG->{'shell'};
196 if (File::Spec->file_name_is_absolute($path)) {
197 warn "Warning: configured $path does not exist\n" unless -e $path;
200 $path ||= $ENV{SHELL};
201 if ($^O eq 'MacOS') {
202 $CONFIG->{'shell'} = 'not_here';
204 $path =~ s,\\,/,g if $^O eq 'os2'; # Cosmetic only
205 $ans = prompt("What is your favorite shell?",$path);
206 $CONFIG->{'shell'} = $ans;
211 Which programs would you like to install?
214 my @selected_programs;
215 my $prompt = "Select the programs you would like to install (by number),
216 put them on one line, separated by blanks, e.g. '1 2 4'";
218 push (@selected_programs, @$INSTALLERLIST);
219 @selected_programs = picklist (\@selected_programs, $prompt);
220 push @{$CONFIG->{selected_programs_list}}, @selected_programs;
224 The selected programs will now be installed
228 # TODO: Check for the available installers, instead of hard-coding
229 # $INSTALLERLIST in this script.
232 # next unless (-e $i."/My/Stuff/");
233 # opendir(X,$i."/My/Stuff")|| warn "$!";
234 # push @l,readdir(X);
237 # find sub { push(@l, $File::Find::name) if -f && /\.pm$/ },
238 # map { "$_/My/Module" } @INC;
240 foreach my $program (@selected_programs) {
241 my $type = 'Bio::Installer::' . $program;
242 my $factory = new Bio::Factory::ObjectFactory(-type => $type);
243 my $instance = $factory->create_object();
244 $instance->destination_install_dir($default);
245 $instance->download();
246 $instance->install();
253 my($items,$prompt,$default,$require_nonempty,$empty_warning)=@_;
261 # display, at most, 15 items at a time
262 my $limit = $#{ $items } - $pos;
263 $limit = 15 if $limit > 15;
265 # show the next $limit items, get the new position
266 $pos = display_some($items, $limit, $pos);
267 $pos = 0 if $pos >= @$items;
269 my $num = prompt($prompt,$default);
271 @nums = split (' ', $num);
272 my $i = scalar @$items;
273 (warn "invalid items entered, try again\n"), next
274 if grep (/\D/ || $_ < 1 || $_ > $i, @nums);
275 if ($require_nonempty) {
276 (warn "$empty_warning\n");
280 # a blank line continues...
290 my ($items, $limit, $pos) = @_;
293 my @displayable = @$items[$pos .. ($pos + $limit)];
294 for my $item (@displayable) {
295 printf "(%d) %s\n", ++$pos, $item;
297 printf("%d more items, hit SPACE RETURN to show them\n",
308 #warn "in find_exe exe[$exe] path[@$path]";
310 my $abs = File::Spec->catfile($dir,$exe);
311 if (($abs = MM->maybe_command($abs))) {