diff options
author | rhatto <rhatto@ratatosk.fluxo.info> | 2014-03-14 13:23:04 -0300 |
---|---|---|
committer | rhatto <rhatto@ratatosk.fluxo.info> | 2014-03-14 13:23:04 -0300 |
commit | 927a8392b30b2329b60f181fb0a67bd450f6df4e (patch) | |
tree | 1f2f33cb3c03612957763ac6b7d7482d3781d8ec | |
parent | 86835f829aacd8466e1fbc908b77de75d722423d (diff) | |
download | keyringer-927a8392b30b2329b60f181fb0a67bd450f6df4e.tar.gz keyringer-927a8392b30b2329b60f181fb0a67bd450f6df4e.tar.bz2 |
Try to get an initial recipient (#32)
-rwxr-xr-x | lib/keyringer/functions | 31 |
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 } |