Skip to content

Instantly share code, notes, and snippets.

@MCOfficer
Created July 6, 2020 10:58
Show Gist options
  • Save MCOfficer/e56cd7a916b2d9e78003205d1a81ba76 to your computer and use it in GitHub Desktop.
Save MCOfficer/e56cd7a916b2d9e78003205d1a81ba76 to your computer and use it in GitHub Desktop.
A bash script that tries to download a file with multiple programs, for use in makepkg.conf.
#!/bin/bash
# arg 0: URL
# arg 1: Output
url="$1"
output="$2"
url_key="%u"
output_key="%o"
order=(
aria2
curl
axel
wget
hget
snarf
ruget
)
declare -A downloaders=(
['aria2']='/usr/bin/aria2c --allow-overwrite=true --continue=true --file-allocation=none --log-level=error --summary-interval=60 --timeout=5 -Uwget --out %o %u'
['axel']='/usr/bin/axel -n 2 -q -o %o %u'
['curl']='/usr/bin/curl -fLC - --retry 3 --retry-delay 3 -o %o %u'
['hget']='/usr/bin/hget %u -skip-tls false %o'
['ruget']='/usr/bin/ruget -o %o %u'
['snarf']='/usr/bin/snarf -N %u %o'
['wget']='/usr/bin/wget -q -t 3 --waitretry=3 -O %o %u'
)
for d in "${order[@]}"
do
echo "Downloading with $d"
cmd=${downloaders[$d]}
cmd=${cmd//"$url_key"/"$url"}
cmd=${cmd//"$output_key"/"$output"}
echo $cmd
$cmd 2>&1 | sed "s/^/ /"
if [ "${PIPESTATUS[0]}" -eq 0 ] ; then
echo ""
echo "Done"
exit 0
fi
echo ""
done
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment