X-Git-Url: http://git.iain.cx/?p=profile.git;a=blobdiff_plain;f=.profile.d%2Fssh.bashrc;h=65d117d00d7b714c482d50be688634b69b7b886b;hp=9aac92cf30028280582ed5e75019ca46274685b2;hb=HEAD;hpb=7ff1edff9e3b22a1fd1f7798a634538d7ed94c54 diff --git a/.profile.d/ssh.bashrc b/.profile.d/ssh.bashrc index 9aac92c..65d117d 100644 --- a/.profile.d/ssh.bashrc +++ b/.profile.d/ssh.bashrc @@ -1,25 +1,17 @@ -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-)" + # Hack to prevent confusion between two agents when launched from xdm. + if [ ! $SHLVL = 1 -o -z "$DESKTOP_SESSION" ]; then + # Read a list of hosts which can run an agent from ~/.ssh/agenthosts. + if [ -f ~/.ssh/agenthosts ]; then + while read allowed; do + if [ "${HOSTNAME%%.*}" = "$allowed" ]; then + eval $(keychain -q --timeout 7200 --agents ssh --eval) + if [ -t 0 ]; then + ssh-add -l >/dev/null || ssh-add + fi + fi + done < ~/.ssh/agenthosts + unset allowed fi fi - unset RUNNING_AGENT fi