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
| sed -i "/@mirrors = localmirrors();/Q" ./scripts/download.pl cat >> scripts/download.pl << "EOF" @mirrors = localmirrors();
foreach my $mirror (@ARGV) { if ($mirror =~ /^\@SF\/(.+)$/) { # give sourceforge a few more tries, because it redirects to different mirrors for (1 .. 5) { push @mirrors, "https://qa.debian.org/watch/sf.php/$1"; } } elsif ($mirror =~ /^\@OPENWRT$/) { # use OpenWrt source server directly } elsif ($mirror =~ /^\@DEBIAN\/(.+)$/) { push @mirrors, "https://mirrors.aliyun.com/debian/$1"; push @mirrors, "https://mirrors.tencent.com/debian/$1"; push @mirrors, "https://ftp.debian.org/debian/$1"; push @mirrors, "https://mirror.leaseweb.com/debian/$1"; push @mirrors, "https://mirror.netcologne.de/debian/$1"; } elsif ($mirror =~ /^\@APACHE\/(.+)$/) { push @mirrors, "https://mirrors.aliyun.com/apache/$1"; push @mirrors, "https://mirrors.tencent.com/apache/$1"; push @mirrors, "https://mirror.netcologne.de/apache.org/$1"; push @mirrors, "https://mirror.aarnet.edu.au/pub/apache/$1"; push @mirrors, "https://mirror.csclub.uwaterloo.ca/apache/$1"; push @mirrors, "https://archive.apache.org/dist/$1"; push @mirrors, "http://mirror.cogentco.com/pub/apache/$1"; push @mirrors, "http://mirror.navercorp.com/apache/$1"; push @mirrors, "http://ftp.jaist.ac.jp/pub/apache/$1"; push @mirrors, "ftp://apache.cs.utah.edu/apache.org/$1"; push @mirrors, "ftp://apache.mirrors.ovh.net/ftp.apache.org/dist/$1"; } elsif ($mirror =~ /^\@GITHUB\/(.+)$/) { # give github a few more tries (different mirrors) for (1 .. 5) { push @mirrors, "https://ghproxy.cn/https://raw.githubusercontent.com/$1"; } } elsif ($mirror =~ /^\@GNU\/(.+)$/) { push @mirrors, "https://mirrors.aliyun.com/gnu/$1"; push @mirrors, "https://mirrors.tencent.com/gnu/$1"; push @mirrors, "https://mirror.csclub.uwaterloo.ca/gnu/$1"; push @mirrors, "https://mirror.netcologne.de/gnu/$1"; push @mirrors, "http://ftp.kddilabs.jp/GNU/gnu/$1"; push @mirrors, "http://www.nic.funet.fi/pub/gnu/gnu/$1"; push @mirrors, "http://mirror.internode.on.net/pub/gnu/$1"; push @mirrors, "http://mirror.navercorp.com/gnu/$1"; push @mirrors, "ftp://mirrors.rit.edu/gnu/$1"; push @mirrors, "ftp://download.xs4all.nl/pub/gnu/$1"; push @mirrors, "https://ftp.gnu.org/gnu/$1"; } elsif ($mirror =~ /^\@SAVANNAH\/(.+)$/) { push @mirrors, "https://study-download.nuoyis.net/savannah/$1"; push @mirrors, "https://mirror.csclub.uwaterloo.ca/nongnu/$1"; push @mirrors, "http://ftp.acc.umu.se/mirror/gnu.org/savannah/$1"; push @mirrors, "http://nongnu.uib.no/$1"; push @mirrors, "http://ftp.igh.cnrs.fr/pub/nongnu/$1"; push @mirrors, "ftp://cdimage.debian.org/mirror/gnu.org/savannah/$1"; push @mirrors, "ftp://ftp.acc.umu.se/mirror/gnu.org/savannah/$1"; } elsif ($mirror =~ /^\@KERNEL\/(.+)$/) { my @extra = ( $1 ); if ($filename =~ /linux-\d+\.\d+(?:\.\d+)?-rc/) { push @extra, "$extra[0]/testing"; } elsif ($filename =~ /linux-(\d+\.\d+(?:\.\d+)?)/) { push @extra, "$extra[0]/longterm/v$1"; } foreach my $dir (@extra) { push @mirrors, "https://mirror.iscas.ac.cn/kernel.org/$dir"; push @mirrors, "https://mirrors.ustc.edu.cn/kernel.org/$dir"; push @mirrors, "https://cdn.kernel.org/pub/$dir"; push @mirrors, "https://download.xs4all.nl/ftp.kernel.org/pub/$dir"; push @mirrors, "https://mirrors.mit.edu/kernel/$dir"; push @mirrors, "http://ftp.nara.wide.ad.jp/pub/kernel.org/$dir"; push @mirrors, "http://www.ring.gr.jp/archives/linux/kernel.org/$dir"; push @mirrors, "ftp://ftp.riken.jp/Linux/kernel.org/$dir"; push @mirrors, "ftp://www.mirrorservice.org/sites/ftp.kernel.org/pub/$dir"; } } elsif ($mirror =~ /^\@GNOME\/(.+)$/) { push @mirrors, "https://mirrors.ustc.edu.cn/gnome/sources/$1"; push @mirrors, "https://download.gnome.org/sources/$1"; push @mirrors, "https://mirror.csclub.uwaterloo.ca/gnome/sources/$1"; push @mirrors, "http://ftp.acc.umu.se/pub/GNOME/sources/$1"; push @mirrors, "http://ftp.cse.buffalo.edu/pub/Gnome/sources/$1"; push @mirrors, "http://ftp.nara.wide.ad.jp/pub/X11/GNOME/sources/$1"; } else { push @mirrors, $mirror; } }
push @mirrors, 'https://study-download.nuoyis.net/openwrt/'; push @mirrors, 'https://openwrt-download.nuoyis.eu.org'; push @mirrors, 'https://sources.openwrt.org';
if (-f "$target/$filename") { $hash_cmd and do { if (system("cat '$target/$filename' | $hash_cmd > '$target/$filename.hash'")) { die "Failed to generate hash for $filename\n"; }
my $sum = `cat "$target/$filename.hash"`; $sum =~ /^(\w+)\s*/ or die "Could not generate file hash\n"; $sum = $1;
cleanup(); exit 0 if $sum eq $file_hash;
die "Hash of the local file $filename does not match (file: $sum, requested: $file_hash) - deleting download.\n"; unlink "$target/$filename"; }; }
$download_tool = select_tool();
while (!-f "$target/$filename") { my $mirror = shift @mirrors; $mirror or die "No more mirrors to try - giving up.\n";
download($mirror, $url_filename, @mirrors); if (!-f "$target/$filename" && $url_filename ne $filename) { download($mirror, $filename, @mirrors); } }
$SIG{INT} = \&cleanup; EOF
|