#!/bin/sh # # SRI Hash Generator # # A safer alternative than using external services such as # https://www.srihash.org # # Parameters BASENAME="`basename $0`" URI="$1" TYPE="${2:-sha512}" # Check if [ -z "$URI" ]; then echo "usage: $BASENAME " exit 1 fi # Get file if echo "$URI" | grep -q '^http'; then echo "downloading $URI and generating hash..." HASH="`curl $URI | openssl dgst -$TYPE -binary | openssl base64 -A`" echo "" else if [ -e "$URI" ]; then # See https://www.srihash.org/ HASH="`openssl dgst -$TYPE -binary $URI | openssl base64 -A`" else echo "file not found: $URI" exit 1 fi fi # Generate if echo $URL | grep -q '.js$'; then cat < EOF else cat < EOF fi