summaryrefslogtreecommitdiff
path: root/get-signers
blob: fc13c54436474d0d76b1eaabaa70462b7d9de424 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/bash

usage()
{
cat << EOF
Usage: $0 [-d <depth>] <keyid> [ <keyid> .. ]
EOF
}

depth="1"
while getopts "hd:" OPTION
do
    case $OPTION in
        h)
            usage
            exit
            ;;
        d)
            depth="$OPTARG"
            ;;
        *)
            usage >&2
            exit 1
            ;;
    esac
done
shift $(($OPTIND - 1))

if [ "$#" -eq 0 ]; then
  usage >&2
  exit 1
fi

tmpdir=`mktemp -d`
trap "rm -rf '$tmpdir'" EXIT

keys="$*"
gpg --recv-keys $keys
while [ "$depth" -gt 0 ]; do
  keys=$(gpg --with-colons --fast-list-mode --list-sigs $keys | awk -F ':' '$1 ~ /sig|rev/ {print $5}' | sort -u)
  recv=""
  for k in $keys; do
    if ! [ -e "$tmpdir/$k" ]; then
      recv="$recv $k"
      touch "$tmpdir/$k"
    fi
  done
  if [ -z "$recv" ] ; then
    break
  fi

  gpg --recv-keys $recv

  depth=$((depth - 1))
done