Skip to content

Instantly share code, notes, and snippets.

@ploxiln
Created May 17, 2017 19:44
Show Gist options
  • Save ploxiln/41879086dd47cf756a72ec4ee69abace to your computer and use it in GitHub Desktop.
Save ploxiln/41879086dd47cf756a72ec4ee69abace to your computer and use it in GitHub Desktop.
getjslibs.sh
#!/bin/sh
set -eu
cd $(dirname $0)
DESTDIR="static/js"
mkdir -p $DESTDIR
JQUERY_VER="3.2.1"
JQUERY_SHA1="fd81582bf1b15e6747472df880ca822c362a97d1"
JQUERY_URL="https://code.jquery.com/jquery-${JQUERY_VER}.js"
UNDERSCORE_VER="1.8.3"
UNDERSCORE_SHA1="8e3a5ace7e47dcadd272642748b7ee8048daddf8"
UNDERSCORE_URL="https://raw.githubusercontent.com/jashkenas/underscore/${UNDERSCORE_VER}/underscore.js"
if which shasum >/dev/null; then SHACMD="shasum -a1"
elif which sha1sum >/dev/null; then SHACMD="sha1sum"
else
echo "ERROR: No supported sha1 tool found" 1>&2 ; exit 1
fi
do_hash() {
$SHACMD "$1" | cut -d' ' -f1
}
dl_file() {
local FILENAME=$1
local HASH=$2
local URL=$3
local FILEPATH=$DESTDIR/$FILENAME
if [ -e $FILEPATH ] && [ $HASH = "$(do_hash $FILEPATH)" ]; then
return
fi
echo "> Downloading $FILENAME ..."
curl -s -k -L "$URL" >$FILEPATH
if [ $HASH != "$(do_hash $FILEPATH)" ]; then
echo "ERROR: $FILENAME did not have expected hash" 1>&2
exit 1
fi
}
dl_file jquery-${JQUERY_VER}.js $JQUERY_SHA1 "$JQUERY_URL"
dl_file underscore-${UNDERSCORE_VER}.js $UNDERSCORE_SHA1 "$UNDERSCORE_URL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment