014ed1f0e5c85a10ab7538160e2d3421ab3dbf7e
- Author
- Heiko Reese <mail@heiko-reese.de>
- Committer
- Heiko Reese <mail@heiko-reese.de>
- Date
Message
Disable ssh-agent support if another ssh-agent is already running.
Diff
1diff --git a/plugins/gpg-agent/gpg-agent.plugin.zsh b/plugins/gpg-agent/gpg-agent.plugin.zsh
2index 8cc71fd57692de243e8a497786d1e1f8eb0b2bba..63c4334133c9bc39462b311ea793637908714f7b 100644
3--- a/plugins/gpg-agent/gpg-agent.plugin.zsh
4+++ b/plugins/gpg-agent/gpg-agent.plugin.zsh
5@@ -1,26 +1,31 @@
6-# Based on ssh-agent code
7-
8 local GPG_ENV=$HOME/.gnupg/gpg-agent.env
9
10-function start_agent {
11- /usr/bin/env gpg-agent --daemon --enable-ssh-support --write-env-file ${GPG_ENV} > /dev/null
12- chmod 600 ${GPG_ENV}
13- . ${GPG_ENV} > /dev/null
14+function start_agent_nossh {
15+ eval $(/usr/bin/env gpg-agent --daemon --write-env-file ${GPG_ENV}) > /dev/null
16+ export GPG_AGENT_INFO
17+}
18+
19+function start_agent_withssh {
20+ eval $(/usr/bin/env gpg-agent --daemon --enable-ssh-support --write-env-file ${GPG_ENV}) > /dev/null
21+ export GPG_AGENT_INFO
22+ export SSH_AUTH_SOCK
23+ export SSH_AGENT_PID
24 }
25
26-# Source GPG agent settings, if applicable
27+# make sure all created files are u=rw only
28+umask 177
29+
30+# source settings of old agent, if applicable
31 if [ -f "${GPG_ENV}" ]; then
32 . ${GPG_ENV} > /dev/null
33- ps -ef | grep ${SSH_AGENT_PID} | grep gpg-agent > /dev/null || {
34- start_agent;
35- }
36-else
37- start_agent;
38 fi
39
40-export GPG_AGENT_INFO
41-export SSH_AUTH_SOCK
42-export SSH_AGENT_PID
43+# check for existing ssh-agent
44+if ssh-add -l > /dev/null 2> /dev/null; then
45+ start_agent_nossh;
46+else
47+ start_agent_withssh;
48+fi
49
50 GPG_TTY=$(tty)
51 export GPG_TTY