utils/bash/sources/09_ssh-agent

36 lines
765 B
Plaintext
Raw Normal View History

2014-08-04 09:40:25 +00:00
#!/bin/bash
2022-08-11 16:39:41 +00:00
# ssh-agent key lifetime
alias ssh-add="ssh-add -t 43200"
2014-08-04 09:40:25 +00:00
SSH_ENV="$HOME/.ssh/environment"
function start_agent {
echo "Initialising new SSH agent..."
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo succeeded
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
2014-10-10 02:21:44 +00:00
# Test the ssh-add if status return 0/1, agent is initialized
2014-08-04 09:40:25 +00:00
/usr/bin/ssh-add;
2014-10-10 02:21:44 +00:00
ST=$?
if [ $ST -ne 0 ] && [ $ST -ne 1 ]; then
return $ST
fi
return 0
2014-08-04 09:40:25 +00:00
}
# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
#ps ${SSH_AGENT_PID} doesn't work under cywgin
ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
start_agent;
}
else
start_agent;
fi