#!/Perl/bin/Perl.exe require File::Spec; use File::Basename; use strict; use ExtUtils::MakeMaker; use LWP::Simple; my $lib = 'libexpat.dll'; my $version = '1.95.7'; my $default = '/Perl/bin'; my $guess = '/Perl/bin'; my $recommended = 'yes'; if (my $hit = search_for($lib, $guess)) { print <<"END"; A copy of the needed library $lib was found in $hit. If this is compatible with the version ($version) used to compile the Perl module, all that is needed to complete the installation is to ensure $hit is in your PATH environment variable. 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://landfill.bugzilla.org/ppm/scripts/' . $lib; print "Fetching $remote ... "; 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 search_for { my ($lib, $guess) = @_; return $guess if (-e File::Spec->catfile($guess, $lib)); my $hit; SEARCH: { my $candidate; for (File::Spec->path) { $candidate = File::Spec->catfile($_, $lib); if (-e $candidate) { $hit = $candidate; last SEARCH; } } my @drives = drives(); last SEARCH unless (@drives > 0); for (@drives) { $candidate = File::Spec->catfile($_, $guess, $lib); if (-e $candidate) { $hit = $candidate; last SEARCH; } } } return $hit ? dirname($hit) : undef; } sub drives { my @drives = (); eval{require Win32API::File;}; return map {"$_:\\"} ('C' .. 'Z') if $@; my @r = Win32API::File::getLogicalDrives(); return unless @r > 0; foreach (@r) { my $t = Win32API::File::GetDriveType($_); push @drives, $_ if ($t == 3 or $t == 4); } return @drives > 0 ? @drives : undef; }