Skip to content

Commit

Permalink
scripts/download.pl: fix support for aria2c download tool on macos
Browse files Browse the repository at this point in the history
Currently we use /dev/shm to place aria2c tmp file. This is not present
on macos. Use the openwrt tmp directory instead of the linux-only
/dev/shm to save compatibility with more os.

Fixes: d391236 ("download.pl: add aria2c support")
Signed-off-by: Christian Marangi <[email protected]>
  • Loading branch information
Ansuel authored and aiamadeus committed Sep 27, 2022
1 parent 5ae6c9b commit 03a0395
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions scripts/download.pl
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ sub download_cmd {
my $additional_mirrors = join(" ", map "$_/$filename", @_);

my @chArray = ('a'..'z', 'A'..'Z', 0..9);
my $rfn = join '', map{ $chArray[int rand @chArray] } 0..9;
my $rfn = join '', "${filename}_", map{ $chArray[int rand @chArray] } 0..9;
if (open CURL, '-|', 'curl', '--version') {
if (defined(my $line = readline CURL)) {
$have_curl = 1 if $line =~ /^curl /;
Expand All @@ -96,13 +96,15 @@ sub download_cmd {

if ($have_aria2c) {
@mirrors=();
return join(" ", "touch /dev/shm/${rfn}_spp;",
return join(" ", "[ -d $ENV{'TMPDIR'}/aria2c ] || mkdir $ENV{'TMPDIR'}/aria2c;",
"touch $ENV{'TMPDIR'}/aria2c/${rfn}_spp;",
qw(aria2c --stderr -c -x2 -s10 -j10 -k1M), $url, $additional_mirrors,
$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");
"--server-stat-of=$ENV{'TMPDIR'}/aria2c/${rfn}_spp",
"--server-stat-if=$ENV{'TMPDIR'}/aria2c/${rfn}_spp",
"-d $ENV{'TMPDIR'}/aria2c -o $rfn;",
"cat $ENV{'TMPDIR'}/aria2c/$rfn;",
"rm $ENV{'TMPDIR'}/aria2c/$rfn $ENV{'TMPDIR'}/aria2c/${rfn}_spp");
} elsif ($have_curl) {
return (qw(curl -f --connect-timeout 20 --retry 5 --location),
$check_certificate ? () : '--insecure',
Expand Down

0 comments on commit 03a0395

Please sign in to comment.