use strict; use ExtUtils::MakeMaker; use Config; require File::Spec; use LWP::Simple qw(getstore $ua is_success); if ($ENV{HTTP_proxy_user} and $ENV{HTTP_proxy_pass} and $ENV{HTTP_proxy} =~ /^http:\/\/([^@]+)$/) { my $proxy ="http://$ENV{HTTP_proxy_user}:$ENV{HTTP_proxy_pass}\@" . $1; print "setting user/pass into proxy_env...\n"; $ua->proxy(['http'], $proxy); } my $lib = 'libdb.dll'; my $version = '2.7.7'; my $default = $Config{binexp}; my $recommended = 'yes'; if (my $hit = is_in_path($lib)) { print <<"END"; A copy of the needed library $lib was found in your PATH environment variable, under $hit. If this is compatible with the version ($version) used to compile the Perl module, no further action is needed to complete the installation. END $recommended = 'no'; } if ($recommended eq 'yes') { print <<"END"; The library $lib is needed to complete the installation, and should be placed in a directory somewhere in your PATH environment variable. I can fetch and install this for you, if you don\'t already have it. END } my $proceed = prompt("Fetch $lib?", $recommended); suggest_manual("Aborting download of $lib.", 'warn') unless ($proceed =~ /^y/i); my $remote = 'http://theoryx5.uwinnipeg.ca/ppms/scripts/' . $lib; print "Fetching $remote ... "; die "Fetching file failed" unless (is_success(getstore($remote, $lib))); print " done!\n"; suggest_manual("Cannot find $lib", 'fatal') unless -f $lib; my $base = prompt("Where should $lib be placed?", $default); $base =~ s/$lib$//i; $base =~ s!\\!/!g; $base =~ s!/$!!; unless (-d $base) { my $ans = prompt("$base does not exist. Create it?", 'no'); if ($ans =~ /^y/i) { mkdir $base; suggest_manual("Could not create $base: $!", 'fatal') unless (-d $base); } else { suggest_manual("Will not create $base.", 'fatal'); } } if (-f "$base/$lib") { my $ans = prompt("$base/$lib exists. Overwrite?", 'no'); if ($ans =~ /^n/i) { suggest_manual("Will not overwrite $base/$lib.", 'fatal'); } } use File::Copy; move($lib, "$base/$lib"); suggest_manual("Moving $lib to $base failed: $!", 'fatal') unless (-f "$base/$lib"); print "$lib has been successfully installed to $base\n"; sleep(5); sub suggest_manual { my ($msg, $type) = @_; print $msg, "\n"; print "Installation of $lib not completed.\n" if ($type eq 'fatal'); sleep (5); exit(0); } sub is_in_path { my $lib = shift; my $hit; foreach my $p (File::Spec->path) { my $candidate = File::Spec->catfile($p, $lib); if (-f $candidate) { $hit = $candidate; last; } } return $hit; }