1#!/usr/local/bin/perl 2 3## This is here because Perl 5.005 installations may try to re-install 4## a whole perl if you run this! If you want to try it, then 5 6use lib './lib'; 7use lib '../lib'; 8use lib "$ENV{HOME}/.cpan"; 9use Getopt::Std; 10 11getopts('cfd:h'); 12 13eval { 14 require 5.6.0; 15}; 16 17use vars qw/$opt_c $opt_f $opt_d $opt_h $VERSION/; 18 19$VERSION = q{$Id}; 20 21my $prog = $0; 22$prog =~ s:.*/::; 23 24$::USAGE = <<EOF; 25usage: $prog [-f] [-d interchange_root] [module1 module2 module_n] 26 27[module] defaults to Bundle::Interchange. 28 29OPTIONS: 30 31 -f Force install for Perl 5.005 32 -d Set interchange root directory (default current) 33 34EOF 35 36if($opt_h) { 37 warn $USAGE; 38 exit 2; 39} 40 41if($@) { 42 43 require 5.005; 44 if(! $opt_f) { 45 my $args = join " ", @ARGV; 46 print <<EOF; 47Perl 5.005 installations may try to re-install a whole perl if you run this! If 48you want to try it, then rerun with a -f flag, i.e. 49 50 $0 -f $args 51 52EOF 53 } 54} 55 56use Cwd; 57use File::Spec; 58 59use strict; 60 61my $libdir = $opt_d || $opt_d || ''; 62 63my @mods_to_get = @ARGV; 64 65if(! @mods_to_get) { 66 push @mods_to_get, 'Bundle::Interchange'; 67} 68 69if(! $libdir) { 70 my @possible = grep -f $_, qw/minivend.cfg interchange.cfg interchange.cfg.dist/; 71 if(@possible) { 72 $libdir = cwd() if -d 'lib'; 73 } 74} 75 76$libdir =~ s:(^|/)lib$::; 77 78if(! File::Spec->file_name_is_absolute($libdir) ) { 79 $libdir = File::Spec->catfile(cwd(), $libdir); 80} 81 82unshift @INC, $libdir, "$libdir/lib"; 83 84$ENV{PERL5LIB} = join ":", @INC; 85 86 87use CPAN; 88 89eval { 90 require CPAN::MyConfig 91}; 92if($@) { 93 eval { 94 require CPAN::Config; 95 }; 96}; 97 98if($@) { 99 print <<EOF if ! $opt_c; 100 101We can go and get optional modules that help Interchange work a 102bit better and faster. At least we can if you are connected 103to the Internet and have one of the following on your machine: 104 105 Perl LWP libraries 106 Perl Net::FTP library 107 ncftp (a nice FTP program) 108 lynx (the text-based web browser) 109 110In case you were wondering, CPAN is a worldwide network of 111over 100 FTP sites which maintain the latest Perl software. 112If you don't know a URL to use, you can try: 113 114 ftp://ftp.freesoftware.com/pub/perl/CPAN 115 ftp://ftp.funet.fi/pub/languages/perl/CPAN 116 117You will be asked quite a few questions during the process. It is 118almost always right to accept the default by hitting ENTER. (There 119may be a couple of module tests that require you to hit 'q' to terminate 120them.) 121 122If you have errors during the process, don't worry. We will try 123real, real, hard to get all of the modules installed. If 124all don't continue to install, then try rerunning: 125 126 $0 127 128EOF 129 my_prompt('Press [ENTER] to continue....'); 130 if(ref $CPAN::Config) { 131 $CPAN::Config->{makepl_arg} = "INSTALLPRIVLIB=$libdir/lib INSTALLARCHLIB=$libdir/lib INSTALLSITELIB=$libdir/lib INSTALLMAN1DIR=none INSTALLMAN3DIR=none INSTALLSITEARCH=$libdir/lib INSTALLDIRS=perl"; 132 $CPAN::Config->{keep_source_where} = "$libdir/src" 133 unless -w $CPAN::Config->{keep_source_where}; 134 $CPAN::Config->{cpan_home} = "$libdir/src" 135 unless -w $CPAN::Config->{cpan_home}; 136 $CPAN::Config->{build_dir} = "$libdir/src" 137 unless -w $CPAN::Config->{build_dir}; 138 } 139 CPAN::get 'Bundle::Interchange'; 140} 141 142# See if we have the CPAN module 143eval { 144 die "Don't try this at home with Windows.\n" if $^O =~ /win32/i; 145}; 146 147if($@) { 148 die "Can't do cpan_local_install: $@\n"; 149} 150 151sub my_prompt { 152 my($pr) = shift || '? '; 153 my($def) = shift; 154 my($ans); 155 156 print $pr; 157 print "[$def] " if $def; 158 chomp($ans = <STDIN>); 159 $ans ? $ans : $def; 160} 161 162for my $module (@mods_to_get) { 163 my $prompt = "Get $module? [yes] "; 164 my $ask = 'y'; 165 $ask = my_prompt($prompt) 166 unless $opt_c; 167 exit 2 if $ask =~ /^\s*n/i; 168 169 $CPAN::Config->{makepl_arg} = "INSTALLPRIVLIB=$libdir/lib INSTALLARCHLIB=$libdir/lib INSTALLSITELIB=$libdir/lib INSTALLMAN1DIR=none INSTALLMAN3DIR=none INSTALLSITEARCH=$libdir/lib INSTALLDIRS=perl"; 170 $CPAN::Config->{keep_source_where} = "$libdir/src" 171 unless -w $CPAN::Config->{keep_source_where}; 172 $CPAN::Config->{cpan_home} = "$libdir/src" 173 unless -w $CPAN::Config->{cpan_home}; 174 $CPAN::Config->{build_dir} = "$libdir/src" 175 unless -w $CPAN::Config->{build_dir}; 176 my $incstring = join " ", @INC; 177 print <<EOF; 178 INSTALLPRIVLIB=$libdir/lib 179 INSTALLARCHLIB=$libdir/lib 180 INSTALLSITELIB=$libdir/lib 181 INSTALLMAN1DIR=none 182 INSTALLMAN3DIR=none 183 INSTALLSITEARCH=$libdir/lib 184 INSTALLDIRS=perl 185 LIBDIRS=$incstring 186EOF 187 CPAN::install($module); 188} 189 190