Skip to content

Commit b3c9933

Browse files
committed
feat: verify checksums in Unix install script (#42)
1 parent 852b6aa commit b3c9933

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

install.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ if [ "$OS_NAME" = "Linux" ]; then
2525
fi
2626
elif [ "$OS_NAME" = "Darwin" ]; then
2727
OS="macOS"
28-
28+
2929
if [ "$ARCH_NAME" = "x86_64" ]; then
3030
BUILD_TARGET="darwin-amd64"
3131
elif [ "$ARCH_NAME" = "arm" ] || [ "$ARCH_NAME" = "arm64" ]; then
@@ -45,6 +45,20 @@ fi
4545

4646
# Download file directly to install directory
4747
sudo curl -sSL "https://github.com/ankddev/envfetch/releases/latest/download/envfetch-$BUILD_TARGET" --output "$INSTALL_DIR/envfetch"
48+
49+
# Check integrity
50+
51+
EXPECTED_CHECKSUM=$(curl -sSL "https://github.com/ankddev/envfetch/releases/latest/download/envfetch-$BUILD_TARGET.sha256" | tr -d '[:space:]' | tr -d '\n')
52+
ACTUAL_CHECKSUM=$(sha256sum "$INSTALL_DIR/envfetch" | awk '{print $1}')
53+
54+
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then
55+
echo "Checksum mismatch" >&2
56+
echo "Expected: $EXPECTED_CHECKSUM"
57+
echo "Actual: $ACTUAL_CHECKSUM"
58+
echo "Please try again later or report this issue to the developer."
59+
exit 1
60+
fi
61+
4862
# Give permissions for executable
4963
sudo chmod +x "$INSTALL_DIR/envfetch"
5064

0 commit comments

Comments
 (0)