diff options
author | Toby Vincent <tobyv13@gmail.com> | 2021-05-12 20:27:05 -0500 |
---|---|---|
committer | Toby Vincent <tobyv13@gmail.com> | 2021-05-12 20:27:05 -0500 |
commit | 395bce80ca7d6f572825c2618767e87ec43ddc12 (patch) | |
tree | c9570e3b2a3fc0874ef95d930fab676bac6f20d0 /sh/gpg.sh | |
parent | 516ce638f5c5ce0dab77367aa906f374da14b315 (diff) |
refactor: renamed the shell folder to sh
Diffstat (limited to 'sh/gpg.sh')
-rw-r--r-- | sh/gpg.sh | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/sh/gpg.sh b/sh/gpg.sh new file mode 100644 index 0000000..ea87d05 --- /dev/null +++ b/sh/gpg.sh @@ -0,0 +1,44 @@ +# https://github.com/benpye/wsl-ssh-pageant +# https://github.com/drduh/YubiKey-Guide#remote-host-configuration +# https://dev.to/dzerycz/series/11353 + +# SSH Socket +# Removing Linux SSH socket and replacing it by link to wsl2-ssh-pageant socket +export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock +ss -a | grep -q $SSH_AUTH_SOCK +if [ $? -ne 0 ]; then + rm -f $SSH_AUTH_SOCK + (setsid nohup socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"$DOTFILES/ssh/wsl2-ssh-pageant.exe" &>/dev/null &) +fi + + +# GPG Socket +# Removing Linux GPG Agent socket and replacing it by link to wsl2-ssh-pageant GPG socket +export GPG_AGENT_SOCK=$HOME/.gnupg/S.gpg-agent + +export GPG_SOCKETS=("${GPG_AGENT_SOCK}" "${GPG_AGENT_SOCK}.extra" "${GPG_AGENT_SOCK}.ssh") + +for socket in "${GPG_SOCKETS[@]}"; do + ss -a | grep -q $socket + if [ $? -ne 0 ]; then + rm -rf $socket + (setsid nohup socat UNIX-LISTEN:$socket,fork EXEC:"$DOTFILES/ssh/wsl2-ssh-pageant.exe --gpg $(basename $socket)" &>/dev/null &) + fi +done + + +alias gpgrst=gpg-reset +# Reload +function gpg-reset() { + gpg-connect-agent.exe KILLAGENT /bye &>/dev/null + + for socket in "${GPG_SOCKETS[@]}"; do + [ -e $socket ] && rm $socket + done + pkill -f 'socat.*wsl2-ssh-pageant.exe' + gpg-connect-agent.exe /bye &>/dev/null + + for socket in "${GPG_SOCKETS[@]}"; do + (setsid nohup socat UNIX-LISTEN:$socket,fork EXEC:"$DOTFILES/ssh/wsl2-ssh-pageant.exe --gpg $(basename $socket)" &>/dev/null &) + done +} |