Added gpvi.
authorFredrik Tolf <fredrik@dolda2000.com>
Fri, 12 Oct 2018 16:11:37 +0000 (18:11 +0200)
committerFredrik Tolf <fredrik@dolda2000.com>
Fri, 12 Oct 2018 16:11:37 +0000 (18:11 +0200)
gpvi [new file with mode: 0644]

diff --git a/gpvi b/gpvi
new file mode 100644 (file)
index 0000000..481b1f2
--- /dev/null
+++ b/gpvi
@@ -0,0 +1,28 @@
+#!/bin/sh
+
+set -e
+
+if [ $# -lt 1 ]; then
+    echo "usage: gpvi FILENAME" >&2
+    exit 1
+fi
+
+file="$1"; shift
+
+rcpt="$(gpg --batch --quiet --decrypt --list-only --status-fd 1 <"$file" | sed -n '/^\[GNUPG:\]/s/^.*ENC_TO \([^ ]*\) .*$/-r \1/p')"
+tf="$(mktemp /tmp/gpvi.XXXXXX)"
+
+gpg --quiet --decrypt --armor <"$file" >"$tf"
+omd5="$(md5sum "$tf")"
+vi -n "$tf"
+nmd5="$(md5sum "$tf")"
+if [ "$omd5" != "$nmd5" ]; then
+    gpg --quiet --encrypt --armor $rcpt <"$tf" >"${file}.new"
+    rm -f "$file~"
+    ln "$file" "$file~"
+    mv "${file}.new" "$file"
+else
+    echo "gpvi: file left unchanged, not overwriting old" >&2
+fi
+
+shred -u "$tf"