termux_download.sh: simplify curl download error handling

Use curl built-in download retry mechanizm instead implementing
such in shell loop.
This commit is contained in:
Leonid Pliushch 2020-07-24 15:14:50 +03:00
parent 5a4eedcd45
commit 8ecb74b324
1 changed files with 13 additions and 19 deletions

View File

@ -16,9 +16,7 @@ termux_download() {
local TMPFILE
TMPFILE=$(mktemp "$TERMUX_PKG_TMPDIR/download.$TERMUX_PKG_NAME.XXXXXXXXX")
echo "Downloading ${URL}"
local TRYMAX=6
for try in $(seq 1 $TRYMAX); do
if curl -L --fail --retry 2 -o "$TMPFILE" "$URL"; then
if curl --fail --retry 10 --retry-connrefused --retry-delay 30 --location --output "$TMPFILE" "$URL"; then
local ACTUAL_CHECKSUM
ACTUAL_CHECKSUM=$(sha256sum "$TMPFILE" | cut -f 1 -d ' ')
if [ "$CHECKSUM" != "SKIP_CHECKSUM" ]; then
@ -33,11 +31,7 @@ termux_download() {
fi
mv "$TMPFILE" "$DESTINATION"
return
else
echo "Download of $URL failed (attempt $try/$TRYMAX)" 1>&2
sleep 45
fi
done
termux_error_exit "Failed to download $URL"
}