# $Id$
+
+SOCKET=~/.ssh/agent
+
if [ ! -z "$SSH_CLIENT" ]; then
# Set display if we aren't already forwarding X11
if [ "$DISPLAY" = "" ]; then
# 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