5 my $target = shift @ARGV;
6 my $filename = shift @ARGV;
7 my $md5sum = shift @ARGV;
12 @ARGV > 0 or die "Syntax: $0 <target dir> <filename> <md5sum> <mirror> [<mirror> ...]\n";
18 open WGET
, "wget -t1 --timeout=20 -O- \"$mirror/$filename\" |" or die "Cannot launch wget.\n";
19 open MD5SUM
, "| md5sum > \"$target/$filename.md5sum\"" or die "Cannot launch md5sum.\n";
20 open OUTPUT
, "> $target/$filename.dl" or die "Cannot create file $target/$filename.dl: $!\n";
22 while (read WGET
, $buffer, 1048576) {
30 if (($?
>> 8) != 0 ) {
31 print STDERR
"Download failed.\n";
36 my $sum = `cat "$target/$filename.md5sum"`;
37 $sum =~ /^(\w+)\s+/ or die "Could not generate md5sum\n";
40 if (($md5sum =~ /\w{32}/) and ($sum ne $md5sum)) {
41 print STDERR
"MD5 sum of the downloaded file does not match - deleting download.\n";
46 unlink "$target/$filename";
47 system("mv \"$target/$filename.dl\" \"$target/$filename\"");
53 unlink "$target/$filename.dl";
54 unlink "$target/$filename.md5sum";
57 foreach my $mirror (@ARGV) {
58 if ($mirror =~ /^\@SF\/(.+)$/) {
60 open SF
, "wget -t1 -q -O- 'http://prdownloads.sourceforge.net/$sfpath/$filename' |";
62 /RADIO NAME=use_default VALUE=(\w+) OnClick="form\.submit\(\)">/ and do {
63 push @mirrors, "http://$1.dl.sourceforge.net/sourceforge/$sfpath";
67 } elsif ($mirror =~ /^\@GNU\/(.+)$/) {
69 push @mirrors, "ftp://ftp.gnu.org/gnu/$gnupath";
70 push @mirrors, "ftp://ftp.belnet.be/mirror/ftp.gnu.org/gnu/$gnupath";
71 push @mirrors, "ftp://ftp.mirror.nl/pub/mirror/gnu/$gnupath";
72 push @mirrors, "http://mirror.switch.ch/ftp/mirror/gnu/$gnupath";
74 push @mirrors, $mirror;
78 push @mirrors, 'http://mirror1.openwrt.org/';
79 push @mirrors, 'http://mirror2.openwrt.org/';
80 push @mirrors, 'http://downloads.openwrt.org/sources/';
83 my $mirror = shift @mirrors;
84 $mirror or die "No more mirrors to try - giving up.\n";
87 -f
"$target/$filename" and $ok = 1;
90 $SIG{INT
} = \
&cleanup
;
This page took 0.057199 seconds and 5 git commands to generate.