# $Id: bashrc,v 1.1 2005/02/28 06:46:50 joostvb Exp $ # $Source: /var/cvs/ad1810.com/packages/ad1810-ssh/contrib/bashrc,v $ # Author: Rudi Sluijtman, 2001 # License: GPL # possible situations: # we have no socket, but an agent exist # we have no socket, no agent exist # we have a socket, no identity # we have a socket, identity have_identity=0 have_socket=0 have_agent=0 # see if there is an ssh-agent running if ps x -o comm | grep -q ssh-agent then have_agent=true else have_agent=false fi if [ $have_agent == false ] then eval `ssh-agent` have_socket=1 fi # have_agent is true by now if [ "$have_socket" = 0 ] then # see if there is an existing socket for dir in /tmp/ssh-* do [ ! -d $dir -o ! -w $dir ] && continue for sock in $dir/* do if [ -w $sock -a -S $sock ] then SSH_AUTH_SOCK=$sock ssh-add -l >/dev/null 2>/dev/null res=$? case $res in 0) SSH_AUTH_SOCK=$sock have_identity=1 break 2 ;; 1) SSH_AUTH_SOCK=$sock break 2 ;; *) # get rid of old sockets rm -f $sock ;; esac fi done # if we get here there was no valid socket in $dir rm -fr $dir done fi # now the dentity export SSH_AUTH_SOCK if [ $have_identity -eq 0 ] then if [ -n "$DISPLAY" ] then xterm -geometry 80x25+300+150 -e ssh-add else ssh-add fi fi