2008-09-23 18:29:44 +00:00
|
|
|
#!/usr/bin/env perl
|
2006-06-27 00:35:46 +00:00
|
|
|
#
|
|
|
|
# Copyright (C) 2006 OpenWrt.org
|
2016-04-03 22:02:46 +02:00
|
|
|
# Copyright (C) 2016 LEDE project
|
2006-06-27 00:35:46 +00:00
|
|
|
#
|
|
|
|
# This is free software, licensed under the GNU General Public License v2.
|
|
|
|
# See /LICENSE for more information.
|
|
|
|
#
|
|
|
|
|
2005-03-19 22:51:51 +00:00
|
|
|
use strict;
|
|
|
|
use warnings;
|
2007-01-24 22:38:02 +00:00
|
|
|
use File::Basename;
|
2012-04-10 14:11:45 +00:00
|
|
|
use File::Copy;
|
2016-11-20 16:01:33 -05:00
|
|
|
use Text::ParseWords;
|
2005-03-19 22:51:51 +00:00
|
|
|
|
2016-01-16 00:19:41 +00:00
|
|
|
@ARGV > 2 or die "Syntax: $0 <target dir> <filename> <hash> <url filename> [<mirror> ...]\n";
|
2007-09-29 00:05:48 +00:00
|
|
|
|
2015-11-22 19:06:33 +00:00
|
|
|
my $url_filename;
|
2017-08-26 15:14:20 +02:00
|
|
|
my $target = glob(shift @ARGV);
|
2005-03-19 22:51:51 +00:00
|
|
|
my $filename = shift @ARGV;
|
2016-01-16 00:19:41 +00:00
|
|
|
my $file_hash = shift @ARGV;
|
2015-11-22 19:06:33 +00:00
|
|
|
$url_filename = shift @ARGV unless $ARGV[0] =~ /:\/\//;
|
2007-01-24 22:38:02 +00:00
|
|
|
my $scriptdir = dirname($0);
|
2005-04-30 19:47:17 +00:00
|
|
|
my @mirrors;
|
2005-03-19 22:51:51 +00:00
|
|
|
my $ok;
|
|
|
|
|
2022-07-23 11:23:16 -04:00
|
|
|
my $check_certificate = $ENV{DOWNLOAD_CHECK_CERTIFICATE} eq "y";
|
|
|
|
|
2015-11-22 19:06:33 +00:00
|
|
|
$url_filename or $url_filename = $filename;
|
|
|
|
|
2007-01-24 22:38:02 +00:00
|
|
|
sub localmirrors {
|
2008-03-18 21:07:22 +00:00
|
|
|
my @mlist;
|
|
|
|
open LM, "$scriptdir/localmirrors" and do {
|
2007-04-06 23:15:39 +00:00
|
|
|
while (<LM>) {
|
|
|
|
chomp $_;
|
2011-07-03 19:33:24 +00:00
|
|
|
push @mlist, $_ if $_;
|
2007-04-06 23:15:39 +00:00
|
|
|
}
|
|
|
|
close LM;
|
|
|
|
};
|
|
|
|
open CONFIG, "<".$ENV{'TOPDIR'}."/.config" and do {
|
|
|
|
while (<CONFIG>) {
|
|
|
|
/^CONFIG_LOCALMIRROR="(.+)"/ and do {
|
|
|
|
chomp;
|
2009-02-20 10:16:47 +00:00
|
|
|
my @local_mirrors = split(/;/, $1);
|
|
|
|
push @mlist, @local_mirrors;
|
2007-04-06 23:15:39 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
close CONFIG;
|
|
|
|
};
|
2007-01-24 22:38:02 +00:00
|
|
|
|
2014-12-12 12:35:23 +00:00
|
|
|
my $mirror = $ENV{'DOWNLOAD_MIRROR'};
|
|
|
|
$mirror and push @mlist, split(/;/, $mirror);
|
|
|
|
|
2008-03-18 21:07:22 +00:00
|
|
|
return @mlist;
|
2007-01-24 22:38:02 +00:00
|
|
|
}
|
|
|
|
|
2006-10-14 00:07:19 +00:00
|
|
|
sub which($) {
|
|
|
|
my $prog = shift;
|
|
|
|
my $res = `which $prog`;
|
|
|
|
$res or return undef;
|
|
|
|
$res =~ /^no / and return undef;
|
|
|
|
$res =~ /not found/ and return undef;
|
|
|
|
return $res;
|
|
|
|
}
|
|
|
|
|
2016-01-16 00:19:41 +00:00
|
|
|
sub hash_cmd() {
|
|
|
|
my $len = length($file_hash);
|
|
|
|
my $cmd;
|
|
|
|
|
2016-12-25 16:40:05 +01:00
|
|
|
$len == 64 and return "mkhash sha256";
|
|
|
|
$len == 32 and return "mkhash md5";
|
2016-01-16 00:19:41 +00:00
|
|
|
return undef;
|
|
|
|
}
|
|
|
|
|
2016-11-20 16:01:33 -05:00
|
|
|
sub download_cmd($) {
|
|
|
|
my $url = shift;
|
|
|
|
my $have_curl = 0;
|
|
|
|
|
2022-09-13 07:38:10 +02:00
|
|
|
if (open CURL, "curl --version 2>/dev/null |") {
|
2016-11-20 16:01:33 -05:00
|
|
|
if (defined(my $line = readline CURL)) {
|
|
|
|
$have_curl = 1 if $line =~ /^curl /;
|
|
|
|
}
|
|
|
|
close CURL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $have_curl
|
2022-09-13 07:40:37 +02:00
|
|
|
? (qw(curl -f --connect-timeout 20 --retry 5 --location),
|
|
|
|
$check_certificate ? () : '--insecure',
|
|
|
|
shellwords($ENV{CURL_OPTIONS} || ''),
|
|
|
|
$url)
|
|
|
|
: (qw(wget --tries=5 --timeout=20 --output-document=-),
|
|
|
|
$check_certificate ? () : '--no-check-certificate',
|
|
|
|
shellwords($ENV{WGET_OPTIONS} || ''),
|
|
|
|
$url)
|
2016-11-20 16:01:33 -05:00
|
|
|
;
|
|
|
|
}
|
|
|
|
|
2016-01-16 00:19:41 +00:00
|
|
|
my $hash_cmd = hash_cmd();
|
2017-12-12 14:55:11 +01:00
|
|
|
$hash_cmd or ($file_hash eq "skip") or die "Cannot find appropriate hash command, ensure the provided hash is either a MD5 or SHA256 checksum.\n";
|
2006-10-10 16:01:49 +00:00
|
|
|
|
2005-03-19 22:51:51 +00:00
|
|
|
sub download
|
|
|
|
{
|
|
|
|
my $mirror = shift;
|
2020-11-18 16:02:23 +01:00
|
|
|
my $download_filename = shift;
|
2012-05-11 18:17:15 +00:00
|
|
|
|
|
|
|
$mirror =~ s!/$!!;
|
|
|
|
|
|
|
|
if ($mirror =~ s!^file://!!) {
|
|
|
|
if (! -d "$mirror") {
|
|
|
|
print STDERR "Wrong local cache directory -$mirror-.\n";
|
2009-02-20 10:16:47 +00:00
|
|
|
cleanup();
|
|
|
|
return;
|
|
|
|
}
|
2012-05-11 18:17:15 +00:00
|
|
|
|
|
|
|
if (! -d "$target") {
|
|
|
|
system("mkdir", "-p", "$target/");
|
2009-02-20 10:16:47 +00:00
|
|
|
}
|
2012-05-11 18:17:15 +00:00
|
|
|
|
|
|
|
if (! open TMPDLS, "find $mirror -follow -name $filename 2>/dev/null |") {
|
|
|
|
print("Failed to search for $filename in $mirror\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $link;
|
|
|
|
|
|
|
|
while (defined(my $line = readline TMPDLS)) {
|
|
|
|
chomp ($link = $line);
|
|
|
|
if ($. > 1) {
|
|
|
|
print("$. or more instances of $filename in $mirror found . Only one instance allowed.\n");
|
2012-04-10 14:11:45 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-05-11 18:17:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
close TMPDLS;
|
|
|
|
|
|
|
|
if (! $link) {
|
|
|
|
print("No instances of $filename found in $mirror.\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
print("Copying $filename from $link\n");
|
|
|
|
copy($link, "$target/$filename.dl");
|
|
|
|
|
2016-01-16 00:19:41 +00:00
|
|
|
$hash_cmd and do {
|
2016-02-27 16:20:06 +00:00
|
|
|
if (system("cat '$target/$filename.dl' | $hash_cmd > '$target/$filename.hash'")) {
|
2016-01-16 00:19:41 +00:00
|
|
|
print("Failed to generate hash for $filename\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
2008-03-18 21:07:22 +00:00
|
|
|
} else {
|
2020-11-18 16:02:23 +01:00
|
|
|
my @cmd = download_cmd("$mirror/$download_filename");
|
2017-05-09 15:20:42 +02:00
|
|
|
print STDERR "+ ".join(" ",@cmd)."\n";
|
2016-11-20 16:01:33 -05:00
|
|
|
open(FETCH_FD, '-|', @cmd) or die "Cannot launch curl or wget.\n";
|
2016-01-16 00:19:41 +00:00
|
|
|
$hash_cmd and do {
|
|
|
|
open MD5SUM, "| $hash_cmd > '$target/$filename.hash'" or die "Cannot launch $hash_cmd.\n";
|
|
|
|
};
|
2008-03-18 21:07:22 +00:00
|
|
|
open OUTPUT, "> $target/$filename.dl" or die "Cannot create file $target/$filename.dl: $!\n";
|
|
|
|
my $buffer;
|
2016-11-20 16:01:33 -05:00
|
|
|
while (read FETCH_FD, $buffer, 1048576) {
|
2016-01-16 00:19:41 +00:00
|
|
|
$hash_cmd and print MD5SUM $buffer;
|
2008-03-18 21:07:22 +00:00
|
|
|
print OUTPUT $buffer;
|
|
|
|
}
|
2016-01-16 00:19:41 +00:00
|
|
|
$hash_cmd and close MD5SUM;
|
2016-11-20 16:01:33 -05:00
|
|
|
close FETCH_FD;
|
2008-03-18 21:07:22 +00:00
|
|
|
close OUTPUT;
|
|
|
|
|
2012-05-11 18:17:15 +00:00
|
|
|
if ($? >> 8) {
|
2008-03-18 21:07:22 +00:00
|
|
|
print STDERR "Download failed.\n";
|
|
|
|
cleanup();
|
|
|
|
return;
|
|
|
|
}
|
2005-03-19 22:51:51 +00:00
|
|
|
}
|
2008-03-18 21:07:22 +00:00
|
|
|
|
2016-01-16 00:19:41 +00:00
|
|
|
$hash_cmd and do {
|
|
|
|
my $sum = `cat "$target/$filename.hash"`;
|
|
|
|
$sum =~ /^(\w+)\s*/ or die "Could not generate file hash\n";
|
|
|
|
$sum = $1;
|
2008-03-18 21:07:22 +00:00
|
|
|
|
2016-01-16 00:19:41 +00:00
|
|
|
if ($sum ne $file_hash) {
|
2017-04-04 11:44:22 +02:00
|
|
|
print STDERR "Hash of the downloaded file does not match (file: $sum, requested: $file_hash) - deleting download.\n";
|
2016-01-16 00:19:41 +00:00
|
|
|
cleanup();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
};
|
2008-03-18 21:07:22 +00:00
|
|
|
|
2005-03-19 22:51:51 +00:00
|
|
|
unlink "$target/$filename";
|
2012-05-11 18:17:15 +00:00
|
|
|
system("mv", "$target/$filename.dl", "$target/$filename");
|
2005-03-19 23:52:32 +00:00
|
|
|
cleanup();
|
2005-03-19 22:51:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub cleanup
|
|
|
|
{
|
|
|
|
unlink "$target/$filename.dl";
|
2016-01-16 00:19:41 +00:00
|
|
|
unlink "$target/$filename.hash";
|
2005-03-19 22:51:51 +00:00
|
|
|
}
|
|
|
|
|
2007-01-24 22:38:02 +00:00
|
|
|
@mirrors = localmirrors();
|
|
|
|
|
2005-04-30 19:47:17 +00:00
|
|
|
foreach my $mirror (@ARGV) {
|
2005-03-19 22:51:51 +00:00
|
|
|
if ($mirror =~ /^\@SF\/(.+)$/) {
|
2006-12-08 12:44:26 +00:00
|
|
|
# give sourceforge a few more tries, because it redirects to different mirrors
|
|
|
|
for (1 .. 5) {
|
2018-02-20 12:43:00 -08:00
|
|
|
push @mirrors, "https://downloads.sourceforge.net/$1";
|
2005-03-19 22:51:51 +00:00
|
|
|
}
|
2021-01-30 10:54:44 -10:00
|
|
|
} elsif ($mirror =~ /^\@OPENWRT$/) {
|
|
|
|
# use OpenWrt source server directly
|
2022-07-12 15:19:04 +08:00
|
|
|
} elsif ($mirror =~ /^\@IMMORTALWRT$/) {
|
|
|
|
# use ImmortalWrt source server directly
|
2022-12-11 13:44:25 +08:00
|
|
|
} elsif ($mirror =~ /^\@DEBIAN\/(.+)$/) {
|
|
|
|
push @mirrors, "https://mirrors.tencent.com/debian/$1";
|
|
|
|
push @mirrors, "https://mirrors.aliyun.com/debian/$1";
|
|
|
|
push @mirrors, "https://mirrors.tuna.tsinghua.edu.cn/debian/$1";
|
|
|
|
push @mirrors, "https://mirrors.ustc.edu.cn/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";
|
|
|
|
push @mirrors, "https://mirrors.tuna.tsinghua.edu.cn/debian/$1";
|
|
|
|
push @mirrors, "https://mirrors.ustc.edu.cn/debian/$1"
|
2016-01-17 10:47:32 +00:00
|
|
|
} elsif ($mirror =~ /^\@APACHE\/(.+)$/) {
|
2021-03-11 14:57:01 +08:00
|
|
|
push @mirrors, "https://mirrors.tencent.com/apache/$1";
|
2020-04-08 00:30:40 +08:00
|
|
|
push @mirrors, "https://mirrors.aliyun.com/apache/$1";
|
2022-12-11 13:44:25 +08:00
|
|
|
push @mirrors, "https://mirrors.tuna.tsinghua.edu.cn/apache/$1";
|
|
|
|
push @mirrors, "https://mirrors.ustc.edu.cn/apache/$1";
|
2016-05-24 14:52:54 +02:00
|
|
|
push @mirrors, "https://mirror.netcologne.de/apache.org/$1";
|
|
|
|
push @mirrors, "https://mirror.aarnet.edu.au/pub/apache/$1";
|
2017-06-25 18:14:33 +02:00
|
|
|
push @mirrors, "https://mirror.csclub.uwaterloo.ca/apache/$1";
|
2019-11-28 16:29:31 +01:00
|
|
|
push @mirrors, "https://archive.apache.org/dist/$1";
|
2016-05-24 14:52:54 +02:00
|
|
|
push @mirrors, "http://mirror.cogentco.com/pub/apache/$1";
|
|
|
|
push @mirrors, "http://mirror.navercorp.com/apache/$1";
|
2016-01-17 10:47:32 +00:00
|
|
|
push @mirrors, "http://ftp.jaist.ac.jp/pub/apache/$1";
|
2016-05-24 14:52:54 +02:00
|
|
|
push @mirrors, "ftp://apache.cs.utah.edu/apache.org/$1";
|
|
|
|
push @mirrors, "ftp://apache.mirrors.ovh.net/ftp.apache.org/dist/$1";
|
2016-04-09 10:25:34 +00:00
|
|
|
} elsif ($mirror =~ /^\@GITHUB\/(.+)$/) {
|
2019-11-12 12:51:10 +08:00
|
|
|
my $dir = $1;
|
|
|
|
my $i = 0;
|
|
|
|
# replace the 2nd '/' with '@' for jsDelivr mirror
|
|
|
|
push @mirrors, "https://cdn.jsdelivr.net/gh/". $dir =~ s{\/}{++$i == 2 ? '@' : $&}ger;
|
2021-03-11 14:57:01 +08:00
|
|
|
push @mirrors, "https://raw.sevencdn.com/$dir";
|
2021-03-15 11:19:22 +08:00
|
|
|
push @mirrors, "https://raw.fastgit.org/$dir";
|
2016-04-09 10:25:34 +00:00
|
|
|
# give github a few more tries (different mirrors)
|
|
|
|
for (1 .. 5) {
|
2019-11-12 12:51:10 +08:00
|
|
|
push @mirrors, "https://raw.githubusercontent.com/$dir";
|
2016-04-09 10:25:34 +00:00
|
|
|
}
|
2005-06-08 06:48:19 +00:00
|
|
|
} elsif ($mirror =~ /^\@GNU\/(.+)$/) {
|
2021-03-11 14:57:01 +08:00
|
|
|
push @mirrors, "https://mirrors.tencent.com/gnu/$1";
|
2021-06-19 18:30:22 +08:00
|
|
|
push @mirrors, "https://mirrors.aliyun.com/gnu/$1";
|
2022-12-11 13:44:25 +08:00
|
|
|
push @mirrors, "https://mirrors.tuna.tsinghua.edu.cn/gnu/$1";
|
|
|
|
push @mirrors, "https://mirrors.ustc.edu.cn/gnu/$1";
|
2017-06-25 18:14:33 +02:00
|
|
|
push @mirrors, "https://mirror.csclub.uwaterloo.ca/gnu/$1";
|
2016-05-24 14:52:54 +02:00
|
|
|
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";
|
2017-06-25 18:14:33 +02:00
|
|
|
push @mirrors, "ftp://mirrors.rit.edu/gnu/$1";
|
2016-05-24 14:52:54 +02:00
|
|
|
push @mirrors, "ftp://download.xs4all.nl/pub/gnu/";
|
2014-10-08 08:01:39 +00:00
|
|
|
} elsif ($mirror =~ /^\@SAVANNAH\/(.+)$/) {
|
2016-05-24 14:52:54 +02:00
|
|
|
push @mirrors, "https://mirror.netcologne.de/savannah/$1";
|
2017-06-25 18:14:33 +02:00
|
|
|
push @mirrors, "https://mirror.csclub.uwaterloo.ca/nongnu/$1";
|
2016-05-24 14:52:54 +02:00
|
|
|
push @mirrors, "http://ftp.acc.umu.se/mirror/gnu.org/savannah/$1";
|
2014-10-08 08:01:39 +00:00
|
|
|
push @mirrors, "http://nongnu.uib.no/$1";
|
|
|
|
push @mirrors, "http://ftp.igh.cnrs.fr/pub/nongnu/$1";
|
2016-05-24 14:52:54 +02:00
|
|
|
push @mirrors, "ftp://cdimage.debian.org/mirror/gnu.org/savannah/$1";
|
|
|
|
push @mirrors, "ftp://ftp.acc.umu.se/mirror/gnu.org/savannah/$1";
|
2007-08-26 18:21:24 +00:00
|
|
|
} elsif ($mirror =~ /^\@KERNEL\/(.+)$/) {
|
2011-02-19 15:41:00 +00:00
|
|
|
my @extra = ( $1 );
|
2011-07-03 15:00:24 +00:00
|
|
|
if ($filename =~ /linux-\d+\.\d+(?:\.\d+)?-rc/) {
|
2011-02-19 15:41:00 +00:00
|
|
|
push @extra, "$extra[0]/testing";
|
2011-07-03 15:00:24 +00:00
|
|
|
} elsif ($filename =~ /linux-(\d+\.\d+(?:\.\d+)?)/) {
|
2011-02-19 15:41:00 +00:00
|
|
|
push @extra, "$extra[0]/longterm/v$1";
|
2019-09-16 08:02:16 +00:00
|
|
|
}
|
2011-02-19 15:41:00 +00:00
|
|
|
foreach my $dir (@extra) {
|
2022-12-11 13:44:25 +08:00
|
|
|
push @mirrors, "https://mirror.iscas.ac.cn/kernel.org/$dir";
|
|
|
|
push @mirrors, "https://mirrors.ustc.edu.cn/kernel.org/$dir";
|
|
|
|
push @mirrors, "https://mirror.nju.edu.cn/kernel.org/$dir";
|
2016-05-23 12:55:01 +02:00
|
|
|
push @mirrors, "https://cdn.kernel.org/pub/$dir";
|
2022-12-11 22:37:35 +08:00
|
|
|
push @mirrors, "https://ftp.jaist.ac.jp/pub/Linux/kernel.org/$dir";
|
2019-09-16 08:02:16 +00:00
|
|
|
push @mirrors, "https://download.xs4all.nl/ftp.kernel.org/pub/$dir";
|
|
|
|
push @mirrors, "https://mirrors.mit.edu/kernel/$dir";
|
2016-05-24 14:52:54 +02:00
|
|
|
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";
|
2011-02-19 15:41:00 +00:00
|
|
|
}
|
2020-08-09 00:33:57 +02:00
|
|
|
} elsif ($mirror =~ /^\@GNOME\/(.+)$/) {
|
2022-12-11 13:44:25 +08:00
|
|
|
push @mirrors, "https://mirrors.ustc.edu.cn/gnome/sources/$1";
|
|
|
|
push @mirrors, "https://mirror.nju.edu.cn/gnome/$1";
|
|
|
|
push @mirrors, "https://download.gnome.org/sources/$1";
|
2017-06-25 18:14:33 +02:00
|
|
|
push @mirrors, "https://mirror.csclub.uwaterloo.ca/gnome/sources/$1";
|
2008-09-01 21:46:17 +00:00
|
|
|
push @mirrors, "http://ftp.acc.umu.se/pub/GNOME/sources/$1";
|
2016-05-24 14:52:54 +02:00
|
|
|
push @mirrors, "http://ftp.kaist.ac.kr/gnome/sources/$1";
|
|
|
|
push @mirrors, "http://www.mirrorservice.org/sites/ftp.gnome.org/pub/GNOME/sources/$1";
|
|
|
|
push @mirrors, "http://mirror.internode.on.net/pub/gnome/sources/$1";
|
2015-12-10 12:40:08 +00:00
|
|
|
push @mirrors, "http://ftp.belnet.be/ftp.gnome.org/sources/$1";
|
2008-09-01 21:46:17 +00:00
|
|
|
push @mirrors, "ftp://ftp.cse.buffalo.edu/pub/Gnome/sources/$1";
|
|
|
|
push @mirrors, "ftp://ftp.nara.wide.ad.jp/pub/X11/GNOME/sources/$1";
|
2020-08-09 00:33:57 +02:00
|
|
|
} else {
|
2005-04-30 19:47:17 +00:00
|
|
|
push @mirrors, $mirror;
|
2005-03-19 22:51:51 +00:00
|
|
|
}
|
2005-04-30 19:47:17 +00:00
|
|
|
}
|
|
|
|
|
2021-11-29 13:23:45 +08:00
|
|
|
# push @mirrors, 'https://mirror01.download.immortalwrt.eu.org';
|
2022-12-11 12:51:49 +08:00
|
|
|
push @mirrors, 'https://mirror2.immortalwrt.org/sources';
|
2021-11-30 20:14:11 +08:00
|
|
|
push @mirrors, 'https://mirror.immortalwrt.org/sources';
|
2023-03-15 17:44:32 +08:00
|
|
|
push @mirrors, 'https://sources-cdn.immortalwrt.org';
|
2021-11-27 03:09:47 +08:00
|
|
|
push @mirrors, 'https://sources.immortalwrt.org';
|
2021-01-26 18:13:28 -10:00
|
|
|
push @mirrors, 'https://sources.cdn.openwrt.org';
|
2019-08-18 15:18:10 +00:00
|
|
|
push @mirrors, 'https://sources.openwrt.org';
|
2018-02-20 12:43:01 -08:00
|
|
|
push @mirrors, 'https://mirror2.openwrt.org/sources';
|
2005-04-30 19:47:17 +00:00
|
|
|
|
2020-11-19 16:32:46 +01:00
|
|
|
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;
|
|
|
|
|
2020-11-27 21:56:30 +01:00
|
|
|
cleanup();
|
2020-11-19 16:32:46 +01:00
|
|
|
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";
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-12-16 15:15:48 +01:00
|
|
|
while (!-f "$target/$filename") {
|
2005-04-30 19:47:17 +00:00
|
|
|
my $mirror = shift @mirrors;
|
|
|
|
$mirror or die "No more mirrors to try - giving up.\n";
|
2008-03-18 21:07:22 +00:00
|
|
|
|
2020-11-18 16:02:23 +01:00
|
|
|
download($mirror, $url_filename);
|
|
|
|
if (!-f "$target/$filename" && $url_filename ne $filename) {
|
|
|
|
download($mirror, $filename);
|
|
|
|
}
|
2005-03-19 22:51:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$SIG{INT} = \&cleanup;
|
|
|
|
|