From 31fbb3a1385002af47f9ebcd281097220c7bac86 Mon Sep 17 00:00:00 2001 From: Wiley Young Date: Apr 23 2020 20:20:48 +0000 Subject: Update gpgverify updating bash syntax: adding quotes, changing `test` to `[[`, add and exit code, etc. --- diff --git a/gpgverify b/gpgverify index 524a396..162a03e 100755 --- a/gpgverify +++ b/gpgverify @@ -12,6 +12,7 @@ # modified is included with the above copyright notice. + function print_help { cat <<'EOF' Usage: gpgverify --keyring= --signature= --data= @@ -35,16 +36,16 @@ EOF fatal_error() { message="$1" # an error message - status=$2 # a number to use as the exit code + status="$2" # a number to use as the exit code echo "gpgverify: $message" >&2 - exit $status + exit "$status" } require_parameter() { term="$1" # a term for a required parameter value="$2" # Complain and terminate if this value is empty. - if test -z "${value}" ; then + if [[ -z "$value" ]] ; then fatal_error "No ${term} was provided." 2 fi } @@ -52,9 +53,9 @@ require_parameter() { check_status() { action="$1" # a string that describes the action that was attempted - status=$2 # the exit code of the command - if test $status -ne 0 ; then - fatal_error "$action failed." $status + status="$2" # the exit code of the command + if [[ $status -ne 0 ]] ; then + fatal_error "$action failed." "$status" fi } @@ -65,21 +66,21 @@ signature= data= for parameter in "$@" ; do case "${parameter}" in - (--help) + --help) print_help exit ;; - (--keyring=*) + --keyring=*) keyring="${parameter#*=}" ;; - (--signature=*) + --signature=*) signature="${parameter#*=}" ;; - (--data=*) + --data=*) data="${parameter#*=}" ;; - (*) - fatal_error "Unknown parameter: \"${parameter}\"" 2 + *) + fatal_error 'Unknown parameter:' "$parameter" 2 ;; esac done @@ -89,17 +90,17 @@ require_parameter 'data file' "${data}" # Make a temporary working directory. workdir="$(mktemp --directory)" -check_status 'Making a temporary directory' $? +check_status 'Making a temporary directory' "$?" workring="${workdir}/keyring.gpg" # Decode any ASCII armor on the keyring. This is harmless if the keyring isn't # ASCII-armored. gpg2 --homedir="${workdir}" --yes --output="${workring}" --dearmor "${keyring}" -check_status 'Decoding the keyring' $? +check_status 'Decoding the keyring' "$?" # Verify the signature using the decoded keyring. gpgv2 --homedir="${workdir}" --keyring="${workring}" "${signature}" "${data}" -check_status 'Signature verification' $? +check_status 'Signature verification' "$?" # (--homedir isn't actually necessary. --dearmor processes only the input file, # and if --keyring is used and contains a slash, then gpgv2 uses only that