From a8ac4c2d06e958b92aef193652ac4f8e413401bf Mon Sep 17 00:00:00 2001 From: Nathan Christopher McRae Date: Sun, 23 Nov 2025 20:02:06 -0800 Subject: [PATCH] Fix some issues found by shellcheck --- create-file-message.sh | 15 ++++++++------- verify-script.template | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/create-file-message.sh b/create-file-message.sh index 2c6ccf7..fcb5ee3 100644 --- a/create-file-message.sh +++ b/create-file-message.sh @@ -1,18 +1,19 @@ -#!/bin/bash +#!/bin/env sh -TEMPLATE_FILE="$(dirname $0)/verify-script.template" +TEMPLATE_FILE="$(dirname "$0")/verify-script.template" +#echo "template: $TEMPLATE_FILE" # TODO: argument for the message in case you want to apply it to many files. -read -p "Enter message to sign for the file: " MESSAGE +read -r -p "Enter message to sign for the file: " MESSAGE MESSAGE="$MESSAGE\n" #echo "message: $MESSAGE" -FILE_NAME="$(basename $1)" +FILE_NAME="$(basename "$1")" #echo "file name: $FILE_NAME" -FILE_HASH="$(sha256sum $FILE_NAME | awk '{print $1}')" +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) +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 "$SUBSTITUTED_TEMPLATE" > "$1.sh" \ No newline at end of file +printf '%s' "$SUBSTITUTED_TEMPLATE" > "$1.sh" \ No newline at end of file diff --git a/verify-script.template b/verify-script.template index 9773faa..6d3aa78 100644 --- a/verify-script.template +++ b/verify-script.template @@ -5,7 +5,7 @@ FILE="{filename}" EXPECTED_HASH="{filehash}" if [ "$(sha256sum "$FILE" | awk '{print $1}')" = "$EXPECTED_HASH" ]; then - printf "File %%s validated with message:\\n%%s" "$FILE" "$MESSAGE" + printf "File %s validated with message:\\n%s" "$FILE" "$MESSAGE" exit 0 else echo "File $FILE is not valid"