summaryrefslogtreecommitdiff
path: root/multi-send-key
blob: 0dad01c4b0df01f35bc649d99027860ff45d9a57 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#!/bin/bash
#
# multi-send-key - Send signed PGP/GPG keys to multiple keyservers
#
# Copyright (C) 2004-2006, Tobias Klauser <tklauser@distanz.ch>
# This file is licensed under the GNU General Public License v2

REV='1.18'

gpg_bin=`which gpg`

SCRIPT=`basename $0`
KEYS=""
KEYSERVERS="
	$KEYSERVERS
	subkeys.pgp.net"
#	pgp.uni-mainz.de
#	sks.keyserver.penguin.de
#	wwwkeys.ch.pgp.net
#	keyserver.kjsl.com

version() {
	cat >&2 <<EOF
$SCRIPT $REV
Copyright (C) 2004-2006 Tobias Klauser <tklauser@distanz.ch>
Licensed under the GNU General Public License.
EOF
	exit 1
}

usage() {
	# XXX -f not implemented
	cat >&2 <<EOF
Usage: $SCRIPT [options...] [-f keyring] [keyids...]
Options:
	-f Send the keys contained in the specified keyring file
	-o Send own key (specified in the \$MYKEY envvar)
	-h Print this message and exit
	-v Print version and exit

This script sends all GPG public keys specified via the command line to the
keyservers specified in the \$KEYSERVERS envvar.
EOF
	exit 1
}

eval set -- `getopt -n $SCRIPT "f:ovh" "$@"` || usage
for opt; do
        case "$opt" in
                -f)     shift; keyring="$1"; shift;; # XXX
                -o) 	shift; KEYS="$MYKEY";;
                -h)     shift; usage;;
                -v)     shift; version;;
                --)     shift; break;;
        esac
done

if [ -z "$KEYS" ] && [ -z "$@" ] ; then
    echo "* Please specify at least one key identifier or use -o to send \$MYKEY."
    echo
    usage
    exit 5;
fi

KEYS="$KEYS $@"

$gpg_bin --list-keys $KEYS &> /dev/null

if [ $? -eq 0 ] ; then
	for server in $KEYSERVERS ; do
		for key in $KEYS ; do
			echo "* Sending key [$key] to server [$server]"
		        $gpg_bin --keyserver $server --send-key $key &> /dev/null
			if [ "$?" -gt 0 ]; then
				echo "* An error happened while sending the key to [$server]."
			fi
		done
	done
else
	echo "* Keys [$KEYS] not found in GPG default keyring."
	exit 5;
fi

exit 0;