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_gpg_fingerprint
() {
7 # Desc: Checks if input string looks like gpg fingerprint
8 # Usage: check_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
25 input
="$(echo "$input" | sed 's/^..//')";
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_gpg_fingerprint
"$myVar"; then
51 yell
"Looks like a gpg fingerprint:$myVar";
53 yell
"Doesn't look like a gpg fingerprint:$myVar";