retry_timeouts
This commit is contained in:
@@ -17,6 +17,10 @@ REPO_URL="${PYTORRENT_REPO_URL:-https://github.com/zdzichu6969/pyTorrent}"
|
||||
REPO_BRANCH="${PYTORRENT_REPO_BRANCH:-master}"
|
||||
WORK_DIR="${PYTORRENT_BOOTSTRAP_DIR:-/tmp/pytorrent-stack-installer}"
|
||||
KEEP_WORK_DIR="${PYTORRENT_KEEP_BOOTSTRAP_DIR:-0}"
|
||||
DOWNLOAD_RETRIES="${PYTORRENT_DOWNLOAD_RETRIES:-4}"
|
||||
DOWNLOAD_RETRY_DELAY="${PYTORRENT_DOWNLOAD_RETRY_DELAY:-10}"
|
||||
DOWNLOAD_CONNECT_TIMEOUT="${PYTORRENT_DOWNLOAD_CONNECT_TIMEOUT:-30}"
|
||||
DOWNLOAD_MAX_TIME="${PYTORRENT_DOWNLOAD_MAX_TIME:-600}"
|
||||
|
||||
default_archive_url() {
|
||||
case "${REPO_URL%/}" in
|
||||
@@ -105,14 +109,65 @@ prepare_downloader() {
|
||||
fail "curl or wget is required and no supported package manager was found."
|
||||
}
|
||||
|
||||
retry_countdown() {
|
||||
local seconds="$1"
|
||||
local remaining
|
||||
for ((remaining=seconds; remaining>0; remaining--)); do
|
||||
printf 'Retrying in %ss...\r' "${remaining}"
|
||||
sleep 1
|
||||
done
|
||||
[[ "${seconds}" -gt 0 ]] && printf '%*s\r' 40 ''
|
||||
}
|
||||
|
||||
archive_url_candidates() {
|
||||
local url="$1"
|
||||
printf '%s\n' "${url}"
|
||||
case "${url}" in
|
||||
https://github.com/*/archive/refs/heads/*.tar.gz)
|
||||
local rest owner repo branch
|
||||
rest="${url#https://github.com/}"
|
||||
owner="${rest%%/*}"
|
||||
rest="${rest#*/}"
|
||||
repo="${rest%%/*}"
|
||||
branch="${url##*/}"
|
||||
branch="${branch%.tar.gz}"
|
||||
printf 'https://codeload.github.com/%s/%s/tar.gz/refs/heads/%s\n' "${owner}" "${repo}" "${branch}"
|
||||
;;
|
||||
https://github.com/*/archive/*.tar.gz)
|
||||
local rest owner repo ref
|
||||
rest="${url#https://github.com/}"
|
||||
owner="${rest%%/*}"
|
||||
rest="${rest#*/}"
|
||||
repo="${rest%%/*}"
|
||||
ref="${url##*/}"
|
||||
ref="${ref%.tar.gz}"
|
||||
printf 'https://codeload.github.com/%s/%s/tar.gz/%s\n' "${owner}" "${repo}" "${ref}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
download_file() {
|
||||
local url="$1"
|
||||
local destination="$2"
|
||||
if [[ "${DOWNLOADER}" == "curl" ]]; then
|
||||
curl -fL "${url}" -o "${destination}"
|
||||
else
|
||||
wget -O "${destination}" "${url}"
|
||||
fi
|
||||
local candidate attempt status
|
||||
while IFS= read -r candidate; do
|
||||
[[ -n "${candidate}" ]] || continue
|
||||
for ((attempt=1; attempt<=DOWNLOAD_RETRIES; attempt++)); do
|
||||
if [[ "${DOWNLOADER}" == "curl" ]]; then
|
||||
curl -fL --connect-timeout "${DOWNLOAD_CONNECT_TIMEOUT}" --max-time "${DOWNLOAD_MAX_TIME}" "${candidate}" -o "${destination}" && return 0
|
||||
status=$?
|
||||
else
|
||||
wget --timeout="${DOWNLOAD_CONNECT_TIMEOUT}" --read-timeout="${DOWNLOAD_MAX_TIME}" --tries=1 -O "${destination}" "${candidate}" && return 0
|
||||
status=$?
|
||||
fi
|
||||
log "Download failed (${attempt}/${DOWNLOAD_RETRIES}) from ${candidate} (exit ${status})."
|
||||
if [[ "${attempt}" -lt "${DOWNLOAD_RETRIES}" ]]; then
|
||||
retry_countdown "${DOWNLOAD_RETRY_DELAY}"
|
||||
fi
|
||||
done
|
||||
log "Trying alternative source if available after: ${candidate}"
|
||||
done < <(archive_url_candidates "${url}")
|
||||
return 1
|
||||
}
|
||||
|
||||
detect_os_family() {
|
||||
|
||||
Reference in New Issue
Block a user