ga-rdiff: create_rdiff(): Quote variable definitions for `src` and `dest`
[sunny256-utils.git] / git-add-missing-gpg-keys
blob287feb7653cc9e30ae57f4d91d759785e7807429
1 #!/usr/bin/env bash
3 #=======================================================================
4 # git-add-missing-gpg-keys
5 # File ID: e53738b0-9caa-11e3-a01a-001f3b596ec9
7 # Add missing GPG keys used for signed Git tags and commits.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
13 progname=git-add-missing-gpg-keys
14 VERSION=0.1.0
16 ARGS="$(getopt -o "\
20 " -l "\
21 help,\
22 quiet,\
23 verbose,\
24 version,\
25 " -n "$progname" -- "$@")"
26 test "$?" = "0" || exit 1
27 eval set -- "$ARGS"
29 opt_help=0
30 opt_quiet=0
31 opt_verbose=0
32 while :; do
33 case "$1" in
34 -h|--help) opt_help=1; shift ;;
35 -q|--quiet) opt_quiet=$(($opt_quiet + 1)); shift ;;
36 -v|--verbose) opt_verbose=$(($opt_verbose + 1)); shift ;;
37 --version) echo $progname $VERSION; exit 0 ;;
38 --) shift; break ;;
39 *) echo $progname: Internal error >&2; exit 1 ;;
40 esac
41 done
42 opt_verbose=$(($opt_verbose - $opt_quiet))
44 if test "$opt_help" = "1"; then
45 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
46 cat <<END
48 Add missing GPG keys used for signed Git tags and commits.
50 Usage: $progname [options]
52 Options:
54 -h, --help
55 Show this help.
56 -q, --quiet
57 Be more quiet. Can be repeated to increase silence.
58 -v, --verbose
59 Increase level of verbosity. Can be repeated.
60 --version
61 Print version information.
63 END
64 exit 0
67 LC_ALL=C git log --show-signature "$@" | \
68 grep "^gpg: Can't check signature: public key not found" -B1 | \
69 grep "key ID" | \
70 rev | cut -f 1 -d ' ' | rev | \
71 sort -u | \
72 while read f; do
74 cd ~/.gnupg || { echo $progname: ~/.gnupg: Cannot chdir >&2; exit 1; }
75 gpg --recv-keys $f
76 shopt -s nullglob
77 files_gone=0
78 until test "$files_gone" = "1"; do
79 array=('.#lk'*)
80 if (( ${#array[@]} > 0 )); then
81 echo $progname: Waiting for tmpfiles to disappear...
82 sleep 1
83 else
84 files_gone=1
86 done
87 ciall -y "gpg --recv-keys $f"
89 done