Added (optional) support for sha256 checksum utils

This commit adds (optional) support for additional sha256 checksum utilities
for newer versions of node.js and io.js that use sha256 checksums rather than
sha1.

If nothing is found to do a sha256 checksum on the client machine, a warning is
printed and things continue on as normal.

Following comments from @ljharb on incorporating some of @DomT4's PR
creationix/nvm#664, and making this checksum optional.  If I could I would
gladly include this as an addon to the now closed PR creationix/nvm#664. I am
choosing not to file it onto that PR because it's closed and (currently)
significantly behind the master branch.

@DomT4 did the hard work of actually finding all the different ways in which
one could verify a sha256 checksum, I've just included those here in an effort
to move forward with sha256 checksum support.
Brandon Wood 2016-01-23 22:17:43 -06:00
parent 560c8c9500
commit f1bca106a8
1 changed files with 13 additions and 4 deletions

17
nvm.sh
View File

@ -772,14 +772,23 @@ nvm_checksum() {
fi
else
if nvm_has "sha256sum" && ! nvm_is_alias "sha256sum"; then
NVM_CHECKSUM="$(command sha256sum "$1" | command awk '{print $1}')"
NVM_CHECKSUM="$(sha256sum "$1" | awk '{print $1}')"
elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then
NVM_CHECKSUM="$(shasum -a 256 "$1" | awk '{print $1}')"
elif nvm_has "sha256" && ! nvm_is_alias "sha256"; then
NVM_CHECKSUM="$(command sha256 -q "$1")"
NVM_CHECKSUM="$(sha256 -q "$1" | awk '{print $1}')"
elif nvm_has "gsha256sum" && ! nvm_is_alias "gsha256sum"; then
NVM_CHECKSUM="$(gsha256sum "$1" | command awk '{print $1}')"
NVM_CHECKSUM="$(gsha256sum "$1" | awk '{print $1}')"
elif nvm_has "openssl" && ! nvm_is_alias "openssl"; then
NVM_CHECKSUM="$(openssl dgst -sha256 "$1" | rev | awk '{print $1}' | rev)"
elif nvm_has "libressl" && ! nvm_is_alias "libressl"; then
NVM_CHECKSUM="$(libressl dgst -sha256 "$1" | rev | awk '{print $1}' | rev)"
elif nvm_has "bssl" && ! nvm_is_alias "bssl"; then
NVM_CHECKSUM="$(bssl sha256sum "$1" | awk '{print $1}')"
else
echo "Unaliased sha256sum, sha256, or gsha256sum not found." >&2
return 2
echo "WARNING: Continuing *without checksum verification*" >&2
return
fi
fi