use strict; use ExtUtils::MakeMaker; 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); } use Digest::MD5; use Safe; require File::Spec; my %fake; my $so = 'mod_apreq2.so'; $fake{$so} = 'mod_apreq2.so'; my $dll = 'libapreq2.dll'; $fake{$dll} = 'libapreq2.dll'; my $ap2 = '/Apache2/modules'; my $cs = 'CHECKSUMS'; my $theoryx5 = 'http://theoryx5.uwinnipeg.ca/ppms/x86/'; my $checksums = $theoryx5 . $cs; print <<"END"; The Apache2 module $so and the dll $dll are needed to complete the installation. I will now fetch and install these for you. END my @drives = drives(); my $apache2; # find a possible Apache2 directory APACHE2: { for my $drive (@drives) { for my $p ('Apache2', 'Program Files/Apache2', 'Program Files/Apache Group/Apache2') { my $candidate = File::Spec->catpath($drive, $p); if (-d $candidate) { $apache2 = $candidate; last APACHE2; } } } } if ($apache2) { $apache2 = fix_path($apache2); my $ans = prompt(qq{Install under "$apache2"?}, 'yes'); $apache2 = undef unless ($ans =~ /^y/i); } if (not $apache2) { $apache2 = prompt(qq{Where is your top-level Apache2 directory?}, ''); $apache2 = fix_path($apache2); die "Please specify the top-level Apache2 directory" unless (-d $apache2); } my $vers = qx{"$apache2/bin/httpd.exe" -v}; die qq{"$apache2" does not appear to be version 2.2} unless $vers =~ m!Apache/2.2!; $| = 1; print "fetching $cs ... "; die "Fetching file failed" unless (is_success(getstore($checksums, $cs))); print " done!\n"; my $cksum = load_cs($cs); die "Could not load $cs: $!" unless $cksum; for my $file ( ($so, $dll) ) { my $fake = $fake{$file}; my $remote = $theoryx5 . $fake; print "Fetching $remote ... "; getstore($remote, $fake); print " done!\n"; suggest_manual("Cannot find $fake") unless -f $fake; die qq{CHECKSUM check for "$fake" failed.\n} unless (verifyMD5($cksum, $fake)); rename($fake, $file); my $default = $apache2 . ($file eq 'mod_apreq2.so' ? '/modules' : '/bin'); my $base = prompt("Where should $file be placed?", $default); $base = Win32::GetShortPathName($base) if $base =~ / /; $base =~ s/$file$//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: $!") unless (-d $base); } else { suggest_manual("Will not create $base."); } } if (-f "$base/$file") { my $ans = prompt("$base/$file exists. Overwrite?", 'no'); if ($ans =~ /^n/i) { suggest_manual("Will not overwrite $base/$file."); } } use File::Copy; move($file, "$base/$file"); suggest_manual("Moving $file to $base failed: $!") unless (-f "$base/$file"); print "$file has been successfully installed to $base\n"; } print <<"END"; libapreq2 has been successfully installed. To use it, you should either add $apache2/bin to your PATH environment variable, or put in a line LoadFile "$apache2/bin/libapreq2.dll" in your Apache httpd.conf file. As well, insert a line LoadModule apreq_module modules/mod_apreq2.so into httpd.conf in order to use mod_apreq2. END sleep(9); sub suggest_manual { my $msg = shift; print $msg, "\n"; print "Installation not completed.\n"; sleep(5); exit(0); } # routine to verify the CHECKSUMS for a file # adapted from the MD5 check of CPAN.pm sub load_cs { my $cs = shift; my ($cksum, $fh); unless (open $fh, $cs) { warn "Could not open $cs: $!"; return; } local($/); my $eval = <$fh>; $eval =~ s/\015?\012/\n/g; close $fh; my $comp = Safe->new(); $cksum = $comp->reval($eval); if ($@) { warn $@; return; } return $cksum; } sub verifyMD5 { my ($cksum, $file) = @_; my ($fh, $is, $should); unless (open($fh, $file)) { warn "Cannot open $file: $!"; return; } binmode($fh); unless ($is = Digest::MD5->new->addfile($fh)->hexdigest) { warn "Could not compute checksum for $file: $!"; close($fh); return; } close($fh); if ($should = $cksum->{$file}->{md5}) { my $test = $is eq $should ? 1 : 0; printf qq{Checksum for "$file" is %s\n}, ($test == 1) ? 'OK.' : 'NOT OK.'; return $test; } else { warn "Checksum data for $file not present in CHECKSUMS.\n"; return; } } sub fix_path { my $file = shift; $file = Win32::GetShortPathName($file) if $file =~ / /; $file =~ s!\\!/!g; return $file; } sub drives { my @drives = (); eval{require Win32API::File;}; return map {"$_:\\"} ('C' .. 'Z') if $@; my @r = Win32API::File::getLogicalDrives(); return unless @r > 0; for (@r) { my $t = Win32API::File::GetDriveType($_); push @drives, $_ if ($t == 3 or $t == 4); } return @drives > 0 ? @drives : undef; }