myshellconfig/bin/ssh-init-pkcs11

26 lines
785 B
Text
Raw Normal View History

2020-07-06 11:40:19 +02:00
#!/bin/sh
set -eu
set -x
2021-07-07 16:26:58 +02:00
which dnf >/dev/null 2>&1 [ -z "${P11M+x}" ] && P11M="$(dnf repoquery --installed -l p11-kit | grep \/p11-kit-proxy.so\$ | head -1)"
which dpkg >/dev/null 2>&1 && [ -z "${P11M+x}" ] && P11M="$(dpkg -L p11-kit-modules|grep \/p11-kit-proxy.so\$ | head -1)"
2020-07-06 11:40:19 +02:00
echo SSH_AGENT_PID before: $SSH_AGENT_PID
[ -z "$(pidof ssh-agent)" -o "${SSH_AGENT_PID}" != "$(pidof ssh-agent)" ] && eval "$(ssh-agent -s)"
echo SSH_AGENT_PID after: $SSH_AGENT_PID
#if ssh-add -l | grep -q "${P11M}"; then
2020-07-06 11:40:19 +02:00
# # Remove any stale loaded keys from token, ssh-agent does not automatically
# # reconnect with the token when you reinsert it.
# ssh-add -e "${P11M}"
2020-07-06 11:40:19 +02:00
#fi
ssh-add -e "${P11M}" 2>/dev/null
2020-07-06 11:40:19 +02:00
echo $?
# Tell ssh-agent to use the keys on the token
ssh-add -s "${P11M}"