2018-11-21 17:51:14 -07:00
|
|
|
file="$HOME/.ssh-agent"
|
|
|
|
|
|
|
|
which ssh-agent &> /dev/null
|
|
|
|
if (( $? )); then
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "$SSH_AUTH_SOCK" ]] && [[ -n "$SSH_AGENT_PID" ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -e $file ]]; then
|
|
|
|
sockenv=`cat $file | grep SSH_AUTH_SOCK`
|
|
|
|
pidenv=`cat $file | grep SSH_AGENT_PID`
|
|
|
|
pid=`printf "$pidenv" | grep -o "[0-9]*"`
|
|
|
|
|
2018-11-22 12:18:54 -07:00
|
|
|
kill -0 "$pid" &> /dev/null
|
2018-11-21 17:51:14 -07:00
|
|
|
if (( ! $? )); then
|
|
|
|
export "$sockenv"
|
|
|
|
export "$pidenv"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2018-11-22 12:11:32 -07:00
|
|
|
export $(ssh-agent -s |
|
|
|
|
awk '{
|
|
|
|
if ($1 ~ ".*=.*;") {
|
|
|
|
print substr($1, 0, length($1) - 1)
|
|
|
|
}
|
|
|
|
}' |
|
|
|
|
tee "$file")
|
2018-11-21 17:51:14 -07:00
|
|
|
chmod 600 "$file"
|