aboutsummaryrefslogtreecommitdiff
path: root/lib/keyringer/functions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/keyringer/functions')
-rwxr-xr-xlib/keyringer/functions31
1 files changed, 28 insertions, 3 deletions
diff --git a/lib/keyringer/functions b/lib/keyringer/functions
index ca7f411..0b084af 100755
--- a/lib/keyringer/functions
+++ b/lib/keyringer/functions
@@ -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
}