aboutsummaryrefslogtreecommitdiff
path: root/share/keyringer/edit
blob: dff42e605882d1b0898ea7af1ed5c7fe7bd1132b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/bin/bash
#
# Edit keys.
#

# Load functions
LIB="`dirname $0`/../../lib/keyringer/functions"
source $LIB
keyringer_set_env $*

# Aditional parameters
FILE="`keyringer_filename $2`"

if [ -z "$FILE" ]; then
  echo "Usage: keyringer <keyring> `basename $0` <file>"
  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