jstrieb / just.sh

Compile Justfiles to portable shell scripts
https://jstrieb.github.io/just.sh/
GNU General Public License v3.0
135 stars 2 forks source link

Polyfilling sha256 #1

Open mentalisttraceur opened 7 months ago

mentalisttraceur commented 7 months ago

You have a comment in the readme about being unable to make sha256 portable without relying on Python.

Well, there's at least partial progress to be made by using shasum as a fallback. For example:

if command -v sha256sum >/dev/null
then
    sha256sum ...
else
    shasum -a 256 ...
fi

I believe this will cover basically every modern practically usable system that has a /bin/sh.

In particular, to my knowledge/memory, this covers

  1. basically every Linux distro (sha256sum installed by default),
  2. Git Bash, BusyBox-w32, and the like on Windows, and
  3. MacOS (shasum installed by default).
mentalisttraceur commented 7 months ago

If neither exists, yet another option which might be available in places Python isn't is the openssl CLI: openssl sha256, although that has a different output format than the already mentioned.