chiark / gitweb /
bin/start-ssh-agent: Search for agents in some more places.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 5 Nov 2016 21:28:22 +0000 (21:28 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Wed, 30 Nov 2016 12:52:52 +0000 (12:52 +0000)
bin/start-ssh-agent

index afcfc72937c11556e10273726087ee965e88be40..bfb2608f6c6e645be26c9549a6bbb53ff1a62728 100755 (executable)
@@ -31,20 +31,35 @@ esac
 
 ## Some useful variables.
 hostname=${HOST-$(hostname)}
-user=${USER-${LOGNAME-$(id -un)}}
+user=${USER-${LOGNAME-$(id -un)}} uid=${UID-$(id -u)}
 dir=$TMPDIR/.ssh-agent.$hostname.$user
 socket=$dir/sock; pid=$dir/pid
 export SSH_AUTH_SOCK
 
-### Should I start a new agent?
-case "$force,$SSH_AUTH_SOCK" in
-  t,* | nil,)
-    foundp=nil
-    ;;
-  *)
-    foundp=t
-    set +e; ssh-add -l >/dev/null 2>&1; rc=$?; set -e
-    [ $rc -ge 2 ] && foundp=nil
+## Should I start a new agent?
+foundp=nil
+case $force in
+  nil)
+    case ${SSH_AUTH_SOCK+t} in
+      t)
+       set +e; ssh-add -l >/dev/null 2>&1; rc=$?; set -e
+       if [ $rc -lt 2 ]; then foundp=t; fi
+       ;;
+    esac
+    case $foundp in
+      t) ;;
+      *)
+       for i in \
+         "$HOME/.cache/keyring-"*"/ssh" \
+         "/run/user/$uid/keyring/ssh" \
+         "$socket"
+       do
+         SSH_AUTH_SOCK=$i
+         set +e; ssh-add -l >/dev/null 2>&1; rc=$?; set -e
+         if [ $rc -lt 2 ]; then foundp=t; break; fi
+       done
+       ;;
+    esac
     ;;
 esac