13c22ee30d0e8aa50b1584cdf9293c0cecda908f
2 # Desc: A script that outputs a list of GPG signatures from git log output
3 # Usage: get_gpgkey_from_gitlog.sh [dir]
4 # Input: arg1: directory
5 # Output: stdout: newline-delimited list of 40-char GPG fingerprints
10 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
11 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
12 try
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
14 # Desc: Check arguments
15 if [[ $# -ne 1 ]]; then die
"FATAL:Incorrect number of arguments:$#"; fi;
16 if [[ ! -d $1 ]]; then die
"Not a directory:$1"; fi;
20 # Input: arg1: git dir
21 # Output: var: $buffer: newline-delimited list of gpg fingerprints
22 pushd "$1" 1>/dev
/random || die
"FATAL:Failed to change directory:$1";
23 buffer
="$(git log --show-signature 2>&1)";
24 yell
"DEBUG:Buffer has $(wc -l < <(printf "%s
" "$buffer")) lines.";
25 buffer
="$(grep -E -- "^gpg
:" < <( printf "%s
" "$buffer" ) )";
26 yell
"DEBUG:Buffer has $(wc -l < <(printf "%s
" "$buffer")) lines.";
27 buffer
="$(grep -Eo "([0-9A-F]){40}" < <( printf "%s
" "$buffer" ) )";
28 yell
"DEBUG:Buffer has $(wc -l < <(printf "%s
" "$buffer")) lines.";
29 buffer
="$(sort -u < <( printf "%s
" "$buffer" ))";
30 yell
"DEBUG:Buffer has $(wc -l < <(printf "%s
" "$buffer")) lines.";
31 popd 1>/dev
/random || die
"FATAL:Failed to popd.";
32 }; # fill buffer with git gpg lines
36 printf "%s\n" "$buffer";
42 # git log --show-signature 2>&1 | grep -E -- "^gpg:" | grep -Eo "([0-9A-F]){40}" | sort -u