@@ -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"
4546else
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"
4749fi
4850echo " 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"
5255if command -v curl > /dev/null 2>&1 ; then
5356 curl -fsSL " $DOWNLOAD_URL " -o " $TMP_TARBALL "
5457elif command -v wget > /dev/null 2>&1 ; then
5558 wget -qO " $TMP_TARBALL " " $DOWNLOAD_URL "
5659else
5760 echo " Error: Neither curl nor wget found. Please install one of them."
61+ rm -rf " $TMP_DIR "
5862 exit 1
5963fi
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
6297if ! 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
66101fi
67102
85120tar -xz -C " $INSTALL_DIR " -f " $TMP_TARBALL "
86121chmod +x " $INSTALL_DIR /copilot"
87122echo " ✓ 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
91126case " :$PATH :" in
0 commit comments