2020-07-06 11:40:19 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#set -eu
|
|
|
|
#set -x
|
|
|
|
|
|
|
|
[ -z "${PKCS11_MODULE+x}" ] && { PKCS11_MODULE=/usr/lib64/p11-kit-proxy.so; export PKCS11_MODULE; }
|
|
|
|
|
2020-07-09 13:51:17 +02:00
|
|
|
PASS=$(which pass 2>/dev/null || exit 127 )
|
|
|
|
PKEY="bmi/etoken"
|
2020-07-06 11:40:19 +02:00
|
|
|
|
|
|
|
ssh-add -l &>/dev/null
|
|
|
|
if [ "$?" == 2 ]; then
|
2020-07-06 23:48:41 +02:00
|
|
|
test -r ~/.ssh-agent && \
|
|
|
|
echo "create new ssh-agent" >&2
|
|
|
|
eval "$(<~/.ssh-agent)" >&2
|
|
|
|
#eval "$(<~/.ssh-agent)" >/dev/null
|
2020-07-06 11:40:19 +02:00
|
|
|
|
2020-07-06 23:48:41 +02:00
|
|
|
ssh-add -l &>/dev/null
|
|
|
|
if [ "$?" == 2 ]; then
|
|
|
|
echo "create new ssh-agent and load env for it" >&2
|
|
|
|
(umask 066; ssh-agent > ~/.ssh-agent)
|
|
|
|
eval "$(<~/.ssh-agent)" >&2
|
|
|
|
#eval "$(<~/.ssh-agent)" >/dev/null
|
|
|
|
else
|
|
|
|
echo test X
|
|
|
|
|
|
|
|
fi
|
|
|
|
else
|
2020-07-09 13:51:17 +02:00
|
|
|
:
|
2020-07-06 11:40:19 +02:00
|
|
|
fi
|
|
|
|
|
2020-07-09 13:51:17 +02:00
|
|
|
#echo SSH_AGENT_PID: $SSH_AGENT_PID
|
|
|
|
#echo SSH_AUTH_SOCK: $SSH_AUTH_SOCK
|
|
|
|
#echo PKCS11_MODULE: $PKCS11_MODULE
|
|
|
|
|
2020-07-06 23:48:41 +02:00
|
|
|
|
2020-07-06 11:40:19 +02:00
|
|
|
ssh-add -l &>/dev/null
|
2020-07-06 23:48:41 +02:00
|
|
|
#ssh-add -l & >&2
|
2020-07-06 11:40:19 +02:00
|
|
|
if [ "$?" == 0 ]; then
|
|
|
|
# Remove and add again $PKCS11_MODULE
|
|
|
|
ssh-add -e $PKCS11_MODULE
|
|
|
|
ssh-add -s $PKCS11_MODULE
|
2020-07-06 23:48:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
test -n "${SSH_AUTH_SOCK+x}"
|
|
|
|
if [ "$?" == 0 ] ; then
|
2020-07-07 09:38:46 +02:00
|
|
|
sudo fuser "$SSH_AUTH_SOCK"|awk '{print $NF}'
|
|
|
|
|
|
|
|
SSH_AGENT_PID="$(sudo fuser "$SSH_AUTH_SOCK" |awk '{print $NF}')"
|
|
|
|
echo "SSH_AGENT_PID(fuser): $SSH_AGENT_PID"
|
|
|
|
|
2020-07-06 23:48:41 +02:00
|
|
|
|
|
|
|
test -n "${SSH_AGENT_PID+x}"
|
|
|
|
if [ "$?" == 0 ]; then
|
|
|
|
cat << EOF > ~/.ssh-agent
|
|
|
|
SSH_AUTH_SOCK=${SSH_AUTH_SOCK}; export SSH_AUTH_SOCK;
|
2020-07-09 13:51:17 +02:00
|
|
|
SSH_AGENT_PID=${SSH_AGENT_PID}; export SSH_AGENT_PID;
|
2020-07-06 23:48:41 +02:00
|
|
|
echo auth socket ${SSH_AUTH_SOCK};
|
2020-07-09 13:51:17 +02:00
|
|
|
echo Agent pid ${SSH_AGENT_PID};
|
2020-07-06 23:48:41 +02:00
|
|
|
EOF
|
|
|
|
else
|
|
|
|
cat << EOF > ~/.ssh-agent
|
|
|
|
SSH_AUTH_SOCK=${SSH_AUTH_SOCK}; export SSH_AUTH_SOCK;
|
|
|
|
echo auth socket ${SSH_AUTH_SOCK};
|
|
|
|
echo Agent pid not known;
|
|
|
|
EOF
|
|
|
|
fi
|
|
|
|
else
|
2020-07-09 13:51:17 +02:00
|
|
|
:
|
2020-07-06 23:48:41 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
cat << EOF
|
|
|
|
|
|
|
|
Now run
|
|
|
|
|
|
|
|
eval "\$(<~/.ssh-agent)"
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2020-07-06 11:40:19 +02:00
|
|
|
else
|
|
|
|
echo "not able to create ssh-agent"
|
|
|
|
fi
|
|
|
|
|