Skip to content

Commit

Permalink
Try shasum if no sha256sum binary (address #1)
Browse files Browse the repository at this point in the history
  • Loading branch information
jstrieb committed Nov 16, 2024
1 parent bf8120d commit 855f530
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions just_sh/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ def expression_to_string(expression: ExpressionType, depth: int = 0) -> str:
"sha256_file": r"""sha256_file() {
if type sha256sum > /dev/null 2>&1; then
sha256sum --binary "${1}" | cut -d ' ' -f 1
elif type shasum > /dev/null 2>&1; then
shasum --algorithm 256 --binary "${1}" | cut -d ' ' -f 1
elif type python3 > /dev/null 2>&1; then
python3 -c 'from hashlib import sha256; import sys; print(sha256(sys.stdin.buffer.read()).hexdigest())' \
< "${1}"
Expand All @@ -285,6 +287,8 @@ def expression_to_string(expression: ExpressionType, depth: int = 0) -> str:
"sha256": r"""sha256() {
if type sha256sum > /dev/null 2>&1; then
printf "%s" "${1}" | sha256sum --binary | cut -d ' ' -f 1
if type shasum > /dev/null 2>&1; then
printf "%s" "${1}" | shasum --algorithm 256 --binary | cut -d ' ' -f 1
elif type python3 > /dev/null 2>&1; then
printf "%s" "${1}" | \
python3 -c 'from hashlib import sha256; import sys; print(sha256(sys.stdin.buffer.read()).hexdigest())'
Expand Down

0 comments on commit 855f530

Please sign in to comment.