2005-12-01 19:53:39 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2006-06-22 16:02:58 +00:00
|
|
|
GPG_AGENT=/usr/bin/gpg-agent
|
2005-12-01 19:53:39 +00:00
|
|
|
## Run gpg-agent only if not already running, and available
|
2007-07-06 15:01:54 +00:00
|
|
|
if [ -x "${GPG_AGENT}" ] ; then
|
2006-06-22 16:38:21 +00:00
|
|
|
|
|
|
|
# check validity of GPG_SOCKET (in case of session crash)
|
2006-09-18 13:18:25 +00:00
|
|
|
GPG_AGENT_INFO_FILE=${HOME}/.gpg-agent-info
|
|
|
|
if [ -f "${GPG_AGENT_INFO_FILE}" ]; then
|
2007-07-06 15:01:54 +00:00
|
|
|
GPG_AGENT_PID=`cat ${GPG_AGENT_INFO_FILE} | cut -f2 -d:`
|
|
|
|
GPG_PID_NAME=`ps -p ${GPG_AGENT_PID} -o comm=`
|
|
|
|
if [ ! "x${GPG_PID_NAME}" = "xgpg-agent" ]; then
|
2006-09-18 13:18:25 +00:00
|
|
|
rm -f "${GPG_AGENT_INFO_FILE}" 2>&1 >/dev/null
|
2007-07-06 15:01:54 +00:00
|
|
|
else
|
|
|
|
GPG_SOCKET=`cat "${GPG_AGENT_INFO_FILE}" | cut -f1 -d:`
|
|
|
|
if ! test -S "${GPG_SOCKET}" -a -O "${GPG_SOCKET}" ; then
|
|
|
|
rm -f "${GPG_AGENT_INFO_FILE}" 2>&1 >/dev/null
|
|
|
|
fi
|
2006-06-22 16:38:21 +00:00
|
|
|
fi
|
2007-07-06 15:01:54 +00:00
|
|
|
unset GPG_AGENT_PID GPG_SOCKET GPG_PID_NAME
|
2006-06-22 16:38:21 +00:00
|
|
|
fi
|
|
|
|
|
2006-09-18 13:18:25 +00:00
|
|
|
if [ -f "${GPG_AGENT_INFO_FILE}" ]; then
|
|
|
|
export GPG_AGENT_INFO=$(cat "${GPG_AGENT_INFO_FILE}")
|
2005-12-01 19:53:39 +00:00
|
|
|
export GPG_TTY=$(tty)
|
|
|
|
else
|
|
|
|
eval "$(${GPG_AGENT} -s --daemon ${GPG_OPTIONS})"
|
2006-09-18 12:49:00 +00:00
|
|
|
echo ${GPG_AGENT_INFO} > "${HOME}/.gpg-agent-info"
|
2005-12-01 19:53:39 +00:00
|
|
|
fi
|
2006-06-22 16:38:21 +00:00
|
|
|
|
2005-12-01 19:53:39 +00:00
|
|
|
fi
|