@@ -42,8 +42,10 @@ 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
5860 exit 1
5961fi
6062
63+ # Attempt to download checksums file and validate
64+ TMP_CHECKSUMS=" $( mktemp) "
65+ CHECKSUMS_AVAILABLE=false
66+ if command -v curl > /dev/null 2>&1 ; then
67+ curl -fsSL " $CHECKSUMS_URL " -o " $TMP_CHECKSUMS " 2> /dev/null && CHECKSUMS_AVAILABLE=true
68+ elif command -v wget > /dev/null 2>&1 ; then
69+ wget -qO " $TMP_CHECKSUMS " " $CHECKSUMS_URL " 2> /dev/null && CHECKSUMS_AVAILABLE=true
70+ fi
71+
72+ if [ " $CHECKSUMS_AVAILABLE " = true ]; then
73+ TARBALL_NAME=" copilot-${PLATFORM} -${ARCH} .tar.gz"
74+ EXPECTED_CHECKSUM=$( grep " $TARBALL_NAME " " $TMP_CHECKSUMS " | awk ' {print $1}' )
75+ if [ -n " $EXPECTED_CHECKSUM " ]; then
76+ if command -v sha256sum > /dev/null 2>&1 ; then
77+ ACTUAL_CHECKSUM=$( sha256sum " $TMP_TARBALL " | awk ' {print $1}' )
78+ elif command -v shasum > /dev/null 2>&1 ; then
79+ ACTUAL_CHECKSUM=$( shasum -a 256 " $TMP_TARBALL " | awk ' {print $1}' )
80+ else
81+ echo " Warning: No sha256sum or shasum found, skipping checksum validation."
82+ ACTUAL_CHECKSUM=" "
83+ fi
84+ if [ -n " $ACTUAL_CHECKSUM " ]; then
85+ if [ " $EXPECTED_CHECKSUM " != " $ACTUAL_CHECKSUM " ]; then
86+ echo " Error: Checksum validation failed." >&2
87+ echo " Expected: $EXPECTED_CHECKSUM " >&2
88+ echo " Actual: $ACTUAL_CHECKSUM " >&2
89+ rm -f " $TMP_TARBALL " " $TMP_CHECKSUMS "
90+ exit 1
91+ fi
92+ echo " ✓ Checksum validated"
93+ fi
94+ fi
95+ fi
96+ rm -f " $TMP_CHECKSUMS "
97+
6198# Check that the file is a valid tarball
6299if ! tar -tzf " $TMP_TARBALL " > /dev/null 2>&1 ; then
63100 echo " Error: Downloaded file is not a valid tarball or is corrupted." >&2
0 commit comments