2012-02-01 04:37:51 +00:00
|
|
|
#
|
|
|
|
# Provides for an easier use of gpg-agent.
|
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Florian Walch <florian.walch@gmx.at>
|
|
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
|
|
|
#
|
2010-10-15 14:50:39 +00:00
|
|
|
|
2011-08-31 03:16:15 +00:00
|
|
|
if (( ! $+commands[gpg-agent] )); then
|
2012-03-28 16:19:53 +00:00
|
|
|
return 1
|
2011-08-31 03:16:15 +00:00
|
|
|
fi
|
|
|
|
|
2012-03-09 02:51:42 +00:00
|
|
|
_gpg_env="$HOME/.gnupg/gpg-agent.env"
|
|
|
|
|
2012-03-23 18:57:51 +00:00
|
|
|
function _gpg-agent-start {
|
2012-03-07 23:05:01 +00:00
|
|
|
gpg-agent --daemon --enable-ssh-support --write-env-file "${_gpg_env}" > /dev/null
|
2012-03-07 17:01:05 +00:00
|
|
|
chmod 600 "${_gpg_env}"
|
2012-03-07 23:05:01 +00:00
|
|
|
source "${_gpg_env}" > /dev/null
|
2010-10-15 14:50:39 +00:00
|
|
|
}
|
|
|
|
|
2011-08-31 03:16:15 +00:00
|
|
|
# Source GPG agent settings, if applicable.
|
2012-03-07 17:01:05 +00:00
|
|
|
if [[ -f "${_gpg_env}" ]]; then
|
2012-03-07 23:05:01 +00:00
|
|
|
source "${_gpg_env}" > /dev/null
|
2012-03-07 17:01:05 +00:00
|
|
|
ps -ef | grep "${SSH_AGENT_PID}" | grep -q 'gpg-agent' || {
|
2012-02-01 04:42:01 +00:00
|
|
|
_gpg-agent-start
|
2010-10-15 14:50:39 +00:00
|
|
|
}
|
|
|
|
else
|
2012-02-01 04:42:01 +00:00
|
|
|
_gpg-agent-start
|
2010-10-15 14:50:39 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
export GPG_AGENT_INFO
|
|
|
|
export SSH_AUTH_SOCK
|
|
|
|
export SSH_AGENT_PID
|
2012-02-01 04:42:01 +00:00
|
|
|
export GPG_TTY="$(tty)"
|
2011-08-31 03:16:15 +00:00
|
|
|
|