From 91f4bc89bdbd9eba00cc63942772cf8abac2647a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Thu, 23 Feb 2023 09:59:46 +0100 Subject: [PATCH] move reading for pkcs11-module to funktions --- bashrc_add | 12 ++---------- functions.sh | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/bashrc_add b/bashrc_add index c1ee248..c6ddd89 100755 --- a/bashrc_add +++ b/bashrc_add @@ -74,16 +74,6 @@ if [[ $- = *i* ]] ; then # which dpkg >/dev/null 2>&1 && [ -z "${P11M+x}" ] && P11M="$(dpkg -L p11-kit-modules|grep \/p11-kit-proxy.so\$ | head -1)" - function find_pkcs11module() { - [ -z "${PKCS11_MODULE:+x}" ] && \ - [ -n "$(whereis p11-kit-proxy.so|awk '{print $2}')" ] && \ - export PKCS11_MODULE=$(whereis p11-kit-proxy.so|awk '{print $2}' || \ - { echo "p11-kit-proxy not installed, unset PKCS11_MODULE"; unset PKCS11_MODULE; }) - [ -z "${P11M:+x}" ] && \ - [ -n "$(whereis p11-kit-proxy.so|awk '{print $2}')" ] && \ - export P11M=$(whereis p11-kit-proxy.so|awk '{print $2}' || \ - { echo "p11-kit-proxy not forwarded by ssh or installed, unset P11M"; unset P11M; }) - } # Basics [ -z "${VISUAL+x}" ] && export VISUAL=${VISUAL_DEFAULT} [ -z "${EDITOR+x}" ] && export EDITOR=${EDITOR_DEFAULT} @@ -206,8 +196,10 @@ EOF _tmux_hook _umask_hook + _pkcs11module promptcommandmunge "_tmux_hook" promptcommandmunge "_umask_hook" + promptcommandmunge "_pkcs11module" which direnv >/dev/null && eval "$(direnv hook bash)" cat << EOF >> "${MSC_LOGFILE}" diff --git a/functions.sh b/functions.sh index 1fea80f..618bff2 100755 --- a/functions.sh +++ b/functions.sh @@ -20,6 +20,20 @@ promptcommandmunge () { esac EXIT } + +function _pkcs11module() { + [ -z "${P11M:+x}" ] && \ + [ -n "$(whereis ${pkcs11_module_default:-p11-kit-proxy.so}|awk '{print $2}')" ] && \ + export P11M=$(whereis ${pkcs11_module_default:-p11-kit-proxy.so}|awk '{print $2}' || \ + { echo "${pkcs11_module_default:-p11-kit-proxy.so} not forwarded by ssh or installed, unset P11M"; unset P11M; }) + + [ -z "${PKCS11_MODULE:+x}" ] && PKCS11_MODULE=${P11M} + +# [ -z "${PKCS11_MODULE:+x}" ] && \ +# [ -n "$(whereis p11-kit-proxy.so|awk '{print $2}')" ] && \ +# export PKCS11_MODULE=$(whereis p11-kit-proxy.so|awk '{print $2}' || \ +# { echo "p11-kit-proxy not installed, unset PKCS11_MODULE"; unset PKCS11_MODULE; }) +} ## this function updates in combination with PROMPT_COMMAND the shell-environment-variables in tmux-sessions, # every time prompt is called. It does it only, when called from tmux (Environment TMUX is set) function _tmux_hook() { @@ -1025,6 +1039,7 @@ loadagent() { logdebug "SSH_AGENT_PID: ${SSH_AGENT_PID-not set}" loginfo "currently loaded keys in agent: $(ssh-add -l)" + export P11M=$PKCS11_MODULE EXIT }