tangled
alpha
login
or
join now
sharparam.com
/
dotfiles
0
fork
atom
this repo has no description
dotfiles
0
fork
atom
overview
issues
pulls
pipelines
Add files for WSL GPG forwarding
sharparam.com
6 years ago
3cc8cc1f
15bf8cac
+52
-3
2 changed files
expand all
collapse all
unified
split
bin
wsl-gpg-agent-relay.sh
zsh
.zshrc
+32
bin/wsl-gpg-agent-relay.sh
···
1
1
+
#!/bin/bash
2
2
+
# Launches socat+npiperelay to relay the gpg-agent socket file for use in WSL
3
3
+
# See https://justyn.io/blog/using-a-yubikey-for-gpg-in-windows-10-wsl-windows-subsystem-for-linux/ for details
4
4
+
5
5
+
GPGDIR="${HOME}/.gnupg"
6
6
+
WINDOWS_USERNAME=adamh
7
7
+
WSL_USERNAME=sharparam
8
8
+
WIN_GPGDIR="C:/Users/${WINDOWS_USERNAME}/AppData/Roaming/gnupg"
9
9
+
NPIPERELAY="/mnt/e/apps/npiperelay.exe"
10
10
+
PIDFILE="${GPGDIR}/.gpg-agent-relay.pid"
11
11
+
OLDPID=$(cat "${PIDFILE}" 2>/dev/null)
12
12
+
13
13
+
# Launch socat+npiperelay for the regular gpg-agent
14
14
+
if [ ! -z "${OLDPID}" ]; then
15
15
+
ps -p "${OLDPID}" >/dev/null && \
16
16
+
echo "gpg-agent-relay.sh already running with process id $(cat ${PIDFILE})" && \
17
17
+
exit 0
18
18
+
fi
19
19
+
20
20
+
rm -f "${GPGDIR}/S.gpg-agent*"
21
21
+
echo $$ > ${PIDFILE}
22
22
+
23
23
+
# Relay the regular gpg-agent socket for gpg operations
24
24
+
socat UNIX-LISTEN:"${GPGDIR}/S.gpg-agent,fork" EXEC:"${NPIPERELAY} -ep -ei -s -a '${WIN_GPGDIR}/S.gpg-agent'",nofork &
25
25
+
AGENTPID=$!
26
26
+
27
27
+
# Relay the gpg ssh-agent
28
28
+
socat UNIX-LISTEN:"${GPGDIR}/S.gpg-agent.ssh,fork" EXEC:"${NPIPERELAY} -ep -ei -s -a '${WIN_GPGDIR}/S.gpg-agent.ssh'",nofork &
29
29
+
SSHPID=$!
30
30
+
31
31
+
wait ${AGENTPID}
32
32
+
wait ${SSHPID}
+20
-3
zsh/.zshrc
···
196
196
fi
197
197
198
198
export GPG_TTY="$(tty)"
199
199
-
unset SSH_AGENT_PID
200
200
-
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
201
201
-
gpgconf --launch gpg-agent
199
199
+
if [[ $is_wsl ]]; then
200
200
+
wsl_gpg_agent_relay="$HOME/.local/bin/wsl-gpg-agent-relay.sh"
201
201
+
if [[ -f "$wsl_gpg_agent_relay" ]]; then
202
202
+
echo '[WSL] Launching WSL GPG agent relay'
203
203
+
$wsl_gpg_agent_relay &
204
204
+
else
205
205
+
echo "[WSL] Missing: ${wsl_gpg_agent_relay}"
206
206
+
fi
207
207
+
unset SSH_AGENT_PID
208
208
+
export SSH_AUTH_SOCK=$HOME/.local/wsl-ssh-pageant/ssh-agent.sock
209
209
+
else
210
210
+
unset SSH_AGENT_PID
211
211
+
export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
212
212
+
gpgconf --launch gpg-agent
213
213
+
fi
214
214
+
215
215
+
if [[ -d '/usr/local/go/bin' ]]; then
216
216
+
path=("$path[@]" /usr/local/go/bin)
217
217
+
fi
218
218
+
#export GOPATH="$HOME/go"
202
219
203
220
# tmux helpers
204
221
ts() {