2 ## keyfoo -- do something with a key, and e-mail it to its owner
3 ## (C) 2001 Gergely Nagy <algernon@debian.org>
5 ## Released under the terms of the GNU GPL v2.
7 ## $Id: keyfoo,v 1.6 2001/06/27 14:30:43 mhp Exp $
8 ## Last updated: <2001/06/27 16:30:27 algernon>
11 ## some globals, initialized as empty
19 KF_KEYSERVER=keyring.debian.org
21 KF_MAIL_CMD='mutt -H "${KF_BODY}" -a "${KF_KEYFILE}"'
25 ## this one prints the usage, *wonder*
29 keyfoo -- the key hacker script
31 Usage: keyfoo [id|email|whatever] <[address to send mail to]> [keyserver]
36 ## this one LARTs the user
37 keyfoo_not_configured ()
40 keyfoo -- the key hacker script
42 keyfoo is not configured, no command specified to send the signed key,
43 please consult the documentation
49 ## this one parses the output of gpg --list-key
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,"`
60 ## Here comes the main hackery-wackery
61 # first of all, check paramaters
62 if test $# -lt 1; then
66 test -e /etc/keyfoorc && . /etc/keyfoorc
67 test -e ${HOME}/.keyfoorc && . ${HOME}/.keyfoorc
70 test -z "${KF_MAIL_CMD}" && keyfoo_not_configured
72 ## determine the tempfile
73 if test -x /bin/tempfile; then
76 TEMPFILE=${TMPDIR:-/tmp}/keyfoo.$$
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"
84 KF_PRESIGN="gpg --keyserver ${KF_KEYSERVER} --recv-key ${KF_KEY} ; gpg --list-sigs ${KF_KEY}"
85 test -z "${KF_PRESIGN}" || eval "${KF_PRESIGN}"
89 # now, we got everything we'll ever need :]
90 # time to launch gpg --edit-key
91 gpg --sign-key "${KF_KEY}"
93 KF_SUBJECT="Your signed GPG key (Key ID ${KF_KEYID})"
96 # first, create a draft mail:
99 From: Colin Watson <cjwatson@debian.org>
101 Subject: ${KF_SUBJECT}
102 Fcc: =debian/keysigning
106 Attached to this e-mail is your signed GPG key. I've also uploaded it to
107 the keyserver at ${KF_KEYSERVER}.
113 KF_KEYFILE="${TEMPFILE}.key"
114 $GPG --armor --export "${KF_KEY}" >"${KF_KEYFILE}"
116 # ..then launch the mailer
119 rm -f "${KF_KEYFILE}" "${KF_BODY}"
121 $GPG --keyserver "${KF_KEYSERVER}" --send-key "${KF_KEY}"