Skip to content

Commit 7b140a7

Browse files
devm33Copilot
andcommitted
install: retry without token when authenticated requests fail
Tokens from GitHub org members that haven't been SSO-authorized for the org will be rejected by SAML enforcement, causing downloads to fail. Add a download() helper that tries with the token first, then falls back to an unauthenticated request on failure. Apply the same retry logic to the git ls-remote call for prerelease detection. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent d3c1269 commit 7b140a7

File tree

1 file changed

+33
-11
lines changed

1 file changed

+33
-11
lines changed

install.sh

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,31 @@ if [ -n "$GITHUB_TOKEN" ]; then
4444
GIT_REMOTE="https://x-access-token:${GITHUB_TOKEN}@github.com/github/copilot-cli"
4545
fi
4646

47+
# Download a file, retrying without auth on failure (e.g. SAML enforcement)
48+
download() {
49+
local url="$1" output="$2"
50+
if command -v curl >/dev/null 2>&1; then
51+
if [ ${#CURL_AUTH[@]} -gt 0 ]; then
52+
if curl -fsSL "${CURL_AUTH[@]}" "$url" -o "$output" 2>/dev/null; then
53+
return 0
54+
fi
55+
echo "Warning: Authenticated request failed, retrying without token..." >&2
56+
fi
57+
curl -fsSL "$url" -o "$output"
58+
elif command -v wget >/dev/null 2>&1; then
59+
if [ ${#WGET_AUTH[@]} -gt 0 ]; then
60+
if wget -qO "$output" "${WGET_AUTH[@]}" "$url" 2>/dev/null; then
61+
return 0
62+
fi
63+
echo "Warning: Authenticated request failed, retrying without token..." >&2
64+
fi
65+
wget -qO "$output" "$url"
66+
else
67+
echo "Error: Neither curl nor wget found. Please install one of them." >&2
68+
return 1
69+
fi
70+
}
71+
4772
# Determine download URL based on VERSION
4873
if [ "${VERSION}" = "latest" ] || [ -z "$VERSION" ]; then
4974
DOWNLOAD_URL="https://github.com/github/copilot-cli/releases/latest/download/copilot-${PLATFORM}-${ARCH}.tar.gz"
@@ -54,7 +79,11 @@ elif [ "${VERSION}" = "prerelease" ]; then
5479
echo "Error: git is required to install prerelease versions" >&2
5580
exit 1
5681
fi
57-
VERSION="$(git ls-remote --tags "$GIT_REMOTE" | tail -1 | awk -F/ '{print $NF}')"
82+
VERSION="$(git ls-remote --tags "$GIT_REMOTE" 2>/dev/null | tail -1 | awk -F/ '{print $NF}')"
83+
if [ -z "$VERSION" ] && [ "$GIT_REMOTE" != "https://github.com/github/copilot-cli" ]; then
84+
echo "Warning: Authenticated git request failed, retrying without token..."
85+
VERSION="$(git ls-remote --tags https://github.com/github/copilot-cli | tail -1 | awk -F/ '{print $NF}')"
86+
fi
5887
if [ -z "$VERSION" ]; then
5988
echo "Error: Could not determine prerelease version" >&2
6089
exit 1
@@ -76,23 +105,16 @@ echo "Downloading from: $DOWNLOAD_URL"
76105
# Download and extract with error handling
77106
TMP_DIR="$(mktemp -d)"
78107
TMP_TARBALL="$TMP_DIR/copilot-${PLATFORM}-${ARCH}.tar.gz"
79-
if command -v curl >/dev/null 2>&1; then
80-
curl -fsSL "${CURL_AUTH[@]}" "$DOWNLOAD_URL" -o "$TMP_TARBALL"
81-
elif command -v wget >/dev/null 2>&1; then
82-
wget -qO "$TMP_TARBALL" "${WGET_AUTH[@]}" "$DOWNLOAD_URL"
83-
else
84-
echo "Error: Neither curl nor wget found. Please install one of them."
108+
if ! download "$DOWNLOAD_URL" "$TMP_TARBALL"; then
85109
rm -rf "$TMP_DIR"
86110
exit 1
87111
fi
88112

89113
# Attempt to download checksums file and validate
90114
TMP_CHECKSUMS="$TMP_DIR/SHA256SUMS.txt"
91115
CHECKSUMS_AVAILABLE=false
92-
if command -v curl >/dev/null 2>&1; then
93-
curl -fsSL "${CURL_AUTH[@]}" "$CHECKSUMS_URL" -o "$TMP_CHECKSUMS" 2>/dev/null && CHECKSUMS_AVAILABLE=true
94-
elif command -v wget >/dev/null 2>&1; then
95-
wget -qO "$TMP_CHECKSUMS" "${WGET_AUTH[@]}" "$CHECKSUMS_URL" 2>/dev/null && CHECKSUMS_AVAILABLE=true
116+
if download "$CHECKSUMS_URL" "$TMP_CHECKSUMS" 2>/dev/null; then
117+
CHECKSUMS_AVAILABLE=true
96118
fi
97119

98120
if [ "$CHECKSUMS_AVAILABLE" = true ]; then

0 commit comments

Comments
 (0)