ssh-agent: fix non-existing .ssh folder

master
Pierre Neidhardt 2013-12-23 11:46:51 +01:00
parent f2300b1ce3
commit 304928d2bc
1 changed files with 8 additions and 5 deletions

View File

@ -98,14 +98,17 @@ command -v dwb >/dev/null && export BROWSER="dwb"
## SSH-Agent
## WARNING: this is somewhat insecure if someone else has root access to the machine.
if command -v ssh-agent >/dev/null; then
readonly SSH_ENV_FILE="$HOME/.ssh/ssh-agent-env"
if [ ! -f "$SSH_ENV_FILE" ]; then
ssh-agent > "$SSH_ENV_FILE"
[ ! -e "$HOME/.ssh" ] && mkdir -p "$HOME/.ssh"
if [ -d "$HOME/.ssh" ]; then
readonly SSH_ENV_FILE="$HOME/.ssh/ssh-agent-env"
if [ ! -f "$SSH_ENV_FILE" ]; then
ssh-agent > "$SSH_ENV_FILE"
fi
source "$SSH_ENV_FILE"
fi
source "$SSH_ENV_FILE"
fi
## Kill ssh-agent if this is the only running session.
trap '[ $(w -hs $USER | wc -l) -eq 1 ] && test -n "$SSH_AGENT_PID" && eval $(ssh-agent -k) && rm "$SSH_ENV_FILE"' 0
trap '[ $(w -hs $USER | wc -l) -eq 1 ] && test -n "$SSH_AGENT_PID" && eval $(ssh-agent -k) && rm -f "$SSH_ENV_FILE"' 0
## Set TEMP dir if you want to override /tmp for some applications that check
## for this variable. Usually not a good idea.