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";
25 open WGET
, "wget -t1 --timeout=20 -O- \"$mirror/$filename\" |" or die "Cannot launch wget.\n";
26 open MD5SUM
, "| md5sum > \"$target/$filename.md5sum\"" or die "Cannot launch md5sum.\n";
27 open OUTPUT
, "> $target/$filename.dl" or die "Cannot create file $target/$filename.dl: $!\n";
29 while (read WGET
, $buffer, 1048576) {
37 if (($?
>> 8) != 0 ) {
38 print STDERR
"Download failed.\n";
43 my $sum = `cat "$target/$filename.md5sum"`;
44 $sum =~ /^(\w+)\s+/ or die "Could not generate md5sum\n";
47 if (($md5sum =~ /\w{32}/) and ($sum ne $md5sum)) {
48 print STDERR
"MD5 sum of the downloaded file does not match - deleting download.\n";
53 unlink "$target/$filename";
54 system("mv \"$target/$filename.dl\" \"$target/$filename\"");
60 unlink "$target/$filename.dl";
61 unlink "$target/$filename.md5sum";
64 foreach my $mirror (@ARGV) {
65 if ($mirror =~ /^\@SF\/(.+)$/) {
67 open SF
, "wget -t1 -q -O- 'http://prdownloads.sourceforge.net/$sfpath/$filename' |";
69 /RADIO NAME=use_default VALUE=(\w+) OnClick="form\.submit\(\)">/ or
70 /type="radio" name="use_default" value="(\w+)" onclick="form\.submit\(\)"\/>/ and do {
71 push @mirrors, "http://$1.dl.sourceforge.net/sourceforge/$sfpath";
73 /<a href="\/.+\?use_mirror
=(\w
+)"><b>Download/ and do {
74 push @mirrors, "http
://$1.dl
.sourceforge
.net
/sourceforge/$sfpath";
77 push @mirrors, "http
://dl.sourceforge
.net
/sourceforge/$sfpath";
79 } elsif ($mirror =~ /^\@GNU\/(.+)$/) {
81 push @mirrors, "ftp
://ftp
.gnu
.org
/gnu/$gnupath";
82 push @mirrors, "ftp
://ftp
.belnet
.be
/mirror/ftp
.gnu
.org
/gnu/$gnupath";
83 push @mirrors, "ftp
://ftp
.mirror
.nl
/pub/mirror
/gnu/$gnupath";
84 push @mirrors, "http
://mirror
.switch
.ch
/ftp/mirror
/gnu/$gnupath";
85 push @mirrors, "ftp
://ftp
.uu
.net
/archive/systems
/gnu/$gnupath";
86 push @mirrors, "ftp
://ftp
.eu
.uu
.net
/pub/gnu
/$gnupath";
87 push @mirrors, "ftp
://ftp
.leo
.org
/pub/comp/os/unix
/gnu/$gnupath";
88 push @mirrors, "ftp
://ftp
.digex
.net
/pub/gnu
/$gnupath";
90 push @mirrors, $mirror;
94 push @mirrors, 'http://mirror1.openwrt.org/';
95 push @mirrors, 'http://mirror2.openwrt.org/';
96 push @mirrors, 'http://downloads.openwrt.org/sources/';
99 my $mirror = shift @mirrors;
100 $mirror or die "No more mirrors to try
- giving up
.\n";
103 -f "$target/$filename" and $ok = 1;
106 $SIG{INT} = \&cleanup;
This page took 0.054997 seconds and 5 git commands to generate.