bash/sources/15_gpg-agent
raw ยท 743 bytes
#!/bin/bash
if command -v gpg-connect-agent >/dev/null 2>&1; then
export GPG_TTY
GPG_TTY="$(tty 2>/dev/null || true)"
gpg-connect-agent /bye >/dev/null 2>&1 || true
if [ -n "$GPG_TTY" ]; then
gpg-connect-agent updatestartuptty /bye >/dev/null 2>&1 || true
fi
fi
# Optional: use gpg-agent as ssh-agent only when configured.
if command -v gpgconf >/dev/null 2>&1 &&
[ -f "${GNUPGHOME:-$HOME/.gnupg}/gpg-agent.conf" ] &&
grep -Eq '^[[:space:]]*enable-ssh-support([[:space:]]|$)' "${GNUPGHOME:-$HOME/.gnupg}/gpg-agent.conf"
then
_rbash_gpg_ssh_sock="$(gpgconf --list-dirs agent-ssh-socket 2>/dev/null || true)"
if [ -n "$_rbash_gpg_ssh_sock" ]; then
export SSH_AUTH_SOCK="$_rbash_gpg_ssh_sock"
fi
unset _rbash_gpg_ssh_sock
fi