acmecert: Added certificate expiry check command.
[utils.git] / gpvi
... / ...
CommitLineData
1#!/bin/sh
2
3set -e
4
5if [ $# -lt 1 ]; then
6 echo "usage: gpvi FILENAME" >&2
7 exit 1
8fi
9
10file="$1"; shift
11
12rcpt="$(gpg --batch --quiet --decrypt --list-only --status-fd 1 <"$file" | sed -n '/^\[GNUPG:\]/s/^.*ENC_TO \([^ ]*\) .*$/-r \1/p')"
13tf="$(mktemp /tmp/gpvi.XXXXXX)"
14
15gpg --quiet --decrypt --armor <"$file" >"$tf"
16omd5="$(md5sum "$tf")"
17vi -n "$tf"
18nmd5="$(md5sum "$tf")"
19if [ "$omd5" != "$nmd5" ]; then
20 gpg --quiet --encrypt --armor $rcpt <"$tf" >"${file}.new"
21 rm -f "$file~"
22 ln "$file" "$file~"
23 mv "${file}.new" "$file"
24else
25 echo "gpvi: file left unchanged, not overwriting old" >&2
26fi
27
28shred -u "$tf"