#!/bin/sh # Installation: source this from your .bashrc # # Limitations: if $ssh_auth_sock exists and an ssh-agent is running # which doesn't use it, ssh-reclaim will be tricked into thinking # that they correspond. This will happen if the computer shuts down # uncleanly. # # Possible workarounds: # * Check the command line of ssh-agent to see if we started it # * Check for ssh sockets in /tmp owned by $USER # Colors GRAY="\x1b[0;37;01m" RED="\x1b[1;31;01m" GREEN="\x1b[1;32;01m" YELLOW="\x1b[1;33;01m" BLUE="\x1b[1;34;01m" WHITE="\x1b[1;37;01m" DEFAULT="\x1b[0m" start_agent() { eval `ssh-agent -s -a $ssh_auth_sock &` >/dev/null if [ -t 0 ]; then echo -e " ${BLUE}*${DEFAULT} New agent started (pid ${SSH_AGENT_PID})" echo fi } ssh_agent_pid=$(echo $(pgrep -u $USER ssh-agent) | cut -d' ' -f1) ssh_auth_sock=$HOME/.ssh/agent-auth-sock-`uname -n` if [ -z "$ssh_agent_pid" ]; then rm -f $ssh_auth_sock start_agent else if [ -e $ssh_auth_sock ]; then export SSH_AUTH_SOCK=$ssh_auth_sock SSH_AGENT_PID=$ssh_agent_pid else if [ -t 0 ]; then echo -e " ${YELLOW}*${DEFAULT} Killing stale agent (pid $ssh_agent_pid)" fi pkill -u $USER ssh-agent start_agent fi fi