# $Id$ if [ ! -z "$SSH_CLIENT" ]; then # Set display if we aren't already forwarding X11 if [ "$DISPLAY" = "" ]; then export DISPLAY="$(echo $SSH_CLIENT | cut -s -d ' ' -f 1):0" fi 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)" 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) 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-)" fi fi unset RUNNING_AGENT fi