-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path4-agent
executable file
·36 lines (35 loc) · 1.08 KB
/
4-agent
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# shellcheck shell=ksh
# vim: syntax=sh et ts=2 sw=2 sts=2
start_ssh_agent ()
{
# Bail out early if the ssh directory
# is not found.
if [ ! -d ~/.ssh ]; then
return
fi
# Determine whether we are inside of an
# interactive shell and that ssh-agent
# is actually installed on the host.
if [[ $(command -v ssh-agent) ]] && \
[[ $- = *i* ]]; then
auth_socket=~/.ssh/agent.$(hostname -s).sock
# If we do not have an active ssh-agent
# socket, create one and start up a new
# agent pointing towards it.
if [[ ! -S $auth_socket ]]; then
# Remove the socket should an error occur,
# preventing future agents from connecting
# to the in-use socket bind address.
if ! eval "$(ssh-agent -a "$auth_socket" -t 28800)" >/dev/null 2>&1; then
rm -f "$auth_socket"
fi
# Otherwise, check for an already running
# ssh-agent and similarly point at the
# existing socket.
elif [[ -n $(pgrep ssh-agent) ]]; then
export SSH_AUTH_SOCK=$auth_socket
fi
unset auth_socket
fi
}; start_ssh_agent
unset -f start_ssh_agent