]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Set file extension for encrypted files
authorSilvio Rhatto <rhatto@riseup.net>
Thu, 14 Nov 2013 16:36:46 +0000 (14:36 -0200)
committerSilvio Rhatto <rhatto@riseup.net>
Thu, 14 Nov 2013 16:36:46 +0000 (14:36 -0200)
lib/keyringer/actions/edit
lib/keyringer/actions/encrypt
lib/keyringer/functions

index 54d0fecc0692e894682c7ecfac0ce4cbf042f0bb..f6477bfa0fabd8fc5c55edcd91af59e1a328bbab 100755 (executable)
@@ -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."
index d9d8f968f22ad5e94e1a81a770b2811dccfd05d3..aadb9fa94e6464b112fd3b194218b531570aec56 100755 (executable)
@@ -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
index b39b8ec157bdaa8b89b5f257451cd790980a7ae9..40e13aa5c502c70f1e1b409c6854ef5c010499bb 100755 (executable)
@@ -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