Skip to content

Commit

Permalink
tools: add download testing
Browse files Browse the repository at this point in the history
This script will take an environment variable (NODE_VERSION) and
download all of the files from `http://nodejs.org/dist/v<NODE_VERSION>/`
It will then loop through the `SHASUMS256.txt` file to check if the
SHA256SUMS match up. Initial issue here:
#513
  • Loading branch information
George Adams committed Aug 17, 2017
1 parent 5aea8f0 commit 97bbc70
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions tools/download-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/bin/bash

while [[ $# -gt 1 ]]
do
key="$1"

case "$key" in
-t|--tap)
TAP="$2"
shift # past argument
;;
*) # unknown option
;;
esac
shift # past argument or value
done

if [ "$DOWNLOAD_LOCATION" == "Nightly" ]; then
DOWNLOAD_DIR="nightly"
else
DOWNLOAD_DIR="release"
fi

LINK=`rsync rsync://unencrypted.nodejs.org/nodejs/$DOWNLOAD_DIR/ | grep $NODE_VERSION | sort -t. -k 1,1n -k 2,2n -k 3,3n | tail -1 | awk '{print $5}'`

if [ -z "$NODE_VERSION" ]; then
echo "NODE_VERSION is undefined! Please declare NODE_VERSION"
exit 1
fi

# Remove old files
[ "$TAP" ] && rm -rf "$TAP"
rm -rf v*

# Scrape the download server
rsync -av rsync://unencrypted.nodejs.org/nodejs/"$DOWNLOAD_DIR"/"$LINK" .

num=1
cat "$LINK"/SHASUMS256.txt | { while read line
do
sha=$(echo "${line}" | awk '{print $1}')
file=$(echo "${line}" | awk '{print $2}')
echo "Checking shasum for $file"
remoteSHA=$(shasum -a 256 "$LINK/$file" | awk '{print $1}')
if [ "$remoteSHA" != "$sha" ]; then
echo "Error - SHASUMS256 does not match for $file"
echo "Expected - $sha"
echo "Found - $remoteSHA"
[ "${TAP}" ] && echo "not ok $num SHASUMS256 does not match for $file" >> "$TAP"
return 1
else
echo "Pass - SHASUMS256 for $file is correct"
[ "$TAP" ] && echo "ok $num SHASUMS256 for $file is correct" >> "$TAP"
fi
let num++
done
let num--
[ "$TAP" ] && echo "1..$num" >> "$TAP"
}

0 comments on commit 97bbc70

Please sign in to comment.