summaryrefslogtreecommitdiffstats
path: root/bashrc
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2009-02-08 12:38:27 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2009-02-08 12:38:27 +0100
commit6b798eb0d7eab1e7ceb587d942a8b3cd5e9dbc8c (patch)
tree74d826617aebc2d6a407bc194bb149f0066a61fc /bashrc
parentcb33e74054d702eda5c6b1d6770751e06bc3083c (diff)
downloaddotfiles-6b798eb0d7eab1e7ceb587d942a8b3cd5e9dbc8c.tar.gz
dotfiles-6b798eb0d7eab1e7ceb587d942a8b3cd5e9dbc8c.tar.xz
dotfiles-6b798eb0d7eab1e7ceb587d942a8b3cd5e9dbc8c.zip
added fixssh again to create symlink to latest connected agent-socket
Diffstat (limited to 'bashrc')
-rw-r--r--bashrc/common/ssh-agent-forwarding.sh38
1 files changed, 28 insertions, 10 deletions
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