Skip to content

Commit 97bbc70

Browse files
author
George Adams
committed
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<NODE_VERSION>/` It will then loop through the `SHASUMS256.txt` file to check if the SHA256SUMS match up. Initial issue here: #513
1 parent 5aea8f0 commit 97bbc70

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

tools/download-test.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
while [[ $# -gt 1 ]]
4+
do
5+
key="$1"
6+
7+
case "$key" in
8+
-t|--tap)
9+
TAP="$2"
10+
shift # past argument
11+
;;
12+
*) # unknown option
13+
;;
14+
esac
15+
shift # past argument or value
16+
done
17+
18+
if [ "$DOWNLOAD_LOCATION" == "Nightly" ]; then
19+
DOWNLOAD_DIR="nightly"
20+
else
21+
DOWNLOAD_DIR="release"
22+
fi
23+
24+
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}'`
25+
26+
if [ -z "$NODE_VERSION" ]; then
27+
echo "NODE_VERSION is undefined! Please declare NODE_VERSION"
28+
exit 1
29+
fi
30+
31+
# Remove old files
32+
[ "$TAP" ] && rm -rf "$TAP"
33+
rm -rf v*
34+
35+
# Scrape the download server
36+
rsync -av rsync://unencrypted.nodejs.org/nodejs/"$DOWNLOAD_DIR"/"$LINK" .
37+
38+
num=1
39+
cat "$LINK"/SHASUMS256.txt | { while read line
40+
do
41+
sha=$(echo "${line}" | awk '{print $1}')
42+
file=$(echo "${line}" | awk '{print $2}')
43+
echo "Checking shasum for $file"
44+
remoteSHA=$(shasum -a 256 "$LINK/$file" | awk '{print $1}')
45+
if [ "$remoteSHA" != "$sha" ]; then
46+
echo "Error - SHASUMS256 does not match for $file"
47+
echo "Expected - $sha"
48+
echo "Found - $remoteSHA"
49+
[ "${TAP}" ] && echo "not ok $num SHASUMS256 does not match for $file" >> "$TAP"
50+
return 1
51+
else
52+
echo "Pass - SHASUMS256 for $file is correct"
53+
[ "$TAP" ] && echo "ok $num SHASUMS256 for $file is correct" >> "$TAP"
54+
fi
55+
let num++
56+
done
57+
let num--
58+
[ "$TAP" ] && echo "1..$num" >> "$TAP"
59+
}

0 commit comments

Comments
 (0)