Merge pull request #981 from woodb/node-v4-checksums

[New] Added support for sha256 checksums on `io.js` / merged `node`.

Fixes #664, relates to #736 and #687.
Jordan Harband 2016-01-24 10:40:06 -08:00
commit 754a0d7c5b
1 changed files with 32 additions and 12 deletions

28
nvm.sh
View File

@ -759,6 +759,7 @@ nvm_ls_remote_index_tab() {
nvm_checksum() { nvm_checksum() {
local NVM_CHECKSUM local NVM_CHECKSUM
if [ -z "$3" ] || [ "$3" == "sha1" ]; then
if nvm_has "sha1sum" && ! nvm_is_alias "sha1sum"; then if nvm_has "sha1sum" && ! nvm_is_alias "sha1sum"; then
NVM_CHECKSUM="$(command sha1sum "$1" | command awk '{print $1}')" NVM_CHECKSUM="$(command sha1sum "$1" | command awk '{print $1}')"
elif nvm_has "sha1" && ! nvm_is_alias "sha1"; then elif nvm_has "sha1" && ! nvm_is_alias "sha1"; then
@ -769,6 +770,27 @@ nvm_checksum() {
echo "Unaliased sha1sum, sha1, or shasum not found." >&2 echo "Unaliased sha1sum, sha1, or shasum not found." >&2
return 2 return 2
fi fi
else
if nvm_has "sha256sum" && ! nvm_is_alias "sha256sum"; then
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="$(sha256 -q "$1" | awk '{print $1}')"
elif nvm_has "gsha256sum" && ! nvm_is_alias "gsha256sum"; then
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, shasum, sha256, gsha256sum, openssl, libressl, or bssl not found." >&2
echo "WARNING: Continuing *without checksum verification*" >&2
return
fi
fi
if [ "_$NVM_CHECKSUM" = "_$2" ]; then if [ "_$NVM_CHECKSUM" = "_$2" ]; then
return return
@ -1051,8 +1073,7 @@ nvm_install_merged_node_binary() {
fi fi
if ( if (
[ "$NVM_INSTALL_ERRORED" != true ] && \ [ "$NVM_INSTALL_ERRORED" != true ] && \
echo "WARNING: checksums are currently disabled for node.js v4.0 and later" >&2 && \ nvm_checksum "$tmptarball" "$sum" "sha256" && \
# nvm_checksum "$tmptarball" "$sum" && \
command tar -x${tar_compression_flag}f "$tmptarball" -C "$tmpdir" --strip-components 1 && \ command tar -x${tar_compression_flag}f "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command rm -f "$tmptarball" && \ command rm -f "$tmptarball" && \
command mkdir -p "$VERSION_PATH" && \ command mkdir -p "$VERSION_PATH" && \
@ -1126,8 +1147,7 @@ nvm_install_iojs_binary() {
fi fi
if ( if (
[ "$NVM_INSTALL_ERRORED" != true ] && \ [ "$NVM_INSTALL_ERRORED" != true ] && \
echo "WARNING: checksums are currently disabled for io.js" >&2 && \ nvm_checksum "$tmptarball" "$sum" "sha256" && \
# nvm_checksum "$tmptarball" "$sum" && \
command tar -x${tar_compression_flag}f "$tmptarball" -C "$tmpdir" --strip-components 1 && \ command tar -x${tar_compression_flag}f "$tmptarball" -C "$tmpdir" --strip-components 1 && \
command rm -f "$tmptarball" && \ command rm -f "$tmptarball" && \
command mkdir -p "$VERSION_PATH" && \ command mkdir -p "$VERSION_PATH" && \