Debian Codegraph @

jetring-explode

raw
1 #!/bin/sh
2 # Converts a keyring into a bunch of changesets, one per key.
3 # Only intended to be used for initial import of keyring.
4 set -e
5
6 if [ -z "$1" ] || [ -z "$2" ]; then
7 echo "Usage: keyring-expode keyring changesetdir" >&2
8 exit 1
9 fi
10
11 # avoid gnupg touching ~/.gnupg
12 GNUPGHOME=$(mktemp -d -t jetring.XXXXXXXX)
13 export GNUPGHOME
14 trap cleanup exit
15 cleanup () {
16 rm -rf "$GNUPGHOME"
17 }
18
19 keyring=$(readlink -f "$1") # gpg works better with absolute keyring paths
20 changesetdir="$2"
21
22 basename=$(basename "$keyring")
23 date=`date -R`
24
25 if [ -n "$JETRING_SIGN" ] && [ -e "$changesetdir/index" ]; then
26 JETRING_SIGN=$(readlink -f "$JETRING_SIGN")
27 gpg --no-auto-check-trustdb --options /dev/null \
28 --no-default-keyring --keyring "$JETRING_SIGN" \
29 --verify "$changesetdir/index.gpg" "$changesetdir/index"
30 fi
31
32 mkdir -p "$changesetdir"
33 touch "$changesetdir/index"
34
35 # select the first fingerprint reported after each primary public key
36 for key in $(gpg --fixed-list-mode --with-colons --with-fingerprint --no-auto-check-trustdb --options /dev/null --no-default-keyring --keyring "$keyring" --list-keys \
37 | awk -F: '/^pub:/{ ready = 1; } /^fpr:/{ if (ready) { print $10; ready = 0; } }'); do
38 out="$changesetdir/add-$key"
39 echo "$out"
40 (
41 echo "Comment: extracted from $basename by jetring-explode"
42 echo "Date: $date"
43 echo "Action: import"
44 echo "Data:"
45 gpg --no-auto-check-trustdb --options /dev/null \
46 --no-default-keyring --keyring "$keyring" \
47 -a --export "$key" |
48 sed 's/^/ /'
49 ) > "$out"
50 echo "sha256-$(sha256sum "$out" | cut -d " " -f 1) add-$key" >> "$changesetdir/index"
51 done
52
53 if [ -n "$JETRING_SIGN" ] || [ -e "$changesetdir/index.gpg" ]; then
54 jetring-signindex "$changesetdir"
55 fi