Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding checksum verification to install script #4

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ asdf plugin-add terragrunt https://github.com/ohmer/asdf-terragrunt

### Environment Variable Options

- `ASDF_TERRAGRUNT_OVERWRITE_ARCH`: force the plugin to use a specified processor architecture rather than the
- `ASDF_TERRAGRUNT_OVERWRITE_ARCH`: Force the plugin to use a specified processor architecture rather than the
automatically detected value. Useful, for example, for allowing users on M1 Macs to install `amd64` binaries when
there's no `arm64` binary available.

- `ASDF_TERRAGRUNT_SKIP_CHECKSUM`: Skip the checksum verification when downloading the binary. This is saves some time,
but is less secure.
25 changes: 25 additions & 0 deletions bin/install
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,32 @@ install() {
exit 1
fi

if [[ "${ASDF_TERRAGRUNT_SKIP_CHECKSUM:-"false"}" != "true" ]]; then
local expected_checksum
expected_checksum=$(_sha256 "$bin_path" | awk '{print $1}')
local checksum
checksum="$(curl -sL "https://github.com/gruntwork-io/terragrunt/releases/download/v${version}/SHA256SUMS" | grep "terragrunt_${platform}_${arch}" | awk '{print $1}')"

if [ "$expected_checksum" != "$checksum" ]; then
echo "Checksum for terragrunt did not match"
echo "Expected: $checksum"
echo "Actual: $expected_checksum"
exit 1
fi
fi

chmod +x "$bin_path"
}

_sha256() {
if command -v sha256sum >/dev/null; then
sha256sum "$1"
elif command -v shasum >/dev/null; then
shasum -a 256 "$1"
else
echo "Neither sha256sum nor shasum not found. Consider skipping checksum verification with ASDF_TERRAGRUNT_SKIP_CHECKSUM=true"
exit 1
fi
}

install "$ASDF_INSTALL_TYPE" "$ASDF_INSTALL_VERSION" "$ASDF_INSTALL_PATH"
Loading