a18ad7e0c217f4a8c1f982c316908890543acc32
2 # Desc: Export each pubkey to a separate file
3 # Usage: bk-export-min-pubkeys.sh
6 time_now
="$(date +%Y%m%dT%H%M%S%z)";
7 dir_out
="./$time_now..pubkeys";
9 yell
() { echo "$0: $*" >&2; } # print script path and all args to stderr
10 die
() { yell
"$*"; exit 111; } # same as yell() but non-zero exit status
11 try
() { "$@" || die
"cannot $*"; } # runs args as command, reports args if command fails
13 # Desc: Output ascii-armored gpg pubkey via stdout
14 # Input: arg1: pgp long id
15 # Output: stdout: ascii-armored minimal-signature pgp key
16 # Example: gpg_get_pubkey 0xa0a295abdc3469c9
21 output
="$(gpg --export --armor --export-options export-minimal "$longid")";
23 } # Output ascii-armored gpg pubkey via stdout
25 # Create list of primary key fingerprints
26 list_longid
="$(gpg --list-keys | grep "^pub
" | awk '{print $2}' | cut -d'/' -f2)";
29 path_out
="$(readlink -f "$dir_out")";
30 #yell "DEBUG:path_out:$path_out";
31 if [[ ! -d "$path_out" ]]; then
33 yell
"NOTICE:Creating output directory:$path_out";
36 # Iterate through list
37 while read -r longid
; do
38 yell
"STATUS:Exporting $longid";
41 pubkey_ascii
="$(try gpg_get_pubkey "$longid")";
42 #yell "DEBUG:pubkey_ascii:$pubkey_ascii";
43 echo "$pubkey_ascii" > "$path_out"/"$longid".asc
45 done < <( echo "$list_longid" );
50 # Author: Steven Baltaktei Sandoval