From 6b798eb0d7eab1e7ceb587d942a8b3cd5e9dbc8c Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Sun, 8 Feb 2009 12:38:27 +0100 Subject: added fixssh again to create symlink to latest connected agent-socket --- bashrc/common/ssh-agent-forwarding.sh | 38 ++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 10 deletions(-) (limited to 'bashrc/common') diff --git a/bashrc/common/ssh-agent-forwarding.sh b/bashrc/common/ssh-agent-forwarding.sh index e4435ee..14a880f 100644 --- a/bashrc/common/ssh-agent-forwarding.sh +++ b/bashrc/common/ssh-agent-forwarding.sh @@ -1,14 +1,32 @@ -TMPFILE=$(mktemp) - -# cleanup old agent-sockets -if [ -r "${HOME}/.ssh-agent-forwarding" ]; then - cut -d" " -f2 "${HOME}/.ssh-agent-forwarding" | \ - xargs ls -a 2>/dev/null | \ - grep -f - "${HOME}/.ssh-agent-forwarding" | \ - sort -n > "${TMPFILE}" +wipe_removed_sockets() { + TMPFILE=$(mktemp) + + # cleanup old agent-sockets + if [ -r "${HOME}/.ssh-agent-forwarding" ]; then + cut -d" " -f2 "${HOME}/.ssh-agent-forwarding" | \ + xargs ls -a 2>/dev/null | \ + grep -f - "${HOME}/.ssh-agent-forwarding" | \ + sort -n > "${TMPFILE}" - mv "${TMPFILE}" "${HOME}/.ssh-agent-forwarding" -fi + mv "${TMPFILE}" "${HOME}/.ssh-agent-forwarding" + fi +} + +fixssh() { + # if the symlinked socket, does not exists + # find latest connection, that is still alive + wipe_removed_sockets + + if [ ! -e "${HOME}/.ssh-agent-forwarded-sock" ]; then + LATEST_SOCK=$(tail -n 1 "${HOME}/.ssh-agent-forwarding" | cut -d" " -f2) + + if [ -n "$LATEST_SOCK" ]; then + ln -sf "${LATEST_SOCK}" "${HOME}/.ssh-agent-forwarded-sock" + fi + fi +} + +wipe_removed_sockets # if this login is via ssh and ssh-agent is forwarded if [ -n "$SSH_AUTH_SOCK" -a -n "$SSH_CLIENT" ]; then -- cgit v1.2.3