3 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
4 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
5 try
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
6 check_resembles_gpg_fingerprint
() {
7 # Desc: Checks if input string looks like gpg fingerprint
8 # Usage: check_resembles_gpg_fingerprint arg1
10 # Output: exit code: 0 if arg1 is fingerprint, 1 otherwise
11 # Depends: yell(), die(), try()
13 local pattern1 pattern2 input input_length
16 if [[ $# -ne 1 ]]; then
17 die
"ERROR:Invalid number of arguments:$#";
24 if [[ $input =~
$pattern1 ]]; then
26 #yell "DEBUG:input:$input";
29 ## Check if char count multiple of 8
30 input_length
="${#input}";
31 if [[ ! $
(( input_length
% 8 )) -eq 0 ]]; then
32 yell
"DEBUG:Length not a multiple of 8:$input_length:$input";
36 ## Check if hexadecimal
37 pattern2
="[0-9A-Fa-f]{8,40}";
38 if [[ $1 =~
$pattern2 ]]; then
39 #yell "DEBUG:is a fingerprint:$arg";
42 #yell "DEBUG:Not a fingerprint:$arg";
45 }; # Checks if input string looks like gpg fingerprint
50 if check_resembles_gpg_fingerprint
"$myVar"; then
51 yell
"Looks like a gpg fingerprint:$myVar";
53 yell
"Doesn't look like a gpg fingerprint:$myVar";
56 myVar
="69B4C4CDC628F8F9";
57 if check_resembles_gpg_fingerprint
"$myVar"; then
58 yell
"Looks like a gpg fingerprint:$myVar";
60 yell
"Doesn't look like a gpg fingerprint:$myVar";
63 myVar
="26646D99CBAEC9B81982EF6029D9EE6B1FC730C1";
64 if check_resembles_gpg_fingerprint
"$myVar"; then
65 yell
"Looks like a gpg fingerprint:$myVar";
67 yell
"Doesn't look like a gpg fingerprint:$myVar";
71 if check_resembles_gpg_fingerprint
"$myVar"; then
72 yell
"Looks like a gpg fingerprint:$myVar";
74 yell
"Doesn't look like a gpg fingerprint:$myVar";
78 if check_resembles_gpg_fingerprint
"$myVar"; then
79 yell
"Looks like a gpg fingerprint:$myVar";
81 yell
"Doesn't look like a gpg fingerprint:$myVar";
85 if check_resembles_gpg_fingerprint
"$myVar"; then
86 yell
"Looks like a gpg fingerprint:$myVar";
88 yell
"Doesn't look like a gpg fingerprint:$myVar";