Created
March 4, 2016 20:32
-
-
Save tianon/2ade87b4554ec793a673 to your computer and use it in GitHub Desktop.
edit GPG-encrypted files reasonably
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
usage() { | |
local s="$(basename "$0")" | |
echo "usage: $s [identity] [file]" | |
echo " ie: $s [email protected] ~/some-secret-file.asc" | |
} | |
identity="$1"; shift || { usage >&2; exit 1; } | |
filename="$1"; shift || { usage >&2; exit 1; } | |
tmp="$(mktemp)" | |
trap "( set -x; shred -zu '$tmp' )" EXIT | |
if [ -s "$filename" ]; then | |
( set -x; gpg --decrypt --output "$tmp" --yes "$filename" ) | |
fi | |
vim "$tmp" | |
( set -x; gpg --encrypt --armor --recipient "$identity" --output "$filename" --yes "$tmp" ) | |
# trap shreds $tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment