| 192 |
- |
1 |
#!/bin/sh
|
|
|
2 |
|
|
|
3 |
GPG_AGENT=/usr/bin/gpg-agent
|
|
|
4 |
## Run gpg-agent only if not already running, and available
|
|
|
5 |
if [ -x "${GPG_AGENT}" ] ; then
|
|
|
6 |
|
|
|
7 |
# gpg-agent uses ~/.gpg-agent-info by default, but we'll try to use
|
|
|
8 |
# XDG_RUNTIME_DIR too for added safety
|
|
|
9 |
GPG_AGENT_INFO_FILE=${XDG_RUNTIME_DIR:-${HOME}}/.gpg-agent-info
|
|
|
10 |
|
|
|
11 |
# check validity of GPG_SOCKET (in case of session crash)
|
|
|
12 |
if [ -f "${GPG_AGENT_INFO_FILE}" ]; then
|
|
|
13 |
GPG_AGENT_PID=`cat ${GPG_AGENT_INFO_FILE} | cut -f2 -d:`
|
|
|
14 |
GPG_PID_NAME=`ps -p ${GPG_AGENT_PID} -o comm=`
|
|
|
15 |
if [ ! "x${GPG_PID_NAME}" = "xgpg-agent" ]; then
|
|
|
16 |
rm -f "${GPG_AGENT_INFO_FILE}" 2>&1 >/dev/null
|
|
|
17 |
else
|
|
|
18 |
GPG_SOCKET=`cat "${GPG_AGENT_INFO_FILE}" | cut -f1 -d: | cut -f2 -d=`
|
|
|
19 |
if ! test -S "${GPG_SOCKET}" -a -O "${GPG_SOCKET}" ; then
|
|
|
20 |
rm -f "${GPG_AGENT_INFO_FILE}" 2>&1 >/dev/null
|
|
|
21 |
fi
|
|
|
22 |
fi
|
|
|
23 |
unset GPG_AGENT_PID GPG_SOCKET GPG_PID_NAME
|
|
|
24 |
fi
|
|
|
25 |
|
|
|
26 |
if [ -f "${GPG_AGENT_INFO_FILE}" ]; then
|
|
|
27 |
eval "$(cat "${GPG_AGENT_INFO_FILE}")"
|
|
|
28 |
eval "$(cut -d= -f1 < "${GPG_AGENT_INFO_FILE}" | xargs echo export)"
|
|
|
29 |
export GPG_TTY=$(tty)
|
|
|
30 |
else
|
|
|
31 |
eval "$(${GPG_AGENT} -s --daemon --write-env-file ${GPG_AGENT_INFO_FILE})"
|
|
|
32 |
fi
|
|
|
33 |
|
|
|
34 |
unset GPG_AGENT_INFO_FILE
|
|
|
35 |
|
|
|
36 |
fi
|
|
|
37 |
|
|
|
38 |
unset GPG_AGENT
|