From 9c65197b221b4b73ab1664392debf805c3addea3 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 9 Aug 2016 22:24:09 -0700 Subject: [PATCH] Add `nvm_get_checksum_alg` --- nvm.sh | 29 +++++++++++++++++++++++ test/fast/Unit tests/nvm_get_checksum_alg | 18 ++++++++++++++ 2 files changed, 47 insertions(+) create mode 100755 test/fast/Unit tests/nvm_get_checksum_alg diff --git a/nvm.sh b/nvm.sh index dc4877f..d48c6e4 100644 --- a/nvm.sh +++ b/nvm.sh @@ -1002,6 +1002,34 @@ nvm_ls_remote_index_tab() { nvm_echo "${VERSIONS}" } +nvm_get_checksum_alg() { + if nvm_has "sha256sum" && ! nvm_is_alias "sha256sum"; then + nvm_echo 'sha-256' + elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then + nvm_echo 'sha-256' + elif nvm_has "sha256" && ! nvm_is_alias "sha256"; then + nvm_echo 'sha-256' + elif nvm_has "gsha256sum" && ! nvm_is_alias "gsha256sum"; then + nvm_echo 'sha-256' + elif nvm_has "openssl" && ! nvm_is_alias "openssl"; then + nvm_echo 'sha-256' + elif nvm_has "libressl" && ! nvm_is_alias "libressl"; then + nvm_echo 'sha-256' + elif nvm_has "bssl" && ! nvm_is_alias "bssl"; then + nvm_echo 'sha-256' + elif nvm_has "sha1sum" && ! nvm_is_alias "sha1sum"; then + nvm_echo 'sha-1' + elif nvm_has "sha1" && ! nvm_is_alias "sha1"; then + nvm_echo 'sha-1' + elif nvm_has "shasum" && ! nvm_is_alias "shasum"; then + nvm_echo 'sha-1' + else + nvm_err 'Unaliased sha256sum, shasum, sha256, gsha256sum, openssl, libressl, or bssl not found.' + nvm_err 'Unaliased sha1sum, sha1, or shasum not found.' + return 1 + fi +} + nvm_checksum() { local NVM_CHECKSUM if [ -z "${3-}" ] || [ "${3-}" = 'sha1' ]; then @@ -2849,6 +2877,7 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')" nvm_install_iojs_binary nvm_install_node_binary \ nvm_install_merged_node_binary \ nvm_install_node_source nvm_check_file_permissions \ + nvm_get_checksum_alg \ nvm_version nvm_rc_version nvm_match_version \ nvm_ensure_default_set nvm_get_arch nvm_get_os \ nvm_print_implicit_alias nvm_validate_implicit_alias \ diff --git a/test/fast/Unit tests/nvm_get_checksum_alg b/test/fast/Unit tests/nvm_get_checksum_alg new file mode 100755 index 0000000..e794595 --- /dev/null +++ b/test/fast/Unit tests/nvm_get_checksum_alg @@ -0,0 +1,18 @@ +#!/bin/sh + +set -ex + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +ALG="$(nvm_get_checksum_alg)" + +case "$ALG" in + 'sha-256' | 'sha-1') + echo 'sha-256 or sha-1 found' + ;; + *) + die "sha-256 or sha-1 not found: found ${ALG}" + ;; +esac