implement fail function

This commit is contained in:
drduh 2025-06-15 13:01:56 -07:00
parent ca81deff35
commit 8c0a752934

View file

@ -11,14 +11,20 @@ umask 077
export LC_ALL="C" export LC_ALL="C"
fail() {
# Print an error string in red and exit.
tput setaf 1 ; printf "%s\n" "${1}" ; tput sgr0
exit 1
}
print_cred () { print_cred () {
# Print a credential string in red. # Print a credential string in red.
tput setaf 1 ; printf "%s\n" "${1}" ; tput sgr0 tput setaf 1 ; printf "%s\n" "${1}" ; tput sgr0
} }
print_id () { print_id () {
# Print an identity string in yellow. # Print an identity string in yellow.
tput setaf 3 ; printf "%s\n" "${1}" ; tput sgr0 tput setaf 3 ; printf "%s\n" "${1}" ; tput sgr0
} }
get_id_label () { get_id_label () {
@ -28,12 +34,13 @@ get_id_label () {
get_key_type () { get_key_type () {
# Returns key type and size. # Returns key type and size.
#printf "default"
printf "rsa4096" printf "rsa4096"
} }
get_key_expiration () { get_key_expiration () {
# Returns key expiration date. # Returns key expiration date.
printf "2027-05-01" printf "2027-07-01"
} }
get_temp_dir () { get_temp_dir () {
@ -87,6 +94,9 @@ set_fingerprint () {
key_list=$(gpg --list-secret-keys --with-colons) key_list=$(gpg --list-secret-keys --with-colons)
export KEY_ID=$(printf "$key_list" | awk -F: '/^sec/ { print $5; exit }') export KEY_ID=$(printf "$key_list" | awk -F: '/^sec/ { print $5; exit }')
export KEY_FP=$(printf "$key_list" | awk -F: '/^fpr/ { print $10; exit }') export KEY_FP=$(printf "$key_list" | awk -F: '/^fpr/ { print $10; exit }')
if [[ -z "$KEY_FP" || -z "$KEY_ID" ]]; then
fail "could not set key fingerprint"
fi
printf "got identity (fp='%s', id='%s')\n" "$KEY_FP" "$KEY_ID" printf "got identity (fp='%s', id='%s')\n" "$KEY_FP" "$KEY_ID"
} }