]> gitweb.fluxo.info Git - keyringer.git/commitdiff
Try to get an initial recipient (#32)
authorrhatto <rhatto@ratatosk.fluxo.info>
Fri, 14 Mar 2014 16:23:04 +0000 (13:23 -0300)
committerrhatto <rhatto@ratatosk.fluxo.info>
Fri, 14 Mar 2014 16:23:04 +0000 (13:23 -0300)
lib/keyringer/functions

index ca7f411cf88756efbe72f78d10aa87e6e7027fc0..0b084af268c28b5da9164c236d2f872505d173a1 100755 (executable)
@@ -772,10 +772,35 @@ function keyringer_set_new_recipients {
 
 # Create a new recipients file
 function keyringer_create_new_recipients {
-  if [ ! -e "$1" ]; then
-    mkdir -p "`dirname $1`"
+  local recipients="$1"
+  local recipient
+  local key
+  local uid
+  local fpr
+
+  if [ ! -e "$recipients" ]; then
+    mkdir -p "`dirname $recipients`"
     echo "# Use entries in the form of 'john@doe.com XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'" > "$1"
-    echo "" >> "$1"
+    echo "" >> "$recipients"
+
+    # Try to get an initial recipient
+    if [ -e "$HOME/.gnupg/gpg.conf" ]; then
+      recipient="`grep -e "^default-key" ~/.gnupg/gpg.conf | cut -d ' ' -f 2`"
+
+      if [ ! -z "$recipient" ]; then
+        key="`gpg --fingerprint --with-colons $recipient 2> /dev/null`"
+
+        if [ "$?" == "0" ]; then
+          fpr="`echo "$key" | grep -e '^fpr:' | head -1 | cut -d : -f 10`"
+          uid="`echo "$key" | grep -e '^uid:' | head -1 | cut -d : -f 10 | sed -e 's|^[^<]*<||' -e 's|>$||'`"
+
+          if [ ! -z "$uid" ] && [ ! -z "$fpr" ]; then
+            echo "Default key $fpr ($uid) found at ~/.gnupg/gpg.conf, using as initial recipient."
+            echo "$uid $fpr" >> "$recipients"
+          fi
+        fi
+      fi
+    fi
   fi
 }