From 2e377a64d65f43374561cb6bccfa7dda016de6a7 Mon Sep 17 00:00:00 2001 From: George Adams Date: Wed, 19 Jul 2017 19:08:11 +0100 Subject: [PATCH] tools: add download testing This script will take an environment variable (NODE_VERSION) and download all of the files from `http://nodejs.org/dist/v/` It will then loop through the `SHASUMS256.txt` file to check if the SHA256SUMS match up. Initial issue here: https://github.com/nodejs/build/issues/513 --- tools/download-test.sh | 59 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 tools/download-test.sh diff --git a/tools/download-test.sh b/tools/download-test.sh new file mode 100755 index 000000000..0957fda43 --- /dev/null +++ b/tools/download-test.sh @@ -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 -r "$TAP" || true +rm -r v* || true + +# 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" +}