Skip to content

Commit

Permalink
Fix missing sha256sum command and print info for fish shell (#92)
Browse files Browse the repository at this point in the history
When I tried to install ponyup on my macOS machine, it was failing with this error:

```bash
sh: line 116: sha256sum: command not found
```

But  macOS Catalina comes with `shasum` utility, so I made a change to check if `sha256sum` is not available, then use `shasum`, otherwise just exit printing error.

Also, I use [fish shell](https://fish.sh) which has a slightly different syntax, so I added a custom message for fish.
  • Loading branch information
khaledez authored Feb 5, 2020
1 parent 946ef4e commit 5e91962
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ All notable changes to this project will be documented in this file. This projec
### Fixed

- Include initial ponyup package in lockfile ([PR #89](https://github.com/ponylang/ponyup/pull/89))
- Use `shasum` if `sha256sum` command is missing, or exit with error message ([PR #92](https://github.com/ponylang/ponyup/pull/92))

### Added

- Colorize important ponyup-init.sh output ([PR #81](https://github.com/ponylang/ponyup/pull/81))
- Support showing `$PATH` message for [fish shell](https://fish.sh) ([PR #92](https://github.com/ponylang/ponyup/pull/92))

### Changed

Expand Down
29 changes: 24 additions & 5 deletions ponyup-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,15 @@ Linux*)
;;
esac

if command -v sha256sum > /dev/null 2>&1; then
sha256sum='sha256sum'
elif command -v shasum > /dev/null 2>&1; then
sha256sum='shasum --algorithm 256'
else
printf "%bNo checksum command found.%b\n" "${RED}" "${DEFAULT}"
exit 1
fi

ponyup_root="${prefix}/ponyup"
echo "ponyup_root = ${ponyup_root}"

Expand Down Expand Up @@ -130,7 +139,7 @@ echo "downloading ${filename}"

curl "${dl_url}" -o "${tmp_dir}/${filename}"

dl_checksum="$(sha256sum "${tmp_dir}/${filename}" | awk '{ print $1 }')"
dl_checksum="$(${sha256sum} "${tmp_dir}/${filename}" | awk '{ print $1 }')"

if [ "${dl_checksum}" != "${checksum}" ]; then
printf "%bchecksum mismatch:\n" "${RED}"
Expand All @@ -149,8 +158,18 @@ printf "%bponyup placed in %b${ponyup_root}/bin%b\n" \
"${BLUE}" "${YELLOW}" "${DEFAULT}"

if ! echo "$PATH" | grep -q "${ponyup_root}/bin"; then
printf "%bYou should add %b${ponyup_root}/bin%b to \$PATH:%b\n" \
"${BLUE}" "${YELLOW}" "${BLUE}" "${DEFAULT}"
printf "%bexport PATH=${ponyup_root}/bin:\$PATH%b\n" \
"${YELLOW}" "${DEFAULT}"
case "${SHELL}" in
*fish)
printf "%bYou should add %b${ponyup_root}/bin%b to \$PATH:%b\n" \
"${BLUE}" "${YELLOW}" "${BLUE}" "${DEFAULT}"
printf "%bset -g fish_user_paths ${ponyup_root}/bin \$fish_user_paths%b\n" \
"${YELLOW}" "${DEFAULT}"
;;
*)
printf "%bYou should add %b${ponyup_root}/bin%b to \$PATH:%b\n" \
"${BLUE}" "${YELLOW}" "${BLUE}" "${DEFAULT}"
printf "%bexport PATH=${ponyup_root}/bin:\$PATH%b\n" \
"${YELLOW}" "${DEFAULT}"
;;
esac
fi

0 comments on commit 5e91962

Please sign in to comment.