1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
|
#####################################################################
# A Perl script to retrieve and join split files
# making up a Win32 Perl/Apache binary distribution
#
# Files created by hjsplit (http://www.freebyte.com/hjsplit/)
# with the joining accomplished by hj-join
#
# This script is Copyright 2003, by Randy Kobes,
# and may be distributed under the same terms as Perl itself.
# Please report problems to Randy Kobes <randy@theoryx5.uwinnipeg.ca>
#####################################################################
use strict;
use warnings;
use Net::FTP;
use Safe;
use Digest::MD5;
use IO::File;
use ExtUtils::MakeMaker;
die 'This is intended for Win32' unless ($^O =~ /Win32/i);
my $theoryx5 = 'theoryx5.uwinnipeg.ca';
my $bsize = 102400;
my $kb = sprintf("%d", $bsize / 1024);
my $cs = 'CHECKSUMS';
my $join = 'join32.exe';
print <<"END";
This script will fetch and then join the files needed for
creating and installing a Perl/Apache Win32 binary distribution from
ftp://$theoryx5/pub/other/.
If the file transfer is interrupted before all the neccessary
files are obtained, run the script again in the same directory;
files successfully fetched earlier will not be downloaded again.
A hash mark represents transfer of $kb kB.
Available distributions are:
1. Perl 5.8.7 / Apache 2.0.54 / mod_perl-2.0.1
2. Perl 5.6.1 / Apache 1.3.27 / mod_perl 1.27
It is recommended to install Perl and Apache into fresh locations,
so that current files are not overwritten and that old files do
not linger which may confuse the new installation.
END
my $dist;
my $ans = prompt("Desired distribution (1, 2, or 'q' to quit)?", 1);
CHECK: {
($ans =~ /^q/i) and die 'Installation aborted';
($ans == 1) and do {
$dist = 'Perl-5.8-win32-bin';
last CHECK;
};
($ans == 2) and do {
$dist = 'perl-win32-bin';
last CHECK;
};
die 'Please answer either 1, 2, or q';
}
my $exe = $dist . '.exe';
my $ftp = Net::FTP->new($theoryx5);
$ftp->login('anonymous', "$dist\@perl.apache.org")
or die "Cannot login to $theoryx5";
$ftp->cwd("pub/other/$dist")
or die "Cannot cwd to pub/other/$dist";
my $max;
die "Unable to determine number of files to get" unless ($max = get_max());
my @files = ();
# fetch the CHECKSUMS file
print qq{Fetching "$cs" ...};
$ftp->ascii;
$ftp->get($cs);
print " done!\n";
die qq{Failed to fetch "$cs"} unless (-e $cs);
push @files, $cs;
# evaluate CHECKSUMS
my $cksum;
die qq{Cannot load "$cs" file} unless ($cksum = load_cs($cs) );
$ftp->binary;
$ftp->hash(1, $bsize);
# fetch the join program
die qq{Cannot fetch "$join"} unless (fetch($join));
push @files, $join;
# fetch the split files
print "\nFetching $max split files ....\n\n";
for (1 .. $max) {
my $num = $_ < 10 ? "00$_" : "0$_";
my $file = $dist . '.exe.' . $num;
push @files, $file;
die qq{Cannot fetch "$file"} unless (fetch($file));
}
print "\nFinished fetching split files.\n";
$ftp->quit;
# now join them
if (-e $exe) {
unlink($exe) or warn qq{Cannot unlink $exe: $!};
}
my @args = ($join);
system(@args);
die qq{Joining files to create "$exe" failed} unless (-e $exe);
# remove the temporary files, if desired
$ans = prompt('Remove temporary files?', 'yes');
if ($ans =~ /^y/i) {
unlink(@files) or warn "Cannot unlink temporary files: $!\n";
}
# run the exe, if desired
$ans = prompt("Run $exe now?", 'yes');
if ($ans =~ /^y/i) {
@args = ($exe);
system(@args);
}
else {
print "\nDouble click on $exe to install.\n";
}
# fetch a file, unless it exists and the checksum checks
sub fetch {
my $file = shift;
local $| = 1;
if (-e $file) {
if (verifyMD5($file)) {
print qq{Skipping "$file" ...\n};
return 1;
}
else {
unlink $file or warn qq{Could not unlink "$file"\n};
}
}
my $size = sprintf("%d", $ftp->size($file) / 1024);
print "\nFetching $file ($size kB) ...\n";
$ftp->get($file);
print "Done!\n";
unless (-e $file) {
warn qq{Unable to fetch "$file"\n};
return;
}
unless (verifyMD5($file)) {
print qq{CHECKSUM check for "$file" failed.\n};
unlink $file or warn qq{Cannot unlink "$file": $!\n};
return;
}
return 1;
}
# routines to verify the CHECKSUMS for a file
# adapted from the MD5 check of CPAN.pm
# load the CHECKSUMS file into $cksum
sub load_cs {
my $cs = shift;
my $fh = IO::File->new;
unless ($fh->open($cs)) {
warn qq{Could not open "$cs": $!\n};
return;
}
local($/);
my $eval = <$fh>;
$fh->close;
$eval =~ s/\015?\012/\n/g;
my $comp = Safe->new();
my $cksum = $comp->reval($eval);
if ($@) {
warn qq{eval of "$cs" failed: $@\n};
return;
}
return $cksum;
}
# verify a CHECKSUM for a file
sub verifyMD5 {
my $file = shift;
my ($is, $should);
my $fh = IO::File->new;
unless ($fh->open($file)) {
warn qq{Cannot open "$file": $!};
return;
}
binmode($fh);
unless ($is = Digest::MD5->new->addfile($fh)->hexdigest) {
warn qq{Could not compute checksum for "$file": $!};
$fh->close;
return;
}
$fh->close;
if ($should = $cksum->{$file}->{md5}) {
my $test = ($is eq $should);
printf qq{ Checksum for "$file" is %s\n},
($test) ? 'OK.' : 'NOT OK.';
return $test;
}
else {
warn qq{Checksum data for "$file" not present in $cs.\n};
return;
}
}
# get number of split files
sub get_max {
my $dir = $ftp->ls();
my $count = 0;
foreach (@$dir) {
$count++ if m!$dist.exe.\d+$!;
}
return $count;
}
|