always source settings of old agent, if applicable

Fixes the problem that the `GPG_AGENT_INFO` environment variable is only exported,
if no `gpg-agent` instance is already running.
This commit is contained in:
Marvin Frommhold 2016-09-02 11:45:58 +02:00 committed by GitHub
commit d35846083f

View file

@ -14,18 +14,17 @@ function start_agent_withssh {
export SSH_AGENT_PID export SSH_AGENT_PID
} }
# check if another agent is running # source settings of old agent, if applicable
if ! gpg-connect-agent --quiet /bye > /dev/null 2> /dev/null; then if [ -f "${GPG_ENV}" ]; then
# source settings of old agent, if applicable
if [ -f "${GPG_ENV}" ]; then
. ${GPG_ENV} > /dev/null . ${GPG_ENV} > /dev/null
export GPG_AGENT_INFO export GPG_AGENT_INFO
export SSH_AUTH_SOCK export SSH_AUTH_SOCK
export SSH_AGENT_PID export SSH_AGENT_PID
fi fi
# check if another agent is running
if ! gpg-connect-agent --quiet /bye > /dev/null 2> /dev/null; then
# check again if another agent is running using the newly sourced settings
if ! gpg-connect-agent --quiet /bye > /dev/null 2> /dev/null; then
# check for existing ssh-agent # check for existing ssh-agent
if ssh-add -l > /dev/null 2> /dev/null; then if ssh-add -l > /dev/null 2> /dev/null; then
# ssh-agent running, start gpg-agent without ssh support # ssh-agent running, start gpg-agent without ssh support
@ -34,7 +33,6 @@ if ! gpg-connect-agent --quiet /bye > /dev/null 2> /dev/null; then
# otherwise start gpg-agent with ssh support # otherwise start gpg-agent with ssh support
start_agent_withssh; start_agent_withssh;
fi fi
fi
fi fi
GPG_TTY=$(tty) GPG_TTY=$(tty)