aboutsummaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2010-09-03 17:31:37 -0300
committerSilvio Rhatto <rhatto@riseup.net>2010-09-03 17:31:37 -0300
commit8075cff27d4d17d2f9d69c43f9774392b03a5560 (patch)
treea4b219b4bd6f1a87f576071b625d0e0e3449778b /share
parent3c29eaf7ffd39f82e63cba2c2bcf850f3c047fff (diff)
downloadkeyringer-8075cff27d4d17d2f9d69c43f9774392b03a5560.tar.gz
keyringer-8075cff27d4d17d2f9d69c43f9774392b03a5560.tar.bz2
Adding edit command (2)
Diffstat (limited to 'share')
-rwxr-xr-xshare/keyringer/edit48
1 files changed, 48 insertions, 0 deletions
diff --git a/share/keyringer/edit b/share/keyringer/edit
new file mode 100755
index 0000000..153e236
--- /dev/null
+++ b/share/keyringer/edit
@@ -0,0 +1,48 @@
+#!/bin/bash
+#
+# Edit keys.
+#
+
+# Load functions
+LIB="`dirname $0`/../../lib/keyringer/functions"
+source $LIB
+
+# Config
+BASEDIR="$1"
+FILE="`keyringer_filename $2`"
+KEYDIR="$BASEDIR/keys"
+RECIPIENTS="$BASEDIR/config/recipients"
+BASENAME="`basename $0`"
+
+if [ -z "$FILE" ]; then
+ echo "Usage: keyringer <keyring> `basename $0` <file>"
+ exit 1
+elif [ ! -f "$RECIPIENTS" ]; then
+ echo "No recipient config was found"
+ exit 1
+elif [ ! -f "$KEYDIR/$FILE" ]; then
+ echo "File not found: $KEYDIR/$FILE"
+ exit 1
+elif [ -z "$EDITOR" ]; then
+ echo "You have to set EDITOR env variable"
+ exit 1
+fi
+
+echo "Make sure that $BASEDIR is atop of an encrypted volume."
+
+# Set a tmp file
+TMPFILE="`keyringer_set_tmpfile edit`"
+trap "keyringer_unset_tmpfile $TMPFILE ; exit" INT TERM EXIT
+
+# Decrypt the information to the file
+gpg --yes -o $TMPFILE --use-agent -d $KEYDIR/$FILE
+
+echo "Press any key to open the decrypted data into $EDITOR, Ctrl-C to abort"
+read key
+$EDITOR $TMPFILE
+
+# Encrypt again
+gpg --yes -o $KEYDIR/$FILE --use-agent --armor -e -s $(keyringer_recipients $RECIPIENTS) $TMPFILE
+
+# Remove temp file
+keyringer_unset_tmpfile $TMPFILE