]> git.sthu.org Git - pgp-tools.git/blob - gpg-key2ps/gpg-key2ps
Add description
[pgp-tools.git] / gpg-key2ps / gpg-key2ps
1 #! /bin/sh
2 #
3 # gpg-key2ps: convert a PGP/GnuPG key into paper slips.
4 #
5 # $Id$
6
7 set -e
8
9 VERSION='$Rev$'
10 USAGE="Usage: $0 [-p papersize] [-r revoked-style] keyid-or-name"
11
12
13 if [ -z "$*" ]; then
14 echo $USAGE
15 exit 1
16 fi
17
18 KEYIDS=
19 REVOKESTYLE=hide
20
21 while [ -n "$1" ]; do
22 case "$1" in
23 -p)
24 PAPERSIZE=$2
25 export PAPERSIZE
26 shift 2
27 ;;
28 -p*)
29 PAPERSIZE=`echo $1 | sed -e 's/^-p//'`
30 export PAPERSIZE
31 shift 1
32 ;;
33 -r)
34 REVOKESTYLE=$2
35 shift 2
36 ;;
37 -r*)
38 REVOKESTYLE=`echo $1 | sed -e 's/^-r//'`
39 shift 1
40 ;;
41 -*)
42 echo $USAGE
43 exit 1
44 ;;
45 *)
46 KEYIDS=$1
47 shift 1
48 ;;
49 esac
50 done
51
52 case "$REVOKESTYLE" in
53 grey|hide|note|show|strike)
54 ;;
55 *)
56 echo >&2 "Unknown style \"$REVOKESTYLE\". Please use one of"
57 echo >&2 " grey - Print text in grey"
58 echo >&2 " hide - Don't show revoked uids"
59 echo >&2 " note - Add \"(revoked)\""
60 echo >&2 " show - List revoked uids normally"
61 echo >&2 " strike - Strike through lines"
62 exit 1
63 ;;
64 esac
65
66 TMPFILE=`mktemp -t gpg-key2ps.XXXXXX`
67
68 if ! gpg --fingerprint --with-colons $KEYIDS 2>/dev/null >$TMPFILE; then
69 echo >&2 "Key not found. Try 'gpg --list-keys'"
70 rm $TMPFILE
71 exit 1
72 fi
73
74 NUMLINES=$((`wc -l <$TMPFILE` + `grep '^pub:' $TMPFILE | wc -l` - 1))
75
76 if test -x /usr/bin/paperconf; then
77 w=`paperconf -w`
78 h=`paperconf -h`
79 else
80 # Default to A4.
81 w=596
82 h=842
83 fi
84
85 cat <<EOF
86 %!PS-Adobe-3.0
87 %%BoundingBox: 0 0 $w $h
88 %%Title:
89 %%Creator: gpg-key2ps $VERSION
90 EOF
91 echo "%%CreationDate: `date`"
92 cat <<EOF
93 %%Pages: 1
94 %%EndComments
95
96 %%Page: 1 1
97
98 /w $w def
99 /h $h def
100
101 /Times-Roman findfont 9 scalefont setfont
102
103 /newline {
104 /y y 10 sub def
105 } def
106
107 /hline {
108 30 y 3 add moveto
109 w 2 div 30 sub y 3 add lineto stroke
110 newline
111 } def
112
113 /needhline {
114 /condhline { hline } def
115 } def
116
117 /noneedhline {
118 /condhline { } def
119 } def
120
121 /showAlgorithm {
122 << 1 (R) 2 (r) 3 (s) 16 (g) 20 (G) 17 (D) >> exch get
123 show
124 } def
125
126 /pub {
127 condhline
128 50 y moveto (pub) show
129 70 y moveto show showAlgorithm (/) show show
130 150 y moveto show
131 200 y moveto show
132 newline
133 needhline
134 } def
135
136 /fpr {
137 70 y moveto (Key fingerprint = ) show show
138 newline
139 } def
140
141 /uid {
142 50 y moveto (uid) show
143 200 y moveto show
144 newline
145 } def
146
147 EOF
148
149 case "$REVOKESTYLE" in
150 grey)
151 echo "/revuid {"
152 echo " .5 setgray"
153 echo " uid"
154 echo " 0 setgray"
155 echo "} def"
156 ;;
157 hide)
158 echo "/revuid {} def"
159 ;;
160 note)
161 echo "/revuid {"
162 echo " 50 y moveto (uid) show"
163 echo " 200 y moveto show ([revoked]) show"
164 echo " newline"
165 echo "} def"
166 ;;
167 show)
168 echo "/revuid { uid } def"
169 ;;
170 strike)
171 echo "/revuid {"
172 echo " uid"
173 echo " 45 y 9 add moveto h 2 div 45 sub y 18 add lineto stroke"
174 echo "} def"
175 ;;
176 esac
177
178 cat <<EOF
179
180 /sbk {
181 50 y moveto (sub) show
182 70 y moveto show showAlgorithm (/) show show
183 150 y moveto show
184 newline
185 } def
186
187 /key {
188 noneedhline
189 EOF
190 sed -e '/^tru:/d' \
191 -e '/^uat:/d' \
192 -e 's/^pub:[^:]*:\([^:]*\):\([0-9]*\):.\{8,8\}\(.\{8,8\}\):\([^:]*\):[^:]*:[^:]*:[^:]*:\([^:]*\):[^:]*:[^:]*:.*/ (\5) (\4) (\3) \2 (\1) pub/' \
193 -e 's/^fpr:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\):.*/ (\1) fpr/' \
194 -e 's/(\(.\{16,16\}\)\(.\{16,16\}\)) fpr/(@split@\1@ @split@\2@) fpr/' \
195 -e 's/@split@\(.\{2,2\}\)\(.\{2,2\}\)\(.\{2,2\}\)\(.\{2,2\}\)\(.\{2,2\}\)\(.\{2,2\}\)\(.\{2,2\}\)\(.\{2,2\}\)@/\1 \2 \3 \4 \5 \6 \7 \8/g' \
196 -e 's/(\(.\{20,20\}\)\(.\{20,20\}\)) fpr/(@split@\1@ @split@\2@) fpr/' \
197 -e 's/@split@\(.\{4,4\}\)\(.\{4,4\}\)\(.\{4,4\}\)\(.\{4,4\}\)\(.\{4,4\}\)@/\1 \2 \3 \4 \5/g' \
198 -e 's/^uid:[^:r]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\):.*/ (\1) uid/' \
199 -e 's/^uid:r[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:\([^:]*\):.*/ (\1) revuid/' \
200 -e 's/^sub:[^:]*:\([^:]*\):\([0-9]*\):.\{8,8\}\(.\{8,8\}\):\([^:]*\):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:.*/ (\4) (\3) \2 (\1) sbk/' \
201 <$TMPFILE
202 cat <<EOF
203 } def
204
205 EOF
206 echo "/numlines $(($NUMLINES + 1)) def"
207 cat <<EOF
208 /num w 16 sub 10 div numlines div def
209
210 /column {
211 /y w 20 sub def
212 1 1 num {
213 gsave
214 0 0 h 2 div w rectclip
215 /upper y 11 add def
216 key
217 newline
218 /lower y 11 add def
219 0 upper h 2 div upper h 2 div lower 0 lower 0 upper moveto lineto lineto lineto lineto stroke
220 grestore
221 } for
222 } def
223
224 w 0 translate
225 90 rotate
226 column
227 h 2 div 0 translate
228 column
229
230 showpage
231
232 %%Trailer
233 %%EOF
234 EOF
235
236 rm $TMPFILE