Skip to content

Commit e5349eb

Browse files
authored
Merge pull request #794 from github/devm33/checksum
Add checksum validation to install script
2 parents 312222a + b808518 commit e5349eb

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

install.sh

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,61 @@ if [ -n "$VERSION" ]; then
4242
*) VERSION="v$VERSION" ;;
4343
esac
4444
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"
4546
else
4647
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"
4749
fi
4850
echo "Downloading from: $DOWNLOAD_URL"
4951

5052
# Download and extract with error handling
51-
TMP_TARBALL="$(mktemp)"
53+
TMP_DIR="$(mktemp -d)"
54+
TMP_TARBALL="$TMP_DIR/copilot-${PLATFORM}-${ARCH}.tar.gz"
5255
if command -v curl >/dev/null 2>&1; then
5356
curl -fsSL "$DOWNLOAD_URL" -o "$TMP_TARBALL"
5457
elif command -v wget >/dev/null 2>&1; then
5558
wget -qO "$TMP_TARBALL" "$DOWNLOAD_URL"
5659
else
5760
echo "Error: Neither curl nor wget found. Please install one of them."
61+
rm -rf "$TMP_DIR"
5862
exit 1
5963
fi
6064

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+
6196
# Check that the file is a valid tarball
6297
if ! tar -tzf "$TMP_TARBALL" >/dev/null 2>&1; then
6398
echo "Error: Downloaded file is not a valid tarball or is corrupted." >&2
64-
rm -f "$TMP_TARBALL"
99+
rm -rf "$TMP_DIR"
65100
exit 1
66101
fi
67102

@@ -85,7 +120,7 @@ fi
85120
tar -xz -C "$INSTALL_DIR" -f "$TMP_TARBALL"
86121
chmod +x "$INSTALL_DIR/copilot"
87122
echo "✓ GitHub Copilot CLI installed to $INSTALL_DIR/copilot"
88-
rm -f "$TMP_TARBALL"
123+
rm -rf "$TMP_DIR"
89124

90125
# Check if install directory is in PATH
91126
case ":$PATH:" in

0 commit comments

Comments
 (0)