more careful error checking running gpg

pull/205/head
Josh Rabinowitz 6 years ago
parent 5873865899
commit b268ddf226

@ -161,6 +161,10 @@ function hide {
# shellcheck disable=2086 # shellcheck disable=2086
$gpg_local --use-agent --yes --trust-model=always --encrypt \ $gpg_local --use-agent --yes --trust-model=always --encrypt \
$recipients -o "$output_path" "$input_path" > /dev/null 2>&1 $recipients -o "$output_path" "$input_path" > /dev/null 2>&1
local exit_code=$?
if [[ "$exit_code" -ne 0 ]]; then
_abort "problem encrypting file with gpg: exit code $exit_code"
fi
# If -m option was provided, it will update unencrypted file hash # If -m option was provided, it will update unencrypted file hash
local key="$filename" local key="$filename"
local hash="$file_hash" local hash="$file_hash"

@ -28,9 +28,13 @@ function killperson {
# Getting the local `gpg` command: # Getting the local `gpg` command:
local gpg_local local gpg_local
gpg_local=$(_get_gpg_local) gpg_local=$(_get_gpg_local)
t
for email in "${emails[@]}"; do for email in "${emails[@]}"; do
$gpg_local --batch --yes --delete-key "$email" $gpg_local --batch --yes --delete-key "$email"
local exit_code=$?
if [[ "$exit_code" -ne 0 ]]; then
_abort "problem deleting key with gpg: exit code $exit_code"
fi
done done
echo 'removed keys.' echo 'removed keys.'

@ -11,6 +11,10 @@ function get_gpg_key_count {
local gpg_local local gpg_local
gpg_local=$(_get_gpg_local) gpg_local=$(_get_gpg_local)
$gpg_local --list-public-keys --with-colon | gawk "$AWK_GPG_KEY_CNT" $gpg_local --list-public-keys --with-colon | gawk "$AWK_GPG_KEY_CNT"
local exit_code=$?
if [[ "$exit_code" -ne 0 ]]; then
_abort "problem counting keys with gpg: exit code $exit_code"
fi
} }
function tell { function tell {
@ -68,12 +72,18 @@ function tell {
# shellcheck disable=2154 # shellcheck disable=2154
local keyfile="$filename" local keyfile="$filename"
local exit_code
if [[ -z "$homedir" ]]; then if [[ -z "$homedir" ]]; then
$SECRETS_GPG_COMMAND --export -a "$email" > "$keyfile" $SECRETS_GPG_COMMAND --export -a "$email" > "$keyfile"
exit_code=$?
else else
# It means that homedir is set as an extra argument via `-d`: # It means that homedir is set as an extra argument via `-d`:
$SECRETS_GPG_COMMAND --no-permission-warning --homedir="$homedir" \ $SECRETS_GPG_COMMAND --no-permission-warning --homedir="$homedir" \
--export -a "$email" > "$keyfile" --export -a "$email" > "$keyfile"
exit_code=$?
fi
if [[ "$exit_code" -ne 0 ]]; then
_abort "problem exporting public key for '$email' with gpg: exit code $exit_code"
fi fi
if [[ ! -s "$keyfile" ]]; then if [[ ! -s "$keyfile" ]]; then
@ -84,6 +94,10 @@ function tell {
local gpg_local local gpg_local
gpg_local=$(_get_gpg_local) gpg_local=$(_get_gpg_local)
$gpg_local --import "$keyfile" > /dev/null 2>&1 $gpg_local --import "$keyfile" > /dev/null 2>&1
exit_code=$?
if [[ "$exit_code" -ne 0 ]]; then
_abort "problem importing public key with gpg: exit code $exit_code"
fi
done done
echo "done. ${emails[*]} added as someone who know(s) the secret." echo "done. ${emails[*]} added as someone who know(s) the secret."

Loading…
Cancel
Save