change function-names from xx-xx to xx_xx
This commit is contained in:
parent
e78a781638
commit
9491f9f017
1 changed files with 26 additions and 25 deletions
|
@ -1,13 +1,14 @@
|
||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
FILELOGLEVEL=DEBUG
|
FILELOGLEVEL=DEBUG
|
||||||
|
. $(dirname $0)/../logging
|
||||||
# loggerfactory
|
# loggerfactory
|
||||||
LANG=C
|
LANG=C
|
||||||
|
|
||||||
usage(){
|
usage(){
|
||||||
cat << EOF
|
cat << EOF
|
||||||
|
|
||||||
Usage: ssh-agent-start-or-restart [[-c]|[--create-only]]|[[-t]|[--token-only]]|[[-k]|[--key-only]]|[[-r]|[-f]|[--readd]|[--force]] [<ssh-identity>]
|
Usage: $(basename $0) [[-c]|[--create-only]]|[[-t]|[--token-only]]|[[-k]|[--key-only]]|[[-r]|[-f]|[--readd]|[--force]] [<ssh-identity>]
|
||||||
|
|
||||||
If started only with <ssh-identity>, the script looks up in configured identity-path \$SSH_IDENTITIES_DIR (${SSH_IDENTITIES_DIR}) if it can find a directory named after <ssh-identity>.
|
If started only with <ssh-identity>, the script looks up in configured identity-path \$SSH_IDENTITIES_DIR (${SSH_IDENTITIES_DIR}) if it can find a directory named after <ssh-identity>.
|
||||||
If no <ssh_identity> is given, the identity is set to \$SSH_DEFAULT_IDENTITY ($SSH_DEFAULT_IDENTITY) configured via Environment.
|
If no <ssh_identity> is given, the identity is set to \$SSH_DEFAULT_IDENTITY ($SSH_DEFAULT_IDENTITY) configured via Environment.
|
||||||
|
@ -121,7 +122,7 @@ logtrace " SSH_IDENTITIES_DIR: $SSH_IDENTITIES_DIR"
|
||||||
[ -z "${SSH_IDENTITIES_DIR-x}" ] || mkdir -vp "$SSH_IDENTITIES_DIR"
|
[ -z "${SSH_IDENTITIES_DIR-x}" ] || mkdir -vp "$SSH_IDENTITIES_DIR"
|
||||||
|
|
||||||
|
|
||||||
agent-start-or-restart () {
|
agent_start_or_restart () {
|
||||||
|
|
||||||
# If DISPLAY is set, ssh-add calls ssh-askpass, and if its in remote-terminal, it wont work
|
# If DISPLAY is set, ssh-add calls ssh-askpass, and if its in remote-terminal, it wont work
|
||||||
# So remember and unset DISPLAY, and set it at the end again, if it was set before
|
# So remember and unset DISPLAY, and set it at the end again, if it was set before
|
||||||
|
@ -146,7 +147,7 @@ agent-start-or-restart () {
|
||||||
logtrace "agentsocket for ${ssh_identity}: $agentsocket"
|
logtrace "agentsocket for ${ssh_identity}: $agentsocket"
|
||||||
if (! $keyonly && ! $tokenonly ) && $remove ; then
|
if (! $keyonly && ! $tokenonly ) && $remove ; then
|
||||||
logdebug "delete keys and tokens in this ssh-agent"
|
logdebug "delete keys and tokens in this ssh-agent"
|
||||||
logdebug "$(ssh-runinagent $agentfile ssh-add -D 2>&1)"
|
logdebug "$(ssh_runinagent $agentfile ssh-add -D 2>&1)"
|
||||||
createonly=true
|
createonly=true
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -183,7 +184,7 @@ agent-start-or-restart () {
|
||||||
|
|
||||||
#logdebug "ssh-agent for identity »$ssh_identity«: $agentfile"
|
#logdebug "ssh-agent for identity »$ssh_identity«: $agentfile"
|
||||||
$createonly && logtrace "current loaded keys after action:
|
$createonly && logtrace "current loaded keys after action:
|
||||||
$(ssh-runinagent $agentfile ssh-add -l)"
|
$(ssh_runinagent $agentfile ssh-add -l)"
|
||||||
echo $agentfile
|
echo $agentfile
|
||||||
ret=0
|
ret=0
|
||||||
else
|
else
|
||||||
|
@ -201,7 +202,7 @@ $(ssh-runinagent $agentfile ssh-add -l)"
|
||||||
logdebug "$(cat $agentfile)"
|
logdebug "$(cat $agentfile)"
|
||||||
logdebug "ssh-agent for identity »$ssh_identity«: $agentfile"
|
logdebug "ssh-agent for identity »$ssh_identity«: $agentfile"
|
||||||
# logdebug "currently loaded keys after action:
|
# logdebug "currently loaded keys after action:
|
||||||
#$(ssh-runinagent $agentfile ssh-add -l)"
|
#$(ssh_runinagent $agentfile ssh-add -l)"
|
||||||
echo $agentfile
|
echo $agentfile
|
||||||
ret=0
|
ret=0
|
||||||
else
|
else
|
||||||
|
@ -217,7 +218,7 @@ $(ssh-runinagent $agentfile ssh-add -l)"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
agent-load-identity-keys () {
|
agent_load_identity_keys () {
|
||||||
|
|
||||||
# If DISPLAY is set, ssh-add calls ssh-askpass, and if its in remote-terminal, it wont work
|
# If DISPLAY is set, ssh-add calls ssh-askpass, and if its in remote-terminal, it wont work
|
||||||
# So remember and unset DISPLAY, and set it at the end again, if it was set before
|
# So remember and unset DISPLAY, and set it at the end again, if it was set before
|
||||||
|
@ -247,7 +248,7 @@ agent-load-identity-keys () {
|
||||||
logtrace "agentsocket: $agentsocket"
|
logtrace "agentsocket: $agentsocket"
|
||||||
logtrace "identitydir: $identitydir"
|
logtrace "identitydir: $identitydir"
|
||||||
|
|
||||||
fingerprints=( $(ssh-runinagent $agentfile "ssh-add -l|awk '{print \$2}'") )
|
fingerprints=( $(ssh_runinagent $agentfile "ssh-add -l|awk '{print \$2}'") )
|
||||||
logdebug "fingerprints from loaded keys before action:"
|
logdebug "fingerprints from loaded keys before action:"
|
||||||
for f in ${fingerprints[*]};do
|
for f in ${fingerprints[*]};do
|
||||||
logdebug "$f"
|
logdebug "$f"
|
||||||
|
@ -261,13 +262,13 @@ agent-load-identity-keys () {
|
||||||
if $readd || $remove ; then
|
if $readd || $remove ; then
|
||||||
$readd && logdebug "re-add key $key"
|
$readd && logdebug "re-add key $key"
|
||||||
$remove && logdebug "remove key $key"
|
$remove && logdebug "remove key $key"
|
||||||
logdebug "$(ssh-runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -d ${key} 2>&1)"
|
logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -d ${key} 2>&1)"
|
||||||
$remove || logdebug "$(ssh-runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} ${key} 2>&1)"
|
$remove || logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} ${key} 2>&1)"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
logdebug "key: $key is not loaded -> load it"
|
logdebug "key: $key is not loaded -> load it"
|
||||||
#logdebug "$(ssh-runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -d ${key} 2>&1)"
|
#logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -d ${key} 2>&1)"
|
||||||
$remove || logdebug "$(ssh-runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} ${key} 2>&1)"
|
$remove || logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} ${key} 2>&1)"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
@ -308,24 +309,24 @@ agent-load-identity-keys () {
|
||||||
|
|
||||||
if [[ ${fingerprints[*]} =~ "$tokenfingerprint" ]]; then
|
if [[ ${fingerprints[*]} =~ "$tokenfingerprint" ]]; then
|
||||||
logdebug "token: $key ($tokenfingerprint) is loaded"
|
logdebug "token: $key ($tokenfingerprint) is loaded"
|
||||||
check-pubkeysonly
|
check_pubkeysonly
|
||||||
if $readd || $remove ; then
|
if $readd || $remove ; then
|
||||||
$readd && logdebug "re-add token $key"
|
$readd && logdebug "re-add token $key"
|
||||||
$remove && logdebug "remove token $key"
|
$remove && logdebug "remove token $key"
|
||||||
echo agentfile1 $agentfile \$SSH_ADD_OPTIONS $key >&2
|
echo agentfile1 $agentfile \$SSH_ADD_OPTIONS $key >&2
|
||||||
logdebug "$(ssh-runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -e "${key}" 2>&1)"
|
logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -e "${key}" 2>&1)"
|
||||||
ssh-runinagent $agentfile echo $SSH_AUTH_SOCK >&2
|
ssh_runinagent $agentfile echo $SSH_AUTH_SOCK >&2
|
||||||
$remove || logdebug "$(ssh-runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -s "${key}" 2>&1)"
|
$remove || logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -s "${key}" 2>&1)"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
logdebug "token: $key is not loaded -> load it"
|
logdebug "token: $key is not loaded -> load it"
|
||||||
logdebug "$(ssh-runinagent $agentfile ssh-add -v ${SSH_ADD_OPTIONS} -e ${key} 2>&1)"
|
logdebug "$(ssh_runinagent $agentfile ssh-add -v ${SSH_ADD_OPTIONS} -e ${key} 2>&1)"
|
||||||
$remove || logdebug "$(ssh-runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -s ${key} 2>&1)"
|
$remove || logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -s ${key} 2>&1)"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
loginfo "currently loaded keys after action: $(ssh-runinagent $agentfile ssh-add -l|wc -l)"
|
loginfo "currently loaded keys after action: $(ssh_runinagent $agentfile ssh-add -l|wc -l)"
|
||||||
logdebug "$(ssh-runinagent $agentfile ssh-add -l)"
|
logdebug "$(ssh_runinagent $agentfile ssh-add -l)"
|
||||||
else
|
else
|
||||||
logwarning "ssh-identity $ssh_identity is not configured. Please create $identitydir and add keys"
|
logwarning "ssh-identity $ssh_identity is not configured. Please create $identitydir and add keys"
|
||||||
fi
|
fi
|
||||||
|
@ -336,10 +337,10 @@ agent-load-identity-keys () {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function check-pubkeysonly () {
|
function check_pubkeysonly () {
|
||||||
if [ ${#pubkeysonly[*]} -gt 0 ] ; then
|
if [ ${#pubkeysonly[*]} -gt 0 ] ; then
|
||||||
for p in ${pubkeysonly[@]}; do
|
for p in ${pubkeysonly[@]}; do
|
||||||
ssh-runinagent $agentfile ssh-add -T ${p} 2>&1 || { $remove || readd=true; break; }
|
ssh_runinagent $agentfile ssh-add -T ${p} 2>&1 || { $remove || readd=true; break; }
|
||||||
done
|
done
|
||||||
else
|
else
|
||||||
logwarning "obviously there is no pubkey for the token in ${SSH_IDENTITIES_DIR}/${ssh_identity}/"
|
logwarning "obviously there is no pubkey for the token in ${SSH_IDENTITIES_DIR}/${ssh_identity}/"
|
||||||
|
@ -352,7 +353,7 @@ function check-pubkeysonly () {
|
||||||
logdebug "readd: $readd"
|
logdebug "readd: $readd"
|
||||||
}
|
}
|
||||||
|
|
||||||
ssh-runinagent () {
|
ssh_runinagent () {
|
||||||
|
|
||||||
|
|
||||||
local agentfile
|
local agentfile
|
||||||
|
@ -375,13 +376,13 @@ ssh-runinagent () {
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ $SSH_TTY || $X2GO_SESSION ]] ; then
|
if [[ $SSH_TTY || $X2GO_SESSION ]] ; then
|
||||||
logdebug "run with forwarded ssh-agent"
|
logdebug "Shell running with forwarded ssh-agent. Please add local token manually"
|
||||||
check_token
|
check_token
|
||||||
res=1
|
res=1
|
||||||
else
|
else
|
||||||
logdebug "run with local ssh-agent"
|
logdebug "run with local ssh-agent"
|
||||||
agent-start-or-restart $ssh_identity
|
agent_start_or_restart $ssh_identity
|
||||||
! $createonly && agent-load-identity-keys $ssh_identity
|
! $createonly && agent_load_identity_keys $ssh_identity
|
||||||
res=0
|
res=0
|
||||||
fi
|
fi
|
||||||
SCRIPTEXIT
|
SCRIPTEXIT
|
||||||
|
|
Loading…
Reference in a new issue