Skip to content

Instantly share code, notes, and snippets.

@timcharper
Created August 5, 2017 01:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timcharper/f2379d371960abc96d094ae395a7fe73 to your computer and use it in GitHub Desktop.
Save timcharper/f2379d371960abc96d094ae395a7fe73 to your computer and use it in GitHub Desktop.
Download file checking sha256sum
#/bin/bash
URL="$1"
DEST="$2"
SHA256SUM=$3
curl -L -f -o "${2}.tmp" "$1"
do_sha256sum() {
cmd=$(which sha256sum shasum | head -n 1)
case $(basename "$cmd") in
sha256sum)
sha256sum "$1" | cut -f 1 -d ' '
;;
shasum)
shasum -a 256 "$1" | cut -f 1 -d ' '
;;
*)
echo "Couldn't find shasum" 1>&2
;;
esac
}
FILE_SHA256SUM="$(do_sha256sum "$2.tmp")"
if [ "$FILE_SHA256SUM" == "$SHA256SUM" ]; then
mv $2.tmp $2
exit 0
else
echo "sha256sum did not match" 1>&2
echo "Expected: $SHA256SUM" 1>&2
echo "Got: $FILE_SHA256SUM" 1>&2
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment