myshellconfig/bin/token

83 lines
1.6 KiB
Text
Raw Normal View History

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-06 23:48:41 +02:00
echo SSH_AGENT_PID: $SSH_AGENT_PID
echo SSH_AUTH_SOCK: $SSH_AUTH_SOCK
echo PKCS11_MODULE: $PKCS11_MODULE
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
echo test6
2020-07-06 11:40:19 +02:00
fi
2020-07-06 23:48:41 +02:00
echo SSH_AGENT_PID: $SSH_AGENT_PID
echo SSH_AUTH_SOCK: $SSH_AUTH_SOCK
echo PKCS11_MODULE: $PKCS11_MODULE
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
echo test1
test -n "${SSH_AGENT_PID+x}"
if [ "$?" == 0 ]; then
echo test2
cat << EOF > ~/.ssh-agent
SSH_AUTH_SOCK=${SSH_AUTH_SOCK}; export SSH_AUTH_SOCK;
SSH_AGENT_PID=265136; export SSH_AGENT_PID;
echo auth socket ${SSH_AUTH_SOCK};
echo Agent pid 265136;
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
echo test3
fi
else
echo test4
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