aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorBradford Zhang <zyc@zyc.name>2022-09-14 07:54:04 +0800
committerChristian Marangi <ansuelsmth@gmail.com>2022-09-25 14:56:45 +0200
commitd391236269314a759acb7dfb7ec01ccaa0e0b32c (patch)
treedc2ba53dc7daac163e63222f3d95cd0b8f53136c /scripts
parenta67f484e67b1d0930cb4b10b9e3787ecf7e71579 (diff)
downloadupstream-d391236269314a759acb7dfb7ec01ccaa0e0b32c.tar.gz
upstream-d391236269314a759acb7dfb7ec01ccaa0e0b32c.tar.bz2
upstream-d391236269314a759acb7dfb7ec01ccaa0e0b32c.zip
download.pl: add aria2c support
Use aria2c download tool by default on package download if available in the system. aria2c permits to use multiple mirrors and may improve download speed on special context where servers are hard to reach. Co-authored-by: Christian Marangi <ansuelsmth@gmail.com> Signed-off-by: Bradford Zhang <zyc@zyc.name> [ fix wrong var in the script and improve commit description ] Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/download.pl53
1 files changed, 40 insertions, 13 deletions
diff --git a/scripts/download.pl b/scripts/download.pl
index 33e1e12c1e..4dec985fd1 100755
--- a/scripts/download.pl
+++ b/scripts/download.pl
@@ -70,27 +70,52 @@ sub hash_cmd() {
return undef;
}
-sub download_cmd($) {
+sub download_cmd {
my $url = shift;
my $have_curl = 0;
-
- if (open CURL, "curl --version 2>/dev/null |") {
+ my $have_aria2c = 0;
+ my $filename = shift;
+ my @additional_mirrors = @_;
+ my $mirrors_url = "'$url'";
+
+ my @chArray = ('a'..'z', 'A'..'Z', 0..9);
+ my $rfn = join '', map{ $chArray[int rand @chArray] } 0..9;
+ if (open CURL, '-|', 'curl', '--version') {
if (defined(my $line = readline CURL)) {
$have_curl = 1 if $line =~ /^curl /;
}
close CURL;
}
+ if (open ARIA2C, '-|', 'aria2c', '--version') {
+ if (defined(my $line = readline ARIA2C)) {
+ $have_aria2c = 1 if $line =~ /^aria2 /;
+ }
+ close ARIA2C;
+ }
- return $have_curl
- ? (qw(curl -f --connect-timeout 20 --retry 5 --location),
+ for my $mirror (@additional_mirrors ) {
+ $mirrors_url = $mirrors_url ." '$mirror /$filename'";
+ }
+
+ if ($have_aria2c) {
+ return join(" ", "touch /dev/shm/${rfn}_spp;",
+ qw(aria2c --stderr -c -x2 -s10 -j10 -k1M), $mirrors_url ,
+ $check_certificate ? () : '--check-certificate=false',
+ "--server-stat-of=/dev/shm/${rfn}_spp",
+ "--server-stat-if=/dev/shm/${rfn}_spp",
+ "-d /dev/shm -o $rfn;",
+ "cat /dev/shm/$rfn;", "rm /dev/shm/$rfn /dev/shm/${rfn}_spp");
+ } elsif ($have_curl) {
+ return (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=-),
+ $url);
+ } else {
+ return (qw(wget --tries=5 --timeout=20 --output-document=-),
$check_certificate ? () : '--no-check-certificate',
shellwords($ENV{WGET_OPTIONS} || ''),
- $url)
- ;
+ $url);
+ }
}
my $hash_cmd = hash_cmd();
@@ -100,6 +125,7 @@ sub download
{
my $mirror = shift;
my $download_filename = shift;
+ my @additional_mirrors = @_;
$mirror =~ s!/$!!;
@@ -146,9 +172,9 @@ sub download
}
};
} else {
- my @cmd = download_cmd("$mirror/$download_filename");
+ my @cmd = download_cmd("$mirror/$download_filename", $download_filename, @additional_mirrors);
print STDERR "+ ".join(" ",@cmd)."\n";
- open(FETCH_FD, '-|', @cmd) or die "Cannot launch curl or wget.\n";
+ open(FETCH_FD, '-|', @cmd) or die "Cannot launch aria2c, curl or wget.\n";
$hash_cmd and do {
open MD5SUM, "| $hash_cmd > '$target/$filename.hash'" or die "Cannot launch $hash_cmd.\n";
};
@@ -296,10 +322,11 @@ while (!-f "$target/$filename") {
my $mirror = shift @mirrors;
$mirror or die "No more mirrors to try - giving up.\n";
- download($mirror, $url_filename);
+ download($mirror, $url_filename, @mirrors);
if (!-f "$target/$filename" && $url_filename ne $filename) {
- download($mirror, $filename);
+ download($mirror, $filename, @mirrors);
}
+ @mirrors=();
}
$SIG{INT} = \&cleanup;