aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2013-11-14 14:36:46 -0200
committerSilvio Rhatto <rhatto@riseup.net>2013-11-14 14:36:46 -0200
commit1340e329768f8f022c6d5cd91e512380d883a5ac (patch)
tree87c6cde26d85a21d66b8208e42f2bd0aed274eb1 /lib
parent8857d60617c00553aaab7f06153b17699c860e96 (diff)
downloadkeyringer-1340e329768f8f022c6d5cd91e512380d883a5ac.tar.gz
keyringer-1340e329768f8f022c6d5cd91e512380d883a5ac.tar.bz2
Set file extension for encrypted files
Diffstat (limited to 'lib')
-rwxr-xr-xlib/keyringer/actions/edit8
-rwxr-xr-xlib/keyringer/actions/encrypt17
-rwxr-xr-xlib/keyringer/functions9
3 files changed, 29 insertions, 5 deletions
diff --git a/lib/keyringer/actions/edit b/lib/keyringer/actions/edit
index 54d0fec..f6477bf 100755
--- a/lib/keyringer/actions/edit
+++ b/lib/keyringer/actions/edit
@@ -16,8 +16,13 @@ keyringer_set_recipients "$FILE"
# Warn user
echo "Make sure that $BASEDIR is atop of an encrypted volume."
+# Get original file EXTENSION
+FILENAME="$(basename "$FILE" .asc)"
+FILENAME="$(basename "$FILENAME")"
+EXTENSION="${FILENAME##*.}"
+
# Set a tmp file
-keyringer_set_tmpfile edit
+keyringer_set_tmpfile $BASENAME.$EXTENSION
# Decrypt the information to the file
$GPG --yes -o "$TMPWORK" --use-agent -d "$KEYDIR/$FILE"
@@ -26,6 +31,7 @@ if [ "$BASENAME" == "edit" ]; then
APP="$EDITOR"
elif [ "$BASENAME" == "open" ]; then
if which xdg-open &> /dev/null; then
+ # TODO: set TMPWORK depending on the MIME type (`file -i` or `xdg-mime query filetype`)
APP="xdg-open"
else
echo "You should have xdg-open application to perform this action, aborting."
diff --git a/lib/keyringer/actions/encrypt b/lib/keyringer/actions/encrypt
index d9d8f96..aadb9fa 100755
--- a/lib/keyringer/actions/encrypt
+++ b/lib/keyringer/actions/encrypt
@@ -25,10 +25,25 @@ fi
# Aditional parameters
if [ ! -z "$3" ]; then
- keyringer_get_new_file $2
+ # Set secret name and original file
+ FILE="$2"
shift 2
UNENCRYPTED_FILE="$*"
+ # Get original file EXTENSION
+ FILENAME="$(basename "$UNENCRYPTED_FILE")"
+ EXTENSION="${FILENAME##*.}"
+
+ # Append file extension in the secret name
+ #
+ # Useful when opening files and the application needs the
+ # extension to guess the file type.
+ if ! echo $FILE | grep -q -e "\.$EXTENSION$"; then
+ FILE="$FILE.$EXTENSION"
+ fi
+
+ keyringer_get_new_file $FILE
+
if [ ! -f "$UNENCRYPTED_FILE" ]; then
echo "Error: cannot encrypt $UNENCRYPTED_FILE: file not found."
exit 1
diff --git a/lib/keyringer/functions b/lib/keyringer/functions
index b39b8ec..40e13aa 100755
--- a/lib/keyringer/functions
+++ b/lib/keyringer/functions
@@ -118,13 +118,16 @@ function keyringer_set_tmpfile {
exit 1
fi
+ # Set base temp folder
+ local tmp="$BASEDIR/tmp"
+
if [ -z "$1" ]; then
- template="$BASEDIR/tmp/keyringer.XXXXXXXXXX"
+ template="$tmp/keyringer.XXXXXXXXXX"
else
- template="$BASEDIR/tmp/$1.XXXXXXXXXX"
+ template="$tmp/XXXXXXXXXX.$1"
fi
- mkdir -p "$BASEDIR/tmp"
+ mkdir -p "$tmp"
keyringer_git_ignore 'tmp/*'
if [ "$2" == "-d" ]; then