3 # Copyright (C) 2006 OpenWrt.org
5 # This is free software, licensed under the GNU General Public License v2.
6 # See /LICENSE for more information.
12 my $target = shift @ARGV;
13 my $filename = shift @ARGV;
14 my $md5sum = shift @ARGV;
19 @ARGV > 0 or die "Syntax: $0 <target dir> <filename> <md5sum> <mirror> [<mirror> ...]\n";
23 my $res = `which $prog`;
25 $res =~ /^no / and return undef;
26 $res =~ /not found/ and return undef;
30 my $md5cmd = which
("md5sum");
31 $md5cmd or $md5cmd = which
("md5");
32 $md5cmd or die 'no md5 checksum program found, please install md5 or md5sum';
38 my $options = $ENV{WGET_OPTIONS
};
39 $options or $options = "";
41 open WGET
, "wget -t1 --timeout=20 $options -O- \"$mirror/$filename\" |" or die "Cannot launch wget.\n";
42 open MD5SUM
, "| $md5cmd > \"$target/$filename.md5sum\"" or die "Cannot launch md5sum.\n";
43 open OUTPUT
, "> $target/$filename.dl" or die "Cannot create file $target/$filename.dl: $!\n";
45 while (read WGET
, $buffer, 1048576) {
53 if (($?
>> 8) != 0 ) {
54 print STDERR
"Download failed.\n";
59 my $sum = `cat "$target/$filename.md5sum"`;
60 $sum =~ /^(\w+)\s*/ or die "Could not generate md5sum\n";
63 if (($md5sum =~ /\w{32}/) and ($sum ne $md5sum)) {
64 print STDERR
"MD5 sum of the downloaded file does not match - deleting download.\n";
69 unlink "$target/$filename";
70 system("mv \"$target/$filename.dl\" \"$target/$filename\"");
76 unlink "$target/$filename.dl";
77 unlink "$target/$filename.md5sum";
80 foreach my $mirror (@ARGV) {
81 if ($mirror =~ /^\@SF\/(.+)$/) {
83 open SF
, "wget -t1 -q -O- 'http://prdownloads.sourceforge.net/$sfpath/$filename' |";
85 /RADIO NAME=use_default VALUE=(\w+) OnClick="form\.submit\(\)">/ or
86 /type="radio" name="use_default" value="(\w+)" onclick="form\.submit\(\)"\/>/ and do {
87 push @mirrors, "http://$1.dl.sourceforge.net/sourceforge/$sfpath";
89 /<a href="\/.+\?use_mirror
=(\w
+)"><b>Download/ and do {
90 push @mirrors, "http
://$1.dl
.sourceforge
.net
/sourceforge/$sfpath";
93 push @mirrors, "http
://dl.sourceforge
.net
/sourceforge/$sfpath";
95 } elsif ($mirror =~ /^\@GNU\/(.+)$/) {
97 push @mirrors, "ftp
://ftp
.gnu
.org
/gnu/$gnupath";
98 push @mirrors, "ftp
://ftp
.belnet
.be
/mirror/ftp
.gnu
.org
/gnu/$gnupath";
99 push @mirrors, "ftp
://ftp
.mirror
.nl
/pub/mirror
/gnu/$gnupath";
100 push @mirrors, "http
://mirror
.switch
.ch
/ftp/mirror
/gnu/$gnupath";
101 push @mirrors, "ftp
://ftp
.uu
.net
/archive/systems
/gnu/$gnupath";
102 push @mirrors, "ftp
://ftp
.eu
.uu
.net
/pub/gnu
/$gnupath";
103 push @mirrors, "ftp
://ftp
.leo
.org
/pub/comp/os/unix
/gnu/$gnupath";
104 push @mirrors, "ftp
://ftp
.digex
.net
/pub/gnu
/$gnupath";
106 push @mirrors, $mirror;
110 #push @mirrors, 'http://mirror1.openwrt.org/';
111 push @mirrors, 'http://mirror2.openwrt.org/sources';
112 push @mirrors, 'http://downloads.openwrt.org/sources/';
115 my $mirror = shift @mirrors;
116 $mirror or die "No more mirrors to try
- giving up
.\n";
119 -f "$target/$filename" and $ok = 1;
122 $SIG{INT} = \&cleanup;
This page took 0.06822 seconds and 5 git commands to generate.