From 820074e1d7b5b0ca80020b3c82dd95b2d3b5f1b8 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 15 Feb 2015 23:32:33 -0800 Subject: [PATCH] Make sure checksum commands are not aliases. Fixes #659, #420, #640. --- nvm.sh | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/nvm.sh b/nvm.sh index 3705bbd..0a9b586 100644 --- a/nvm.sh +++ b/nvm.sh @@ -12,6 +12,10 @@ nvm_has() { type "$1" > /dev/null 2>&1 } +nvm_is_alias() { + command alias "$1" > /dev/null 2>&1 +} + nvm_get_latest() { local NVM_LATEST_URL if nvm_has "curl"; then @@ -633,15 +637,19 @@ nvm_ls_remote_iojs() { } nvm_checksum() { - if nvm_has "sha1sum"; then - checksum="$(command sha1sum "$1" | command awk '{print $1}')" - elif nvm_has "sha1"; then - checksum="$(command sha1 -q "$1")" + local NVM_CHECKSUM + if nvm_has "sha1sum" && ! nvm_is_alias "sha1sum"; then + NVM_CHECKSUM="$(command sha1sum "$1" | command awk '{print $1}')" + elif nvm_has "sha1" && ! nvm_is_alias "sha1"; then + NVM_CHECKSUM="$(command sha1 -q "$1")" + elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then + NVM_CHECKSUM="$(shasum "$1" | command awk '{print $1}')" else - checksum="$(shasum "$1" | command awk '{print $1}')" + echo "Unaliased sha1sum, sha1, or shasum not found." >&2 + return 2 fi - if [ "_$checksum" = "_$2" ]; then + if [ "_$NVM_CHECKSUM" = "_$2" ]; then return elif [ -z "$2" ]; then echo 'Checksums empty' #missing in raspberry pi binary