Skip to content

Commit

Permalink
Check shasum/sha256sum in PATH on install script (babashka#1108)
Browse files Browse the repository at this point in the history
* Check shasum/sha256sum in PATH on install script

* Fix typo in .github/pull_request_template.md
  • Loading branch information
thiagokokada authored Dec 16, 2021
1 parent 1c217a7 commit 4ed7cd5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 13 additions & 1 deletion install
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,26 @@ 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"
echo -e "Downloading $download_url to $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"
Expand Down

0 comments on commit 4ed7cd5

Please sign in to comment.