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