Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 49 additions & 5 deletions public/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,41 @@ if ! command -v curl >/dev/null 2>&1; then
exit 1
fi

# curl >= 7.71 can also retry rate-limit 403s (--retry-all-errors); older builds
# still retry connection errors, 5xx and 429 via plain --retry.
RETRY_ALL=0
if curl --help all 2>/dev/null | grep -q -- '--retry-all-errors'; then
RETRY_ALL=1
fi

# Retry transient GitHub failures with exponential backoff: CDN 504s, request
# timeouts, and (where supported) rate-limit 403s.
get() {
if [ "$RETRY_ALL" -eq 1 ]; then
curl -fsSL --retry 5 --retry-max-time 60 --retry-all-errors "$@"
else
curl -fsSL --retry 5 --retry-max-time 60 "$@"
fi
}

# A token (exported by CI as GITHUB_TOKEN / GH_TOKEN) lifts the GitHub API limit
# from 60 req/hr per IP. Shared CI runner IPs routinely exhaust the anonymous
# quota — the usual cause of an intermittent HTTP 403 on the release lookup.
TOKEN="${GITHUB_TOKEN:-${GH_TOKEN:-}}"

releases() {
if [ -n "$TOKEN" ]; then
get -H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${TOKEN}" "$1"
else
get -H "Accept: application/vnd.github+json" "$1"
fi
}

# The /releases endpoint lists ALL releases (prereleases included) sorted
# newest-first. The /releases/latest endpoint excludes prereleases, which
# is why we don't use it.
TAG="$(curl -fsSL \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/${REPO}/releases?per_page=1" \
TAG="$(releases "https://api.github.com/repos/${REPO}/releases?per_page=1" \
| sed -n 's/.*"tag_name": *"\([^"]*\)".*/\1/p' \
| head -n 1)"

Expand All @@ -33,6 +62,21 @@ if [ -z "${TAG}" ]; then
fi

UPSTREAM="https://github.com/${REPO}/releases/download/${TAG}/${ASSET}"

echo "wezel-install: resolving ${TAG} -> ${ASSET}" >&2
curl -fsSL "${UPSTREAM}" | sh

# Run the bundled installer, retrying the whole thing: its binary-tarball
# download can hit transient GitHub CDN errors (e.g. HTTP 504) with no retry
# of its own.
n=1
while :; do
if installer="$(get "${UPSTREAM}")" && printf '%s\n' "${installer}" | sh; then
exit 0
fi
if [ "${n}" -ge 3 ]; then
echo "wezel-install: installer failed after ${n} attempts" >&2
exit 1
fi
echo "wezel-install: attempt ${n} failed, retrying in $((n * 3))s..." >&2
sleep "$((n * 3))"
n=$((n + 1))
done
Loading