From 899fa24894f4ec29e0b4cbea3dba154231e7aa0a Mon Sep 17 00:00:00 2001 From: David Runge Date: Sun, 13 Apr 2014 16:53:28 +0200 Subject: Adding function for gpg crypted file editing. --- bin/secret | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100755 bin/secret (limited to 'bin') diff --git a/bin/secret b/bin/secret new file mode 100755 index 0000000..27391ff --- /dev/null +++ b/bin/secret @@ -0,0 +1,41 @@ +#!/bin/bash +# +# Open and write to a gpg encrypted file +# Will create the file for you if it's not there yet +# +# secret + +writeback () { + gpg --yes -eq -r "$gpgkey" -o $1 $tmpfile + echo "Encrypted file using gpg public key: $gpgkey" + chmod 600 $1 + echo "Finished working on file: $1." + rm $tmpfile + echo "Removed temp file $tmpfile" +} + +filetotmp () { + gpg --yes -o $tmpfile -d $1 +} + +tmpfile=$(mktemp) +gpgkey="David Runge " + +# if file is available, use it, else create it +if [[ -f "$1" ]];then + filetotmp $1 + echo "File $1 now in $tmpfile ." +fi + +echo "Opening file in $EDITOR" +# edit decrypted file in /tmp +$EDITOR $tmpfile +if [[ $? -gt 0 ]];then + echo "Something went wrong with $EDITOR ." + echo "Aborting." + rm $tmpfile + echo "Deleted $tmpfile ." +else + # write back the file + writeback $1 +fi -- cgit v1.2.3-54-g00ecf