]> git.sthu.org Git - pgp-tools.git/blob - gpg-mailkeys/gpg-mailkeys
Checked for policy 3.8.1, no changes necessary.
[pgp-tools.git] / gpg-mailkeys / gpg-mailkeys
1 #! /bin/sh
2 #
3 # gpg-mailkeys: mail out just signed keys to their owners
4 #
5 # $Id$
6
7 set -e
8
9 VERSION='$Rev$'
10
11 if [ -z "$*" ]; then
12 printf "Send people their newly signed GPG key by mail.\n"
13 printf "Usage: $0 keyid ...\n"
14 exit 1
15 fi
16
17 if [ -e ~/.gpg-mailkeysrc ] ; then
18 . ~/.gpg-mailkeysrc
19 fi
20 if [ -n "$EMAIL" ]; then
21 FROM="$EMAIL"
22 fi
23 if [ -z "$SUBJECT" ]; then
24 SUBJECT="Your signed GPG key"
25 fi
26 if [ -z "$NAME" ]; then
27 NAME=`getent passwd $USER | cut -d: -f5 | cut -d, -f1`
28 fi
29 if [ -z "$TEXT" ]; then
30 TEXT="Hi,
31
32 Here is your signed GPG key.
33
34 Enjoy,
35 $NAME"
36 fi
37
38 FAILKEYS=
39
40 while [ -n "$1" ]; do
41 printf "[$1] "
42 TEMPFILE=`mktemp -t gpg2mail.XXXXXX`
43 ADDR=`gpg --with-colons --fixed-list-mode --list-key $1 | sed -e 's/^uid:[^re][^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:<]*<[^:>]*>\):.*/@@uid@@ \1/' -e '/^@@uid@@ /!d' -e 's/([^)]*)//g' -e 's/ */ /g' -e 's/^@@uid@@ //' | head -1`
44 if [ -z "$ADDR" ]; then
45 printf "(no usable user ids)\n"
46 FAILKEYS="$FAILKEYS:$1"
47 shift 1
48 continue
49 fi
50 NANOTIME=`date +%s-%N`
51 BOUNDARY="ksp-$$-boundary-$NANOTIME"
52
53 printf "$ADDR:"
54 if [ $FROM ]; then
55 printf >$TEMPFILE "From: $NAME <$FROM>\n"
56 fi
57 cat << EOM >> $TEMPFILE
58 To: $ADDR
59 Subject: $SUBJECT
60 User-Agent: gpg-mailkeys/$VERSION
61 MIME-Version: 1.0
62 Content-Type: multipart/mixed; micalg=pgp-sha1;
63 boundary="$BOUNDARY"
64 Content-Disposition: inline
65
66
67
68 --$BOUNDARY
69 Content-Type: text/plain; charset=us-ascii
70 Content-Disposition: inline
71 Content-Transfer-Encoding: quoted-printable
72
73
74 $TEXT
75
76 EOM
77
78 if [ -f ~/.signature ];
79 then printf -- "--=20\n" >> $TEMPFILE
80 cat ~/.signature >> $TEMPFILE
81 fi
82
83 cat << EOM >> $TEMPFILE
84
85 --$BOUNDARY
86 Content-Type: application/pgp-keys
87 Content-Disposition: attachment; filename="$1.asc"
88
89 `gpg --armor --export $1`
90
91 --$BOUNDARY--
92 EOM
93 printf " sending"
94 /usr/sbin/sendmail -ti <$TEMPFILE
95 rm $TEMPFILE
96 printf " done.\n"
97 shift 1
98 done
99
100 if [ -n "$FAILKEYS" ]; then
101 printf "\nNote: The following keys could not be sent:\n"
102 printf "$FAILKEYS\n" | tr ':' '\n' | sed -e '/^ *$/d' -e 's/^/ /'
103 fi