Skip to content

Instantly share code, notes, and snippets.

@airglow923
Created May 7, 2021 10:14
Show Gist options
  • Save airglow923/e7c1b557c51d14ca16c000dcb9e03bb8 to your computer and use it in GitHub Desktop.
Save airglow923/e7c1b557c51d14ca16c000dcb9e03bb8 to your computer and use it in GitHub Desktop.
A shell script that generates an integrity for a JavaScript file
#!/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