Fix some issues found by shellcheck
This commit is contained in:
@@ -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.
|
# 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"
|
MESSAGE="$MESSAGE\n"
|
||||||
#echo "message: $MESSAGE"
|
#echo "message: $MESSAGE"
|
||||||
|
|
||||||
FILE_NAME="$(basename $1)"
|
FILE_NAME="$(basename "$1")"
|
||||||
#echo "file name: $FILE_NAME"
|
#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"
|
#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"
|
#echo "substituted: $SUBSTITUTED_TEMPLATE"
|
||||||
printf "$SUBSTITUTED_TEMPLATE" > "$1.sh"
|
printf '%s' "$SUBSTITUTED_TEMPLATE" > "$1.sh"
|
||||||
@@ -5,7 +5,7 @@ FILE="{filename}"
|
|||||||
EXPECTED_HASH="{filehash}"
|
EXPECTED_HASH="{filehash}"
|
||||||
|
|
||||||
if [ "$(sha256sum "$FILE" | awk '{print $1}')" = "$EXPECTED_HASH" ]; then
|
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
|
exit 0
|
||||||
else
|
else
|
||||||
echo "File $FILE is not valid"
|
echo "File $FILE is not valid"
|
||||||
|
|||||||
Reference in New Issue
Block a user