Sometimes we can't use lsof to get ssh-agent PID, so specify it ourselves.
authorIain Patterson <me@iain.cx>
Wed, 26 Jul 2006 09:28:15 +0000 (09:28 +0000)
committerIain Patterson <me@iain.cx>
Wed, 26 Jul 2006 09:28:15 +0000 (09:28 +0000)
git-svn-id: https://svn.cambridge.iain.cx/profile/trunk@29 6be0d1a5-5cfe-0310-89b6-964be062b18b

.profile.d/ssh.bashrc

index b82a987..4674bfc 100644 (file)
@@ -1,4 +1,7 @@
 # $Id$
+
+SOCKET=~/.ssh/agent
+
 if [ ! -z "$SSH_CLIENT" ]; then
   # Set display if we aren't already forwarding X11
   if [ "$DISPLAY" = "" ]; then
@@ -8,19 +11,22 @@ fi
 
 # Try to hook up with already running ssh-agent.
 if [ $UID -gt 0 ]; then
-  RUNNING_AGENT="$(ps waux | grep -- ^$USER\ .\*ssh-agent\ -s | grep -v grep | awk '{ print $2 }' | head -n 1)"
+  # Not all OSes support ``ps -wu''.
+  RUNNING_AGENT="$(ps waux | grep -- ^$USER\ .\*ssh-agent\ -a\ .\*\ -s | grep -v grep | awk '{ print $2 }' | head -n 1)"
   if [ -z "$SSH_AGENT_PID" -o ! "$SSH_AGENT_PID" = "$RUNNING_AGENT" ]; then
     export SSH_AGENT_PID="$RUNNING_AGENT"
     if [ "$SSH_AGENT_PID" = "" ]; then
       unset SSH_AGENT_PID
       unset SSH_AUTH_SOCK
       # Start ssh-agent up then.
-      eval $(/usr/bin/ssh-agent -s)
+      eval $(/usr/bin/ssh-agent -a "$SOCKET" -s)
       trap "kill $SSH_AGENT_PID" 0
       ssh-add
     else
-      export SSH_AUTH_SOCK="/$(lsof -p $SSH_AGENT_PID | grep 'agent.[0-9]*$' | cut -s -d / -f 2-)"
+      export SSH_AUTH_SOCK="$SOCKET"
     fi
   fi
   unset RUNNING_AGENT
 fi
+
+unset SOCKET