Repository: nvm-sh/nvm
File: nvm.sh (Shell)

Code before:
    return 3
  fi
  echo "$VERSIONS"
}

nvm_checksum() {
  local NVM_CHECKSUM
  if [ -z "$3" ] || [ "$3" == "sha1" ]; then
    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
      echo "Unaliased sha1sum, sha1, or shasum not found." >&2
      return 2
    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, sha256, or gsha256sum not found." >&2
      echo "WARNING: Continuing *without checksum verification*" >&2
      return
    fi
  fi

  if [ "_$NVM_CHECKSUM" = "_$2" ]; then
    return
  elif [ -z "$2" ]; then
    echo 'Checksums empty' #missing in raspberry pi binary
    return
  else
    echo 'Checksums do not match.' >&2
    return 1
  fi
}


Review comment (suggestion):
Homebrew on OS X commonly [prefixes GNU utilities with `g`](https://github.com/Homebrew/homebrew/blob/bccdd2869233109e61d02f8a0f5081e1dd6aba85/Library/Formula/coreutils.rb#L67), including `sha256sum`.


Code after:
    return 3
  fi
  echo "$VERSIONS"
}

nvm_checksum() {
  local NVM_CHECKSUM
  if [ -z "$3" ] || [ "$3" == "sha1" ]; then
    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
      echo "Unaliased sha1sum, sha1, or shasum not found." >&2
      return 2
    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
    return
  elif [ -z "$2" ]; then
    echo 'Checksums empty' #missing in raspberry pi binary
    return
  else
    echo 'Checksums do not match.' >&2
    return 1
  fi
}