fix some errors

* in PS1

move token from script to sourced functions.sh
add alias
This commit is contained in:
Jakobus Schürz 2020-07-10 12:34:50 +02:00
parent c8691cc3ea
commit d520d8eca8
4 changed files with 75 additions and 85 deletions

2
PS1
View file

@ -2,7 +2,7 @@
parse_git_branch() {
local BRANCH=$(git branch 2>/dev/null | sed -ne 's/* \(.*\)/ (\1/p')
BRANCH="$BRANCH -> $( git rev-parse --symbolic-full-name --abbrev-ref @{u} 2>/dev/null ) )"
BRANCH="$BRANCH ${BRANCH-->} $( git rev-parse --symbolic-full-name --abbrev-ref @{u} 2>/dev/null ) )"
echo $BRANCH
}

View file

@ -193,3 +193,5 @@ alias gocnfhome='cd /var/atlassian/application-data/confluence/'
alias gocnflog='cd /var/atlassian/application-data/confluence/logs'
alias tailcnf='cd /var/atlassian/application-data/confluence/logs; tail -F atlassian-confluence.log'
# eToken
alias agent='eval "$(<~/.ssh-agent)"'

View file

@ -1,83 +0,0 @@
#!/bin/sh
#set -eu
#set -x
[ -z "${PKCS11_MODULE+x}" ] && { PKCS11_MODULE=/usr/lib64/p11-kit-proxy.so; export PKCS11_MODULE; }
PASS=$(which pass 2>/dev/null || exit 127 )
PKEY="bmi/etoken"
ssh-add -l &>/dev/null
if [ "$?" == 2 ]; then
test -r ~/.ssh-agent && \
echo "create new ssh-agent" >&2
eval "$(<~/.ssh-agent)" >&2
#eval "$(<~/.ssh-agent)" >/dev/null
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
:
fi
#echo SSH_AGENT_PID: $SSH_AGENT_PID
#echo SSH_AUTH_SOCK: $SSH_AUTH_SOCK
#echo PKCS11_MODULE: $PKCS11_MODULE
ssh-add -l &>/dev/null
#ssh-add -l & >&2
if [ "$?" == 0 ]; then
# Remove and add again $PKCS11_MODULE
ssh-add -e $PKCS11_MODULE
ssh-add -s $PKCS11_MODULE
test -n "${SSH_AUTH_SOCK+x}"
if [ "$?" == 0 ] ; then
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"
test -n "${SSH_AGENT_PID+x}"
if [ "$?" == 0 ]; then
cat << EOF > ~/.ssh-agent
SSH_AUTH_SOCK=${SSH_AUTH_SOCK}; export SSH_AUTH_SOCK;
SSH_AGENT_PID=${SSH_AGENT_PID}; export SSH_AGENT_PID;
echo auth socket ${SSH_AUTH_SOCK};
echo Agent pid ${SSH_AGENT_PID};
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
:
fi
cat << EOF
Now run
eval "\$(<~/.ssh-agent)"
EOF
else
echo "not able to create ssh-agent"
fi

View file

@ -625,7 +625,6 @@ reachableim () {
return $res
}
#EOF
reachable () {
local SERVER=$1
@ -649,4 +648,76 @@ reachable () {
return $res
}
token () {
[ -z "${PKCS11_MODULE+x}" ] && { PKCS11_MODULE=/usr/lib64/p11-kit-proxy.so; export PKCS11_MODULE; }
ssh-add -l &>/dev/null
if [ "$?" == 2 ]; then
test -r ~/.ssh-agent && \
echo "create new ssh-agent" >&2
eval "$(<~/.ssh-agent)" >&2
#eval "$(<~/.ssh-agent)" >/dev/null
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
fi
else
:
fi
ssh-add -l &>/dev/null
#ssh-add -l & >&2
if [ "$?" == 0 ]; then
# Remove and add again $PKCS11_MODULE
ssh-add -e $PKCS11_MODULE
ssh-add -s $PKCS11_MODULE
if [ "$?" == 0 ]; then
test -n "${SSH_AUTH_SOCK+x}"
if [ "$?" == 0 ] ; then
SSH_AGENT_PID="$(sudo fuser "$SSH_AUTH_SOCK" 2>/dev/null)"
test -n "${SSH_AGENT_PID+x}"
if [ "$?" == 0 ]; then
SSH_AUTH_SOCK=${SSH_AUTH_SOCK}; export SSH_AUTH_SOCK;
SSH_AGENT_PID=${SSH_AGENT_PID}; export SSH_AGENT_PID;
cat << EOF > ~/.ssh-agent
SSH_AUTH_SOCK=${SSH_AUTH_SOCK}; export SSH_AUTH_SOCK;
SSH_AGENT_PID=${SSH_AGENT_PID}; export SSH_AGENT_PID;
echo Auth socket ${SSH_AUTH_SOCK};
echo Agent pid ${SSH_AGENT_PID};
EOF
else
SSH_AUTH_SOCK=${SSH_AUTH_SOCK}; export SSH_AUTH_SOCK;
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
:
fi
#eval "\$(<~/.ssh-agent)"
else
echo "Token not unlocked"
fi
# cat << EOF
#
#Now run
#
# eval "\$(<~/.ssh-agent)"
#
#EOF
else
echo "not able to create ssh-agent"
fi
}
#EOF