scripts/ssh-agent.sh

18 lines
566 B
Bash
Raw Normal View History

2022-11-14 15:59:19 +00:00
#!/bin/bash
2023-03-13 19:54:38 +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
pkill ssh-agent
rm $HOME/.spool/ssh-agent.*
else
CMD=$(ps -p $PID -o comm | tail -n 1)
if [ ! -z $CMD ] && [ $CMD == 'ssh-agent' ]; then
echo "Valid agent already found at $HOME/.spool/ssh-agent.sock with PID $PID"
exit
fi
fi
fi
2022-11-14 15:59:19 +00:00
eval $(ssh-agent -a $HOME/.spool/ssh-agent.sock | tee $HOME/.spool/ssh-agent.env) >/dev/null