Skip to content

Commit d68b4ce

Browse files
authored
Create install.sh
#!/usr/bin/env bash set -e # GitHub Copilot CLI Installation Script # Usage: curl -fsSL https://gh.io/copilot-install | bash # or: wget -qO- https://gh.io/copilot-install | bash # Use | sudo bash to run as root and install to /usr/local/bin # Export PREFIX to install to $PREFIX/bin/ directory (default: /usr/local for # root, $HOME/.local for non-root), e.g., export PREFIX=$HOME/custom to install # to $HOME/custom/bin echo "Installing GitHub Copilot CLI..." # Detect platform case "$(uname -s || echo "")" in Darwin*) PLATFORM="darwin" ;; Linux*) PLATFORM="linux" ;; *) if command -v winget >/dev/null 2>&1; then echo "Windows detected. Installing via winget..." winget install GitHub.Copilot exit $? else echo "Error: Windows detected but winget not found. Please see https://gh.io/install-copilot-readme" >&2 exit 1 fi ;; esac # Detect architecture case "$(uname -m)" in x86_64|amd64) ARCH="x64" ;; aarch64|arm64) ARCH="arm64" ;; *) echo "Error: Unsupported architecture $(uname -m)" >&2 ; exit 1 ;; esac # Determine download URL based on VERSION if [ -n "$VERSION" ]; then # Prefix version with 'v' if not already present case "$VERSION" in v*) ;; *) VERSION="v$VERSION" ;; esac DOWNLOAD_URL="https://github.com/github/copilot-cli/releases/download/${VERSION}/copilot-${PLATFORM}-${ARCH}.tar.gz" CHECKSUMS_URL="https://github.com/github/copilot-cli/releases/download/${VERSION}/SHA256SUMS.txt" else DOWNLOAD_URL="https://github.com/github/copilot-cli/releases/latest/download/copilot-${PLATFORM}-${ARCH}.tar.gz" CHECKSUMS_URL="https://github.com/github/copilot-cli/releases/latest/download/SHA256SUMS.txt" fi echo "Downloading from: $DOWNLOAD_URL" # Download and extract with error handling TMP_DIR="$(mktemp -d)" TMP_TARBALL="$TMP_DIR/copilot-${PLATFORM}-${ARCH}.tar.gz" if command -v curl >/dev/null 2>&1; then curl -fsSL "$DOWNLOAD_URL" -o "$TMP_TARBALL" elif command -v wget >/dev/null 2>&1; then wget -qO "$TMP_TARBALL" "$DOWNLOAD_URL" else echo "Error: Neither curl nor wget found. Please install one of them." rm -rf "$TMP_DIR" exit 1 fi # Attempt to download checksums file and validate TMP_CHECKSUMS="$TMP_DIR/SHA256SUMS.txt" CHECKSUMS_AVAILABLE=false if command -v curl >/dev/null 2>&1; then curl -fsSL "$CHECKSUMS_URL" -o "$TMP_CHECKSUMS" 2>/dev/null && CHECKSUMS_AVAILABLE=true elif command -v wget >/dev/null 2>&1; then wget -qO "$TMP_CHECKSUMS" "$CHECKSUMS_URL" 2>/dev/null && CHECKSUMS_AVAILABLE=true fi if [ "$CHECKSUMS_AVAILABLE" = true ]; then if command -v sha256sum >/dev/null 2>&1; then if (cd "$TMP_DIR" && sha256sum -c --ignore-missing SHA256SUMS.txt >/dev/null 2>&1); then echo "✓ Checksum validated" else echo "Error: Checksum validation failed." >&2 rm -rf "$TMP_DIR" exit 1 fi elif command -v shasum >/dev/null 2>&1; then if (cd "$TMP_DIR" && shasum -a 256 -c --ignore-missing SHA256SUMS.txt >/dev/null 2>&1); then echo "✓ Checksum validated" else echo "Error: Checksum validation failed." >&2 rm -rf "$TMP_DIR" exit 1 fi else echo "Warning: No sha256sum or shasum found, skipping checksum validation." fi fi # Check that the file is a valid tarball if ! tar -tzf "$TMP_TARBALL" >/dev/null 2>&1; then echo "Error: Downloaded file is not a valid tarball or is corrupted." >&2 rm -rf "$TMP_DIR" exit 1 fi # Check if running as root, fallback to non-root if [ "$(id -u 2>/dev/null || echo 1)" -eq 0 ]; then PREFIX="${PREFIX:-/usr/local}" else PREFIX="${PREFIX:-$HOME/.local}" fi INSTALL_DIR="$PREFIX/bin" if ! mkdir -p "$INSTALL_DIR"; then echo "Error: Could not create directory $INSTALL_DIR. You may not have write permissions." >&2 echo "Try running this script with sudo or set PREFIX to a directory you own (e.g., export PREFIX=\$HOME/.local)." >&2 exit 1 fi # Install binary if [ -f "$INSTALL_DIR/copilot" ]; then echo "Notice: Replacing copilot binary found at $INSTALL_DIR/copilot." fi tar -xz -C "$INSTALL_DIR" -f "$TMP_TARBALL" chmod +x "$INSTALL_DIR/copilot" echo "✓ GitHub Copilot CLI installed to $INSTALL_DIR/copilot" rm -rf "$TMP_DIR" # Check if install directory is in PATH case ":$PATH:" in *":$INSTALL_DIR:"*) ;; *) echo "" echo "Warning: $INSTALL_DIR is not in your PATH" echo "Add it to your PATH by adding this line to your shell profile:" echo " export PATH=\"\$PATH:$INSTALL_DIR\"" ;; esac echo "" echo "Installation complete! Run 'copilot help' to get started."
1 parent de678a8 commit d68b4ce

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

install.sh

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
4+
# GitHub Copilot CLI Installation Script
5+
# Usage: curl -fsSL https://gh.io/copilot-install | bash
6+
# or: wget -qO- https://gh.io/copilot-install | bash
7+
# Use | sudo bash to run as root and install to /usr/local/bin
8+
# Export PREFIX to install to $PREFIX/bin/ directory (default: /usr/local for
9+
# root, $HOME/.local for non-root), e.g., export PREFIX=$HOME/custom to install
10+
# to $HOME/custom/bin
11+
12+
echo "Installing GitHub Copilot CLI..."
13+
14+
# Detect platform
15+
case "$(uname -s || echo "")" in
16+
Darwin*) PLATFORM="darwin" ;;
17+
Linux*) PLATFORM="linux" ;;
18+
*)
19+
if command -v winget >/dev/null 2>&1; then
20+
echo "Windows detected. Installing via winget..."
21+
winget install GitHub.Copilot
22+
exit $?
23+
else
24+
echo "Error: Windows detected but winget not found. Please see https://gh.io/install-copilot-readme" >&2
25+
exit 1
26+
fi
27+
;;
28+
esac
29+
30+
# Detect architecture
31+
case "$(uname -m)" in
32+
x86_64|amd64) ARCH="x64" ;;
33+
aarch64|arm64) ARCH="arm64" ;;
34+
*) echo "Error: Unsupported architecture $(uname -m)" >&2 ; exit 1 ;;
35+
esac
36+
37+
# Determine download URL based on VERSION
38+
if [ -n "$VERSION" ]; then
39+
# Prefix version with 'v' if not already present
40+
case "$VERSION" in
41+
v*) ;;
42+
*) VERSION="v$VERSION" ;;
43+
esac
44+
DOWNLOAD_URL="https://github.com/github/copilot-cli/releases/download/${VERSION}/copilot-${PLATFORM}-${ARCH}.tar.gz"
45+
CHECKSUMS_URL="https://github.com/github/copilot-cli/releases/download/${VERSION}/SHA256SUMS.txt"
46+
else
47+
DOWNLOAD_URL="https://github.com/github/copilot-cli/releases/latest/download/copilot-${PLATFORM}-${ARCH}.tar.gz"
48+
CHECKSUMS_URL="https://github.com/github/copilot-cli/releases/latest/download/SHA256SUMS.txt"
49+
fi
50+
echo "Downloading from: $DOWNLOAD_URL"
51+
52+
# Download and extract with error handling
53+
TMP_DIR="$(mktemp -d)"
54+
TMP_TARBALL="$TMP_DIR/copilot-${PLATFORM}-${ARCH}.tar.gz"
55+
if command -v curl >/dev/null 2>&1; then
56+
curl -fsSL "$DOWNLOAD_URL" -o "$TMP_TARBALL"
57+
elif command -v wget >/dev/null 2>&1; then
58+
wget -qO "$TMP_TARBALL" "$DOWNLOAD_URL"
59+
else
60+
echo "Error: Neither curl nor wget found. Please install one of them."
61+
rm -rf "$TMP_DIR"
62+
exit 1
63+
fi
64+
65+
# Attempt to download checksums file and validate
66+
TMP_CHECKSUMS="$TMP_DIR/SHA256SUMS.txt"
67+
CHECKSUMS_AVAILABLE=false
68+
if command -v curl >/dev/null 2>&1; then
69+
curl -fsSL "$CHECKSUMS_URL" -o "$TMP_CHECKSUMS" 2>/dev/null && CHECKSUMS_AVAILABLE=true
70+
elif command -v wget >/dev/null 2>&1; then
71+
wget -qO "$TMP_CHECKSUMS" "$CHECKSUMS_URL" 2>/dev/null && CHECKSUMS_AVAILABLE=true
72+
fi
73+
74+
if [ "$CHECKSUMS_AVAILABLE" = true ]; then
75+
if command -v sha256sum >/dev/null 2>&1; then
76+
if (cd "$TMP_DIR" && sha256sum -c --ignore-missing SHA256SUMS.txt >/dev/null 2>&1); then
77+
echo "✓ Checksum validated"
78+
else
79+
echo "Error: Checksum validation failed." >&2
80+
rm -rf "$TMP_DIR"
81+
exit 1
82+
fi
83+
elif command -v shasum >/dev/null 2>&1; then
84+
if (cd "$TMP_DIR" && shasum -a 256 -c --ignore-missing SHA256SUMS.txt >/dev/null 2>&1); then
85+
echo "✓ Checksum validated"
86+
else
87+
echo "Error: Checksum validation failed." >&2
88+
rm -rf "$TMP_DIR"
89+
exit 1
90+
fi
91+
else
92+
echo "Warning: No sha256sum or shasum found, skipping checksum validation."
93+
fi
94+
fi
95+
96+
# Check that the file is a valid tarball
97+
if ! tar -tzf "$TMP_TARBALL" >/dev/null 2>&1; then
98+
echo "Error: Downloaded file is not a valid tarball or is corrupted." >&2
99+
rm -rf "$TMP_DIR"
100+
exit 1
101+
fi
102+
103+
# Check if running as root, fallback to non-root
104+
if [ "$(id -u 2>/dev/null || echo 1)" -eq 0 ]; then
105+
PREFIX="${PREFIX:-/usr/local}"
106+
else
107+
PREFIX="${PREFIX:-$HOME/.local}"
108+
fi
109+
INSTALL_DIR="$PREFIX/bin"
110+
if ! mkdir -p "$INSTALL_DIR"; then
111+
echo "Error: Could not create directory $INSTALL_DIR. You may not have write permissions." >&2
112+
echo "Try running this script with sudo or set PREFIX to a directory you own (e.g., export PREFIX=\$HOME/.local)." >&2
113+
exit 1
114+
fi
115+
116+
# Install binary
117+
if [ -f "$INSTALL_DIR/copilot" ]; then
118+
echo "Notice: Replacing copilot binary found at $INSTALL_DIR/copilot."
119+
fi
120+
tar -xz -C "$INSTALL_DIR" -f "$TMP_TARBALL"
121+
chmod +x "$INSTALL_DIR/copilot"
122+
echo "✓ GitHub Copilot CLI installed to $INSTALL_DIR/copilot"
123+
rm -rf "$TMP_DIR"
124+
125+
# Check if install directory is in PATH
126+
case ":$PATH:" in
127+
*":$INSTALL_DIR:"*) ;;
128+
*)
129+
echo ""
130+
echo "Warning: $INSTALL_DIR is not in your PATH"
131+
echo "Add it to your PATH by adding this line to your shell profile:"
132+
echo " export PATH=\"\$PATH:$INSTALL_DIR\""
133+
;;
134+
esac
135+
136+
echo ""
137+
echo "Installation complete! Run 'copilot help' to get started."

0 commit comments

Comments
 (0)