2020-01-02 16:57:06 +01:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
if [ ! -z "$SSH_AGENT_PID" ]; then
|
2020-01-02 23:28:07 +01:00
|
|
|
# Here, the environment is set already, just kill the script.
|
|
|
|
eval $(ssh-agent -k) >/dev/null
|
2020-01-02 16:57:06 +01:00
|
|
|
exit $?
|
|
|
|
else
|
2020-01-02 23:28:07 +01:00
|
|
|
# The env isn't set, construct the file path.
|
|
|
|
STORE_PATH=/tmp
|
|
|
|
if [ ! -z "$1" ]; then
|
|
|
|
STORE_PATH="$STORE_PATH/$1"
|
|
|
|
fi
|
|
|
|
if [ ! -d "$STORE_PATH" ]; then
|
|
|
|
echo "Store Path $STORE_PATH doesn't exist!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
# And check our files exist.
|
|
|
|
if [ -f "$STORE_PATH/ssh-agent-id" ]; then
|
|
|
|
# Grab our PID and socket.
|
|
|
|
SSH_AGENT_PID=$(cat "$STORE_PATH/ssh-agent-id")
|
|
|
|
export SSH_AGENT_PID
|
|
|
|
|
|
|
|
SSH_AUTH_SOCK=$(cat "$STORE_PATH/ssh-auth-sock")
|
|
|
|
export SSH_AUTH_SOCK
|
|
|
|
|
|
|
|
eval $(ssh-agent -k) >/dev/null
|
|
|
|
exit $?
|
|
|
|
else
|
|
|
|
echo "SSH_AGENT_PID not set, $STORE_PATH/ssh-auth-sock doesn't exist!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
2020-01-02 16:57:06 +01:00
|
|
|
fi
|