From a1d14ea5b83aa09698d7e9aa5c393ca2e07197d8 Mon Sep 17 00:00:00 2001 From: wlaurance Date: Tue, 23 Oct 2012 13:38:53 -0400 Subject: [PATCH] Checksum support for binary downloads Checksum support for source downloads Closes #159 --- nvm.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/nvm.sh b/nvm.sh index 76d242c..0e68c2d 100755 --- a/nvm.sh +++ b/nvm.sh @@ -107,6 +107,17 @@ nvm_ls_remote() return } +nvm_checksum() +{ + if [ "$1" = "$2" ]; then + return + else + echo 'Checksums do not match.' + return 1 + fi +} + + print_versions() { OUTPUT='' @@ -186,10 +197,12 @@ nvm() if [ $binavail -eq 1 ]; then t="$VERSION-$os-$arch" url="http://nodejs.org/dist/$VERSION/node-${t}.tar.gz" + sum=`curl -s http://nodejs.org/dist/$VERSION/SHASUMS.txt.asc | grep node-${t}.tar.gz | awk '{print $1}'` if ( mkdir -p "$NVM_DIR/bin/node-${t}" && \ cd "$NVM_DIR/bin" && \ curl -C - --progress-bar $url -o "node-${t}.tar.gz" && \ + nvm_checksum `shasum node-${t}.tar.gz | awk '{print $1}'` $sum && \ tar -xzf "node-${t}.tar.gz" -C "node-${t}" --strip-components 1 && \ mv "node-${t}" "../$VERSION" && \ rm -f "node-${t}.tar.gz" @@ -207,8 +220,10 @@ nvm() echo "Additional options while compiling: $ADDITIONAL_PARAMETERS" tarball='' + sum='' if [ "`curl -Is "http://nodejs.org/dist/$VERSION/node-$VERSION.tar.gz" | grep '200 OK'`" != '' ]; then tarball="http://nodejs.org/dist/$VERSION/node-$VERSION.tar.gz" + sum=`curl -s http://nodejs.org/dist/$VERSION/SHASUMS.txt | grep node-$VERSION.tar.gz | awk '{print $1}'` elif [ "`curl -Is "http://nodejs.org/dist/node-$VERSION.tar.gz" | grep '200 OK'`" != '' ]; then tarball="http://nodejs.org/dist/node-$VERSION.tar.gz" fi @@ -217,6 +232,7 @@ nvm() mkdir -p "$NVM_DIR/src" && \ cd "$NVM_DIR/src" && \ curl --progress-bar $tarball -o "node-$VERSION.tar.gz" && \ + if [ "$sum" = "" ]; then return 0; else nvm_checksum `shasum node-$VERSION.tar.gz | awk '{print $1}'` $sum; fi && \ tar -xzf "node-$VERSION.tar.gz" && \ cd "node-$VERSION" && \ ./configure --prefix="$NVM_DIR/$VERSION" $ADDITIONAL_PARAMETERS && \