From fd8b9b1cd22c2828f9da5443b35582d384a65d01 Mon Sep 17 00:00:00 2001 From: Shokara Date: Sat, 12 Jun 2021 12:52:40 -0400 Subject: fix edit command and encrypt the file File wasn't encrypted before and was stored in plaintext under a gpg extension --- angou | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/angou b/angou index f5e1f2a..b7427ba 100755 --- a/angou +++ b/angou @@ -10,6 +10,9 @@ ANGOU_LIST=${ANGOU_LIST:-"tree"} mkdir -p "$ANGOU_DIR" cd "$ANGOU_DIR" || exit +[ ! -f ".gpg-id" ] && echo "please put your gpg key id into \$ANGOU_DIR/.gpg-id" +GPG_ID="$(cat .gpg-id)" + # decrypt and print a password from ANGOU_DIR or print the directory structure view() { if [ -f "${1%%.gpg}" ]; then @@ -36,12 +39,15 @@ edit() { tmpfile="$(mktemp)" # edit a copy of a password if it already exists - [ -f "${1%%.gpg}".gpg ] && cp "$1" "$tmpfile" + [ -f "${1%%.gpg}".gpg ] && gpg -qd "${1%%.gpg}".gpg > "$tmpfile" "${VISUAL:-${EDITOR:-ed}}" "$tmpfile" mkdir -p "$(dirname "$1")" - mv "$tmpfile" "${1%%.gpg}".gpg + gpg -er "$GPG_ID" "$tmpfile" + + rm "$tmpfile" + mv "$tmpfile.gpg" "${1%%.gpg}".gpg } # print usage -- cgit v1.2.3