Skip to content

Instantly share code, notes, and snippets.

@narthollis
Last active January 29, 2016 02:22
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 narthollis/93f4547fad76687988ad to your computer and use it in GitHub Desktop.
Save narthollis/93f4547fad76687988ad to your computer and use it in GitHub Desktop.
#!/bin/bash
INDEX_URL="http://emotes.gbs.io/"
ZIP_URL="https://s3.amazonaws.com/emotes.gbs.io/pidgin.zip"
ZIP_OUT="pidgin.zip"
ERROR_UNSPECIFIED=1
ERROR_NO_ETAG=2
ERROR_DOWNLOAD_FAIL=3
ERROR_UNZIP_FAIL=4
headers=`curl -sIX HEAD "$ZIP_URL"`
new_etag=""
if [[ $headers =~ [Ee][Tt][Aa][Gg]:\ \"(.*)\" ]]; then
new_etag="${BASH_REMATCH[1]}";
else
exit $ERROR_NO_ETAG;
fi
if [ -f "${ZIP_OUT}.etag" ]; then
old_etag=`cat "${ZIP_OUT}.etag"`
if [[ "$old_etag" == "$new_etag" ]]; then
# no changes, exit with success
exit 0
fi
fi
if curl -s "$ZIP_URL" > "$ZIP_OUT"; then
if unzip -uq "$ZIP_OUT"; then
echo $new_etag > "${ZIP_OUT}.etag"
# woo! success
exit 0
else
exit $ERROR_UNZIP_FAIL
fi
else
exit $ERROR_DOWNLOAD_FAIL
fi
exit $ERROR_UNSPECIFIED;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment