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