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