Skip to content

Instantly share code, notes, and snippets.

@mrinalwadhwa
Created February 13, 2016 14:01
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 mrinalwadhwa/7ef2fa6f58ad894f6d0a to your computer and use it in GitHub Desktop.
Save mrinalwadhwa/7ef2fa6f58ad894f6d0a to your computer and use it in GitHub Desktop.
Script to download and check hash
#!/usr/bin/env bash
#
# Usage:
# download.sh URL DEST MD5
#
# Example:
# download.sh \
# http://a.mbbsindia.com/hbase/1.1.3/hbase-1.1.3-bin.tar.gz \
# /var/downloads/cache/1c9f52d89cf665ef35f101cb8f2b57e4 \
# 1c9f52d89cf665ef35f101cb8f2b57e4
#
url="$1"
dest_path="$2"
expected_hash="$3"
curl -L# -o "$dest_path" "$url"
generated_hash=`md5 "$dest_path" | cut -d' ' -f4`
if [ "$generated_hash" == "$expected_hash" ]; then
exit 0
else
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment