forked from github/copilot-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·137 lines (124 loc) · 4.45 KB
/
install.sh
File metadata and controls
executable file
·137 lines (124 loc) · 4.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/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."