Created
May 7, 2021 10:14
-
-
Save airglow923/e7c1b557c51d14ca16c000dcb9e03bb8 to your computer and use it in GitHub Desktop.
A shell script that generates an integrity for a JavaScript file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
usage() { | |
# additional error messages | |
if [ "$#" -ne 0 ]; then | |
printf "$@\n" >&2; | |
fi | |
printf "Usage: $0 ALGORITHM JS_FILE\n" >&2; | |
} | |
if [ "${#@}" -eq 0 ]; then | |
usage | |
exit 1; | |
fi | |
ALGORITHM="$1" | |
FILE="$2" | |
BINARY=$(openssl dgst -"$ALGORITHM" -binary "$FILE") | |
if [ $? -ne 0 ]; then | |
usage | |
exit 1; | |
fi | |
INTEGRITY=$(echo -n "$BINARY" | openssl base64 -A) | |
echo "$ALGORITHM-$INTEGRITY" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment