fix: web_get() now tests for redirections using curl

Mostly this fixes downloads from sourceforge, but should make curl downloads more reliable in general
This commit is contained in:
Martin Wimpress 2024-04-19 16:32:14 +01:00 committed by Martin Wimpress
parent 8f20ae1e5d
commit 81f0506bf7
1 changed files with 7 additions and 0 deletions

View File

@ -1490,6 +1490,13 @@ function web_get() {
fi fi
if command -v curl &>/dev/null; then if command -v curl &>/dev/null; then
# Check for URL redirections
# Output to nonexistent directory so the download fails fast
local REDIRECT_URL=$(curl --silent --location --fail "${URL}" --write-out %{url_effective} --output /var/cache/${RANDOM}/${RANDOM})
if [ "${REDIRECT_URL}" != "${URL}" ]; then
echo "Redirected to ${REDIRECT_URL}"
URL="${REDIRECT_URL}"
fi
if ! curl --progress-bar --location --output "${DIR}/${FILE}" --continue-at - --user-agent "${USER_AGENT}" "${HEADERS[@]}" -- "${URL}"; then if ! curl --progress-bar --location --output "${DIR}/${FILE}" --continue-at - --user-agent "${USER_AGENT}" "${HEADERS[@]}" -- "${URL}"; then
echo "ERROR! Failed to download ${URL} with curl." echo "ERROR! Failed to download ${URL} with curl."
echo " Try deleting '${DIR}/${FILE}' running 'quickget' again." echo " Try deleting '${DIR}/${FILE}' running 'quickget' again."