Created
August 30, 2018 15:17
-
-
Save charles-dyfis-net/ad0d6eb0729ee91ad3cd40a601b9bc2a to your computer and use it in GitHub Desktop.
gpg-agent yubikey / gpg tooling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
do_gpg_setup() { | |
local ssh_add_err | |
if gpg-connect-agent /bye &>/dev/null && [[ -e "$HOME/.ssh_auth_sock" ]] && { ssh_add_err=$(SSH_AUTH_SOCK=$HOME/.ssh_auth_sock ssh-add -l 2>&1) || [[ $ssh_add_err = "The agent has no identities." ]]; }; then | |
export SSH_AUTH_SOCK=$HOME/.ssh_auth_sock | |
return # Nothing to do | |
else | |
[[ $orig_GPG_AGENT_INFO ]] && GPG_AGENT_INFO=$orig_GPG_AGENT_INFO gpg-connect-agent killagent /bye | |
[[ $GPG_AGENT_INFO ]] && GPG_AGENT_INFO=$GPG_AGENT_INFO gpg-connect-agent killagent /bye | |
fi | |
local cmds | |
cmds="$(gpg-agent --daemon --enable-ssh-support)" || return | |
eval "$cmds" | |
if [[ $SSH_AUTH_SOCK ]]; then | |
export ssh_agent_is_gpg_agent=1 | |
orig_SSH_AUTH_SOCK=$SSH_AUTH_SOCK | |
ln -s -f -- "$orig_SSH_AUTH_SOCK" $HOME/.ssh_auth_sock | |
SSH_AUTH_SOCK=$HOME/.ssh_auth_sock | |
export orig_SSH_AUTH_SOCK | |
fi | |
if [[ $GPG_AGENT_INFO ]]; then | |
: "${orig_GPG_AGENT_INFO:=$GPG_AGENT_INFO}" | |
IFS=: read -r gpg_agent_file gpg_agent_pid _ <<<"$GPG_AGENT_INFO" | |
ln -s -f -- "$gpg_agent_file" "$HOME/.gpg_agent_lock" | |
GPG_AGENT_INFO="$HOME/.gpg_agent_lock:${GPG_AGENT_INFO#*:}" | |
export orig_GPG_AGENT_INFO | |
fi | |
} | |
do_gpg_setup |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
enable-ssh-support |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment