From 4ed7cd5aea803bf042acb69acc25c33fb0e81504 Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Thu, 16 Dec 2021 11:26:33 -0300 Subject: [PATCH] Check shasum/sha256sum in PATH on install script (#1108) * Check shasum/sha256sum in PATH on install script * Fix typo in .github/pull_request_template.md --- .github/pull_request_template.md | 2 +- install | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index cc3ba754..26bec21c 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -2,7 +2,7 @@ Please answer the following questions and leave the below in as part of your PR. - [ ] I have read the [developer documentation](https://github.com/babashka/babashka/blob/master/doc/dev.md). -- [ ] This PR correponds to an [issue with a clear problem statement](https://github.com/babashka/babashka/blob/master/doc/dev.md#start-with-an-issue-before-writing-code). +- [ ] This PR corresponds to an [issue with a clear problem statement](https://github.com/babashka/babashka/blob/master/doc/dev.md#start-with-an-issue-before-writing-code). - [ ] This PR contains a [test](https://github.com/babashka/babashka/blob/master/doc/dev.md#tests) to prevent against future regressions diff --git a/install b/install index d44505d9..318b8f60 100755 --- a/install +++ b/install @@ -111,6 +111,18 @@ esac download_url="https://github.com/babashka/babashka/releases/download/v$version/$filename" +# macOS only have shasum available by default +# Some Linux distros (RHEL-like) only have sha256sum avaiable by default (others have both) +if command -v sha256sum >/dev/null; then + sha256sum_cmd="sha256sum" +elif command -v shasum >/dev/null; then + sha256sum_cmd="shasum -a 256" +else + >&2 echo "Either 'sha256sum' or 'shasum' needs to be on PATH for '--checksum' flag!" + >&2 echo "Exiting..." + exit 1 +fi + # Running this part in a subshell so when it finishes we go back to the previous directory mkdir -p "$download_dir" && ( cd "$download_dir" @@ -118,7 +130,7 @@ mkdir -p "$download_dir" && ( curl -o "$filename" -sL "$download_url" if [[ -n "$checksum" ]]; then - if ! echo "$checksum *$filename" | shasum -a 256 --check --status; then + if ! echo "$checksum *$filename" | $sha256sum_cmd --check --status; then >&2 echo "Failed checksum on $filename" >&2 echo "Got: $(shasum -a 256 "$filename" | cut -d' ' -f1)" >&2 echo "Expected: $checksum"