add trap to remove temp dir in list_primary_fingerprints function
[monkeysphere.git] / src / share / common
index 28da3c09925fc7ccb7487a05c7c5c0e8280fa456..914fffa5e9536d69365deab301aba75899812b71 100644 (file)
@@ -530,6 +530,15 @@ gpg2authorized_keys() {
 
 ### GPG UTILITIES
 
+# script to determine if gpg version is equal to or greater than specified version
+is_gpg_version_greater_equal() {
+    local gpgVersion=$(gpg --version | head -1 | awk '{ print $3 }')
+    local latest=$(printf '%s\n%s\n' "$1" "$gpgVersion" \
+       | tr '.' ' ' | sort -g -k1 -k2 -k3 \
+       | tail -1 | tr ' ' '.')
+    [[ "$gpgVersion" == "$latest" ]]
+}
+
 # retrieve all keys with given user id from keyserver
 # FIXME: need to figure out how to retrieve all matching keys
 # (not just first N (5 in this case))
@@ -753,7 +762,7 @@ process_user_id() {
 }
 
 # output all valid keys for specified user ID literal
-keys_from_userid() {
+keys_for_userid() {
     local userID
     local noKey=
     local nKeys
@@ -1168,9 +1177,11 @@ process_authorized_user_ids() {
 # fingerprints, one per line:
 list_primary_fingerprints() {
     local fake=$(msmktempdir)
+    trap "rm -rf $fake" EXIT
     GNUPGHOME="$fake" gpg --no-tty --quiet --import
     GNUPGHOME="$fake" gpg --with-colons --fingerprint --list-keys | \
        awk -F: '/^fpr:/{ print $10 }'
+    trap - EXIT
     rm -rf "$fake"
 }