#!/bin/env sh TEMPLATE_FILE="$(dirname "$0")/verify-script.template" 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" SUBSTITUTED_TEMPLATE=$(sed -e "s!{message}!$MESSAGE!g" -e "s!{filename}!$FILE_NAME!g" -e "s!{filehash}!$FILE_HASH!g" "$TEMPLATE_FILE") printf '%s' "$SUBSTITUTED_TEMPLATE" > "$1.sh"