2015-05-08 09:21:51 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# Contains a simple fetcher to download a file from a remote URL and verify its
|
2016-01-14 10:14:59 +00:00
|
|
|
# SHA1 or SHA256 checksum (selected based on provided length).
|
2015-05-08 09:21:51 +00:00
|
|
|
#
|
2016-01-14 10:14:59 +00:00
|
|
|
# Usage: fetch.sh <remote URL> <SHA1/SHA256 checksum>
|
2015-05-08 09:21:51 +00:00
|
|
|
set -e
|
|
|
|
|
2015-09-10 08:37:52 +00:00
|
|
|
# Skip the download if no operands specified
|
|
|
|
if [ "$1" == "" -o "$2" == "" ]; then
|
|
|
|
echo "Fetch operands missing, skipping..."
|
|
|
|
exit
|
|
|
|
fi
|
|
|
|
|
2015-05-08 09:21:51 +00:00
|
|
|
# Pull the file from the remote URL
|
|
|
|
file=`basename $1`
|
|
|
|
echo "Downloading $1..."
|
|
|
|
wget -q $1
|
|
|
|
|
|
|
|
# Generate a desired checksum report and check against it
|
|
|
|
echo "$2 $file" > $file.sum
|
2016-01-14 10:14:59 +00:00
|
|
|
if [ "${#2}" == "40" ]; then
|
|
|
|
sha1sum -c $file.sum
|
|
|
|
else
|
|
|
|
sha256sum -c $file.sum
|
|
|
|
fi
|
2015-05-08 09:21:51 +00:00
|
|
|
rm $file.sum
|