chiark / gitweb /
svnpath: Allow substitution of 'upstream'.
[bin.git] / keyfoo
1 #! /bin/sh
2 ## keyfoo -- do something with a key, and e-mail it to its owner
3 ## (C) 2001 Gergely Nagy <algernon@debian.org>
4 ##
5 ## Released under the terms of the GNU GPL v2.
6 ##
7 ## $Id: keyfoo,v 1.6 2001/06/27 14:30:43 mhp Exp $
8 ## Last updated: <2001/06/27 16:30:27 algernon>
9 ##
10
11 ## some globals, initialized as empty
12 KF_KEY=
13 KF_ADDRESS=
14 KF_RECIPIENT=
15 KF_KEYID=
16 TEMPFILE=
17 KF_BODY=
18 KF_KEYFILE=
19 KF_KEYSERVER=keyring.debian.org
20 GPG=gpg
21 KF_MAIL_CMD='mutt -H "${KF_BODY}" -a "${KF_KEYFILE}"'
22
23
24
25 ## this one prints the usage, *wonder*
26 keyfoo_usage ()
27 {
28     cat <<EOF
29 keyfoo -- the key hacker script
30
31 Usage: keyfoo [id|email|whatever] <[address to send mail to]> [keyserver]
32 EOF
33     exit ${1:-0}
34 }
35
36 ## this one LARTs the user
37 keyfoo_not_configured ()
38 {
39     cat <<EOF
40 keyfoo -- the key hacker script
41
42 keyfoo is not configured, no command specified to send the signed key,
43 please consult the documentation
44 EOF
45
46     exit ${1:-1}
47 }
48
49 ## this one parses the output of gpg --list-key
50 keyfoo_parse_gpg ()
51 {
52     local kf_tmp
53     kf_tmp=`gpg --list-key ${KF_KEY} | head -n 1`
54     # and now a complicated regexp, I do this separately, so
55     # the line will fit into 80 chars ;]
56     KF_ADDRESS=`echo ${kf_tmp} | sed -e "s,^pub *[^ ]* *[0-9\-]* *,,"`
57     KF_KEYID=`echo ${kf_tmp} | sed -e "s,^pub *[^\/]*\/\([^ ]*\) .*,0x\1,"`
58 }
59
60 ## Here comes the main hackery-wackery
61 # first of all, check paramaters
62 if test $# -lt 1; then
63     keyfoo_usage 1
64 fi
65
66 test -e /etc/keyfoorc && . /etc/keyfoorc
67 test -e ${HOME}/.keyfoorc && . ${HOME}/.keyfoorc
68
69 ## Sanity check..
70 test -z "${KF_MAIL_CMD}" && keyfoo_not_configured
71
72 ## determine the tempfile
73 if test -x /bin/tempfile; then
74     TEMPFILE=`tempfile`
75 else
76     TEMPFILE=${TMPDIR:-/tmp}/keyfoo.$$
77 fi
78
79 KF_KEY=$1;
80 test $# -ge 2 && test x"$2" != x && KF_RECIPIENT="$2"
81 KF_RECIPIENT="${KF_RECIPIENT:-$KF_ADDRESS}"
82 test $# -ge 3 && test x"$3" != x && KF_KEYSERVER="$3"
83
84 KF_PRESIGN="gpg --keyserver ${KF_KEYSERVER} --recv-key ${KF_KEY} ; gpg --list-sigs ${KF_KEY}"
85 test -z "${KF_PRESIGN}" || eval "${KF_PRESIGN}"
86
87 keyfoo_parse_gpg
88
89 # now, we got everything we'll ever need :]
90 # time to launch gpg --edit-key
91 gpg --sign-key "${KF_KEY}"
92
93 KF_SUBJECT="Your signed GPG key (Key ID ${KF_KEYID})"
94
95 ## now mail the thing
96 # first, create a draft mail:
97 KF_BODY=${TEMPFILE}
98 cat >${KF_BODY} <<EOF
99 From: Colin Watson <cjwatson@debian.org>
100 To: ${KF_RECIPIENT}
101 Subject: ${KF_SUBJECT}
102 Fcc: =debian/keysigning
103
104 Hi,
105
106 Attached to this e-mail is your signed GPG key. I've also uploaded it to
107 the keyserver at ${KF_KEYSERVER}.
108
109 Cheers,
110 EOF
111
112 # export the key..
113 KF_KEYFILE="${TEMPFILE}.key"
114 $GPG --armor --export "${KF_KEY}" >"${KF_KEYFILE}"
115
116 # ..then launch the mailer
117 eval ${KF_MAIL_CMD}
118
119 rm -f "${KF_KEYFILE}" "${KF_BODY}"
120
121 $GPG --keyserver "${KF_KEYSERVER}" --send-key "${KF_KEY}"
122