Skip to content

Commit d3c1269

Browse files
authored
Merge pull request #1960 from github/install-auth
install: use GITHUB_TOKEN for authenticated GitHub requests
2 parents 28d2487 + 0160eb9 commit d3c1269

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

install.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,16 @@ case "$(uname -m)" in
3434
*) echo "Error: Unsupported architecture $(uname -m)" >&2 ; exit 1 ;;
3535
esac
3636

37+
# Set up authentication for GitHub requests if GITHUB_TOKEN is available
38+
CURL_AUTH=()
39+
WGET_AUTH=()
40+
GIT_REMOTE="https://github.com/github/copilot-cli"
41+
if [ -n "$GITHUB_TOKEN" ]; then
42+
CURL_AUTH=(-H "Authorization: token $GITHUB_TOKEN")
43+
WGET_AUTH=(--header="Authorization: token $GITHUB_TOKEN")
44+
GIT_REMOTE="https://x-access-token:${GITHUB_TOKEN}@github.com/github/copilot-cli"
45+
fi
46+
3747
# Determine download URL based on VERSION
3848
if [ "${VERSION}" = "latest" ] || [ -z "$VERSION" ]; then
3949
DOWNLOAD_URL="https://github.com/github/copilot-cli/releases/latest/download/copilot-${PLATFORM}-${ARCH}.tar.gz"
@@ -44,7 +54,7 @@ elif [ "${VERSION}" = "prerelease" ]; then
4454
echo "Error: git is required to install prerelease versions" >&2
4555
exit 1
4656
fi
47-
VERSION="$(git ls-remote --tags https://github.com/github/copilot-cli | tail -1 | awk -F/ '{print $NF}')"
57+
VERSION="$(git ls-remote --tags "$GIT_REMOTE" | tail -1 | awk -F/ '{print $NF}')"
4858
if [ -z "$VERSION" ]; then
4959
echo "Error: Could not determine prerelease version" >&2
5060
exit 1
@@ -67,9 +77,9 @@ echo "Downloading from: $DOWNLOAD_URL"
6777
TMP_DIR="$(mktemp -d)"
6878
TMP_TARBALL="$TMP_DIR/copilot-${PLATFORM}-${ARCH}.tar.gz"
6979
if command -v curl >/dev/null 2>&1; then
70-
curl -fsSL "$DOWNLOAD_URL" -o "$TMP_TARBALL"
80+
curl -fsSL "${CURL_AUTH[@]}" "$DOWNLOAD_URL" -o "$TMP_TARBALL"
7181
elif command -v wget >/dev/null 2>&1; then
72-
wget -qO "$TMP_TARBALL" "$DOWNLOAD_URL"
82+
wget -qO "$TMP_TARBALL" "${WGET_AUTH[@]}" "$DOWNLOAD_URL"
7383
else
7484
echo "Error: Neither curl nor wget found. Please install one of them."
7585
rm -rf "$TMP_DIR"
@@ -80,9 +90,9 @@ fi
8090
TMP_CHECKSUMS="$TMP_DIR/SHA256SUMS.txt"
8191
CHECKSUMS_AVAILABLE=false
8292
if command -v curl >/dev/null 2>&1; then
83-
curl -fsSL "$CHECKSUMS_URL" -o "$TMP_CHECKSUMS" 2>/dev/null && CHECKSUMS_AVAILABLE=true
93+
curl -fsSL "${CURL_AUTH[@]}" "$CHECKSUMS_URL" -o "$TMP_CHECKSUMS" 2>/dev/null && CHECKSUMS_AVAILABLE=true
8494
elif command -v wget >/dev/null 2>&1; then
85-
wget -qO "$TMP_CHECKSUMS" "$CHECKSUMS_URL" 2>/dev/null && CHECKSUMS_AVAILABLE=true
95+
wget -qO "$TMP_CHECKSUMS" "${WGET_AUTH[@]}" "$CHECKSUMS_URL" 2>/dev/null && CHECKSUMS_AVAILABLE=true
8696
fi
8797

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

0 commit comments

Comments
 (0)