alphabetize the options
[monkeysphere.git] / src / seckey2sshagent
index ecfd7aa6ebdeee0bb64dfacdb92a213549a00524..4b765dc1aae94f16eb42b2654935a751bee98a1e 100755 (executable)
@@ -26,10 +26,6 @@ explanation() {
     echo -n "The basic strategy of seckey2sshagent is to dump your
 OpenPGP authentication key(s) into your agent.
 
-The first argument to the command should be your gpg key id (the 8 
-character hex string; try gpg --list-key your@emailaddress.org to 
-lookup your key id).
-
 This script is a gross hack at the moment.  It is done by creating a
 new, temporary private keyring, letting the user remove the
 passphrases from the keys, and then exporting them.  The temporary
@@ -61,7 +57,7 @@ You can check on it with:
 
 # if no hex string is supplied, just print an explanation.
 # this covers seckey2sshagent --help, --usage, -h, etc...
-if [ -z "$1" ] || [  "$(echo "$1" | tr -d '0-9a-fA-F')" ]; then
+if [  "$(echo "$1" | tr -d '0-9a-fA-F')" ]; then
     explanation
     exit
 fi
@@ -71,8 +67,13 @@ trap cleanup EXIT
 GPGIDS="$1"
 
 if [ -z "$GPGIDS" ]; then
+    # hack: we need to get the list of secret keys, because if you
+    # --list-secret-keys with no arguments, GPG fails to print the
+    # capability flags (i've just filed this as
+    # https://bugs.g10code.com/gnupg/issue945)
+    KEYIDS=$(gpg2 --with-colons --list-secret-keys | grep ^sec | cut -f5 -d:)
     # default to using all fingerprints of authentication-enabled keys 
-    GPGIDS=$(gpg  --with-colons --fingerprint --fingerprint --list-secret-keys "$GPGID" | egrep -A1 '^(ssb|sec):.*:[^:]*a[^:]*:$' | grep ^fpr: | cut -d: -f10)
+    GPGIDS=$(gpg  --with-colons --fingerprint --fingerprint --list-secret-keys $KEYIDS | egrep -A1 '^(ssb|sec):.*:[^:]*a[^:]*:$' | grep ^fpr: | cut -d: -f10)
 fi
 
 for GPGID in $GPGIDS; do