Added improved ssh-agent support.

This commit is contained in:
Darren 'Tadgy' Austin 2019-07-01 15:19:05 +01:00
commit ace5e0e8e3
3 changed files with 174 additions and 28 deletions

View file

@ -1,4 +1,7 @@
if (( $SHLVL == 1 )); then
#!/bin/bash - not strictly necessary, but helps nano with syntax highlighting.
# Clear the screen/console on logout.
if (( $SHLVL == 10 )); then
if [ -x /usr/bin/clear_console ]; then
/usr/bin/clear_console -q
elif [ -x /usr/bin/clear ]; then
@ -9,3 +12,25 @@ if (( $SHLVL == 1 )); then
echo -ne "\E[2J"
fi
fi
# Remove the SSH_AUTH_SOCK from the agents file.
(( $SHLVL == 1 )) && {
hash ssh-add ssh-agent >/dev/null 2>&1 && [[ ! -z "$SSH_AGENT_PID" ]] && [[ ! -z "$SSH_AUTH_SOCK" ]] && {
exec 9>~/.ssh/agents.lock
if flock -E 10 -w 0.5 9; then
_pop_agent_sock || {
echo -e "$(tput setaf 1 || tput AF 1)Failed to clean up agents file!$(tput op)"
_SLEEP=3
}
else
echo "$(tput setaf 1 || tput AF 1)Failed to obtain lockfile!$(tput op)"
_SLEEP=3
fi
exec 9>&-
ssh-agent -k >/dev/null 2>&1 || {
echo -e "$(tput setaf 1 || tput AF 1)Failed to kill ssh-agent!$(tput op)"
_SLEEP=3
}
sleep ${_SLEEP:-0}
}
}