chore(user/get_gpgkey_from_gitlog.sh):Add version number
[BK-2020-03.git] / user / get_gpgkey_from_gitlog.sh
... / ...
CommitLineData
1#!/usr/bin/env bash
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
6# Version: 0.0.1
7
8declare -g buffer;
9
10yell() { echo "$0: $*" >&2; } # print script path and all args to stderr
11die() { yell "$*"; exit 111; } # same as yell() but non-zero exit status
12try() { "$@" || die "cannot $*"; } # runs args as command, reports args if command fails
13check_args() {
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;
17 return 0;
18}; # check args
19fill_buffer() {
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
33main() {
34 check_args "$@";
35 fill_buffer "$1";
36 printf "%s\n" "$buffer";
37 return 0;
38};
39
40main "$@";
41
42# git log --show-signature 2>&1 | grep -E -- "^gpg:" | grep -Eo "([0-9A-F]){40}" | sort -u