From: Fredrik Tolf Date: Fri, 12 Oct 2018 16:11:37 +0000 (+0200) Subject: Added gpvi. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=e076cc186737e0ce09a1d38ce8bd30cddf1330b9;p=utils.git Added gpvi. --- diff --git a/gpvi b/gpvi new file mode 100644 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"