scripts/ssh-agent.sh

18 lines
629 B
Bash
Raw Normal View History

2022-11-14 15:59:19 +00:00
#!/bin/bash
2023-07-06 16:16:20 +00:00
if [ -e "${HOME}/.spool/ssh-agent.sock" ]; then
PID=$(tail -n 1 "${HOME}/.spool/ssh-agent.env" | sed 's/echo Agent pid \([0-9]*\);/\1/')
if [ -z "$PID" ]; then
2023-08-11 16:19:58 +00:00
rm "${HOME}/.spool/ssh-agent.sock" "${HOME}/.spool/ssh-agent.pid" 2>/dev/null
2023-03-13 19:54:38 +00:00
pkill ssh-agent
else
2023-07-06 16:16:20 +00:00
CMD=$(ps -p "$PID" -o comm | tail -n 1)
if [ -n "$CMD" ] && [ "$CMD" == 'ssh-agent' ]; then
echo "Valid agent already found at ${HOME}/.spool/ssh-agent.sock with PID $PID"
2023-03-13 19:54:38 +00:00
exit
fi
fi
fi
2023-07-06 16:16:20 +00:00
eval $(ssh-agent -a "${HOME}/.spool/ssh-agent.sock" | tee "${HOME}/.spool/ssh-agent.env")