From 0c8410fcc3d8fac0cfe3f3c573139ca16b25c526 Mon Sep 17 00:00:00 2001 From: Fraser Tweedale Date: Sat, 10 Aug 2013 14:30:47 +1000 Subject: [PATCH] support FreeBSD's sha1(1) for integrity checks In the absense of shasum(1) (which on FreeBSD is provided by Perl, from ports) nvm falls back to sha1sum(1) which does not exist on FreeBSD. But FreeBSD does have sha1(1) so look for sha1(1) and use it if present. As part of this change, refactor the execution of the checksum program down into nvm_checksum and also clean up some special-casing of empty dist checksums, which is already handled by nvm_checksum. --- nvm.sh | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/nvm.sh b/nvm.sh index 2f60317..b40b88b 100755 --- a/nvm.sh +++ b/nvm.sh @@ -125,7 +125,15 @@ nvm_ls_remote() { } nvm_checksum() { - if [ "$1" = "$2" ]; then + if which shasum >/dev/null 2>&1; then + checksum=$(shasum $1 | awk '{print $1}') + elif which sha1 >/dev/null 2>&1; then + checksum=$(sha1 -q $1) + else + checksum=$(sha1sum $1 | awk '{print $1}') + fi + + if [ "$checksum" = "$2" ]; then return elif [ -z $2 ]; then echo 'Checksums empty' #missing in raspberry pi binary @@ -220,17 +228,12 @@ nvm() { local url local sum local tarball - local shasum='shasum' local nobinary if ! has "curl"; then echo 'NVM Needs curl to proceed.' >&2; fi - if ! has "shasum"; then - shasum='sha1sum' - fi - if [ $# -lt 2 ]; then nvm help return @@ -283,7 +286,7 @@ nvm() { if ( mkdir -p "$tmpdir" && \ curl -L -C - --progress-bar $url -o "$tmptarball" && \ - nvm_checksum `${shasum} "$tmptarball" | awk '{print $1}'` $sum && \ + nvm_checksum "$tmptarball" $sum && \ tar -xzf "$tmptarball" -C "$tmpdir" --strip-components 1 && \ rm -f "$tmptarball" && \ mv "$tmpdir" "$NVM_DIR/$VERSION" @@ -319,7 +322,7 @@ nvm() { [ ! -z $tarball ] && \ mkdir -p "$tmpdir" && \ curl -L --progress-bar $tarball -o "$tmptarball" && \ - if [ "$sum" = "" ]; then : ; else nvm_checksum `${shasum} "$tmptarball" | awk '{print $1}'` $sum; fi && \ + nvm_checksum "$tmptarball" $sum && \ tar -xzf "$tmptarball" -C "$tmpdir" && \ cd "$tmpdir/node-$VERSION" && \ ./configure --prefix="$NVM_DIR/$VERSION" $ADDITIONAL_PARAMETERS && \