Commit | Line | Data |
---|---|---|
e076cc18 FT |
1 | #!/bin/sh |
2 | ||
3 | set -e | |
4 | ||
5 | if [ $# -lt 1 ]; then | |
6 | echo "usage: gpvi FILENAME" >&2 | |
7 | exit 1 | |
8 | fi | |
9 | ||
10 | file="$1"; shift | |
11 | ||
12 | rcpt="$(gpg --batch --quiet --decrypt --list-only --status-fd 1 <"$file" | sed -n '/^\[GNUPG:\]/s/^.*ENC_TO \([^ ]*\) .*$/-r \1/p')" | |
13 | tf="$(mktemp /tmp/gpvi.XXXXXX)" | |
14 | ||
15 | gpg --quiet --decrypt --armor <"$file" >"$tf" | |
16 | omd5="$(md5sum "$tf")" | |
17 | vi -n "$tf" | |
18 | nmd5="$(md5sum "$tf")" | |
19 | if [ "$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" | |
24 | else | |
25 | echo "gpvi: file left unchanged, not overwriting old" >&2 | |
26 | fi | |
27 | ||
28 | shred -u "$tf" |