diff --git a/create-file-message.sh b/create-file-message.sh index fcb5ee3..1392b6d 100644 --- a/create-file-message.sh +++ b/create-file-message.sh @@ -1,19 +1,23 @@ #!/bin/env sh TEMPLATE_FILE="$(dirname "$0")/verify-script.template" -#echo "template: $TEMPLATE_FILE" +if [ ! -f "$TEMPLATE_FILE" ]; then + echo "'$TEMPLATE_FILE' not found. The template file should have come with this script." 1>&2 + exit 1 +fi + +FILE_PATH="$1" +if [ ! -f "$FILE_PATH" ]; then + echo "'$FILE_PATH' not found" 1>&2 + exit 1 +fi +FILE_NAME="$(basename "$FILE_PATH")" +FILE_HASH="$(sha256sum "$FILE_PATH" | awk '{print $1}')" # TODO: argument for the message in case you want to apply it to many files. read -r -p "Enter message to sign for the file: " MESSAGE MESSAGE="$MESSAGE\n" -#echo "message: $MESSAGE" - -FILE_NAME="$(basename "$1")" -#echo "file name: $FILE_NAME" -FILE_HASH="$(sha256sum "$FILE_NAME" | awk '{print $1}')" -#echo "file hash: $FILE_HASH" SUBSTITUTED_TEMPLATE=$(sed -e "s!{message}!$MESSAGE!g" -e "s!{filename}!$FILE_NAME!g" -e "s!{filehash}!$FILE_HASH!g" "$TEMPLATE_FILE") -#echo "substituted: $SUBSTITUTED_TEMPLATE" printf '%s' "$SUBSTITUTED_TEMPLATE" > "$1.sh" \ No newline at end of file