forked from herlo/ssh-gpg-smartcard-config
-
Notifications
You must be signed in to change notification settings - Fork 7
/
gpg-agent-wrapper
40 lines (32 loc) · 1.19 KB
/
gpg-agent-wrapper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/bin/bash
GPG_CONNECT_AGENT=$(which gpg-connect-agent 2>/dev/null)
if [ -x "$GPG_CONNECT_AGENT" ]; then
$GPG_CONNECT_AGENT /bye
export SSH_AUTH_SOCK=$XDG_RUNTIME_DIR/gnupg/S.gpg-agent.ssh
if [ ! -S $SSH_AUTH_SOCK ]; then
# older versions of gpg-connect-agent put it in $HOME/.gnupg
export SSH_AUTH_SOCK=$HOME/.gnupg/S.gpg-agent.ssh
fi
else
# Copyright (c) 2010 Diego E. Pettenò <flameeyes@gmail.com>
# Available under CC-BY license (Attribution)
if ! [ -f "${HOME}/.gpg-agent-info" ] ||
! pgrep -u ${USER} gpg-agent >/dev/null; then
gpg-agent --daemon --enable-ssh-support --scdaemon-program /usr/libexec/scdaemon --use-standard-socket --log-file ~/.gnupg/gpg-agent.log --write-env-file
fi
# for ssh-agent forwarding, override gnome-keyring though!
if [ -n ${SSH_AUTH_SOCK} ] && \
[ ${SSH_AUTH_SOCK#/tmp/keyring-} = ${SSH_AUTH_SOCK} ]; then
fwd_SSH_AUTH_SOCK=${SSH_AUTH_SOCK}
fi
export SSH_AUTH_SOCK
if [ "${fwd_SSH_AUTH_SOCK}" != "" ]; then
SSH_AUTH_SOCK=${fwd_SSH_AUTH_SOCK}
export SSH_AUTH_SOCK
fi
source ${HOME}/.gpg-agent-info
export GPG_AGENT_INFO
export SSH_AGENT_PID
GPG_TTY=$(tty)
export GPG_TTY
fi