From e026154a3ae8e6fdce7b298dd3013dc7a602830b Mon Sep 17 00:00:00 2001 From: Anthony Perkins Date: Thu, 22 Sep 2022 16:34:30 +0100 Subject: [PATCH] Remove stale ssh-agent socket --- roles/home-cli/files/profile | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/roles/home-cli/files/profile b/roles/home-cli/files/profile index ec03ec9..a24d023 100644 --- a/roles/home-cli/files/profile +++ b/roles/home-cli/files/profile @@ -240,6 +240,14 @@ if command -v ssh-agent > /dev/null then export SSH_AUTH_SOCK="${SSH_AUTH_SOCK:-$XDG_RUNTIME_DIR/ssh-agent.socket}" export SSH_AGENT_PID="${SSH_AGENT_PID:-$XDG_RUNTIME_DIR/ssh-agent.pid}" + ssh-add -l > /dev/null 2>&1 + local _acp_ssh_agent_exists=$? + if [ -S "$SSH_AUTH_SOCK" ] && [ $_acp_ssh_agent_exists -eq 2 ] + then + # Remove stale ssh-agent socket. + rm -f "$SSH_AUTH_SOCK" + fi + unset _acp_ssh_agent_exists if [ ! -S "$SSH_AUTH_SOCK" ] then ssh-agent -a "$SSH_AUTH_SOCK" > /dev/null