-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmsign
executable file
·75 lines (64 loc) · 1.32 KB
/
msign
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/ksh
# msign $msg
# mencrypt $msg
# Produce signed/encrypted message on stdout
# Meant to be invoked from mcom(1), a part of mblaze
MBLAZE=${MBLAZE-$HOME/.mblaze}
cfglook () {
mhdr -h $* | envsubst
}
cmd=$(cfglook EncryptCmd "$MBLAZE/profile")
[ -z "${cmd}" ] && cmd=${MENCRYPT_CMD-gpg}
[ $# -eq 0 ] && {
echo usage: $(basename $0) msgfile
exit 1
}
warn () {
echo "$*" 1>&2
}
f=$1
tmp=$(dirname $(dirname $f))/tmp/$(basename $f)
cat $f | \
perl -lpe 'if ($_ =~ /^--text follows this line--$/) { print "\n" }' > $tmp
mv $tmp $f
recipients () {
typeset f recips
f=$1
shift
recips=""
recips=$(mhdr -h to:cc:bcc $f | while read recip; do
echo " -r '${recip}'"
done)
echo ${recips}
}
opts=
dash_r=$(recipients $f)
#warn "dash_r=${dash_r}"
case "$0" in
*msign*)
opts="--sign --clearsign --armor"
;;
*mencrypt*)
opts="--encrypt --armor"
;;
*)
echo $0: 'what?'
exit 1
;;
esac
head_tmp=${f}.htmp
mshow -q -H $f > ${head_tmp}
echo '' >> ${head_tmp}
hdr_lines=$(cat ${head_tmp} | wc -l)
body_tmp=${f}.btmp
mshow -r -H $f | sed -e "1,${hdr_lines}d" > ${body_tmp}
mshow -q $f 1>&2
warn "=============================="
warn "${cmd} ${opts} ${dash_r} ${f}.btmp"
eval "${cmd} ${opts} ${dash_r} ${f}.btmp" || {
warn "${cmd} ${opts} failed"
exit 1
}
cat ${head_tmp} ${f}.btmp.asc
rm -f ${f}.btmp.asc ${f}.[hb]tmp
exit 0