Update ensure-ssh-agent for environments without a runtime dir

On macOS a XDG_RUNTIME is not set. Use a temp file instead if on macOS
main
Buddy Sandidge 5 years ago
parent 5683bf0b1e
commit c448b945fa

@ -1,14 +1,26 @@
#!/usr/bin/env bash #!/usr/bin/env bash
ENVFILE="${XDG_RUNTIME_DIR:-$XDG_DATA_HOME}/ssh-agent.env" function tmp-if-needed {
tmpdir=/tmp/ssh-env-$(whoami)
[[ -d $tmpdir ]] || mkdir $tmpdir
chmod 700 "$tmpdir"
chown $(whoami) "$tmpdir"
echo $tmpdir
}
ENVFILE="${XDG_RUNTIME_DIR:-$(tmp-if-needed)}/ssh-agent.env"
if [ -f $ENVFILE ] ; then if [ -f $ENVFILE ] ; then
. $ENVFILE > /dev/null . $ENVFILE > /dev/null
if ! kill -0 $SSH_AGENT_PID > /dev/null 2>&1; then if ! kill -0 $SSH_AGENT_PID > /dev/null 2>&1; then
eval $(ssh-agent | tee $ENVFILE) eval $(ssh-agent | tee $ENVFILE)
chmod 700 "$ENVFILE"
chown $(whoami) "$ENVFILE"
ssh-add ssh-add
fi fi
else else
eval $(ssh-agent | tee $ENVFILE) eval $(ssh-agent | tee $ENVFILE)
chmod 700 "$ENVFILE"
chown $(whoami) "$ENVFILE"
ssh-add ssh-add
fi fi

Loading…
Cancel
Save