From 9d294e2d883a5d825edafd9a71f2579440a5cdd4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakobus=20Sch=C3=BCrz?= Date: Tue, 11 Oct 2022 14:50:18 +0200 Subject: [PATCH] change function-names from xx-xx to xx_xx --- bin/startagent | 51 +++++++++++++++++++++++++------------------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/bin/startagent b/bin/startagent index 2859587..2cd0a47 100755 --- a/bin/startagent +++ b/bin/startagent @@ -1,13 +1,14 @@ #!/bin/bash FILELOGLEVEL=DEBUG +. $(dirname $0)/../logging # loggerfactory LANG=C usage(){ cat << EOF - Usage: ssh-agent-start-or-restart [[-c]|[--create-only]]|[[-t]|[--token-only]]|[[-k]|[--key-only]]|[[-r]|[-f]|[--readd]|[--force]] [] + Usage: $(basename $0) [[-c]|[--create-only]]|[[-t]|[--token-only]]|[[-k]|[--key-only]]|[[-r]|[-f]|[--readd]|[--force]] [] If started only with , the script looks up in configured identity-path \$SSH_IDENTITIES_DIR (${SSH_IDENTITIES_DIR}) if it can find a directory named after . If no 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" -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 # 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" if (! $keyonly && ! $tokenonly ) && $remove ; then 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 else @@ -183,7 +184,7 @@ agent-start-or-restart () { #logdebug "ssh-agent for identity »$ssh_identity«: $agentfile" $createonly && logtrace "current loaded keys after action: -$(ssh-runinagent $agentfile ssh-add -l)" +$(ssh_runinagent $agentfile ssh-add -l)" echo $agentfile ret=0 else @@ -201,7 +202,7 @@ $(ssh-runinagent $agentfile ssh-add -l)" logdebug "$(cat $agentfile)" logdebug "ssh-agent for identity »$ssh_identity«: $agentfile" # logdebug "currently loaded keys after action: -#$(ssh-runinagent $agentfile ssh-add -l)" +#$(ssh_runinagent $agentfile ssh-add -l)" echo $agentfile ret=0 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 # 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 "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:" for f in ${fingerprints[*]};do logdebug "$f" @@ -261,13 +262,13 @@ agent-load-identity-keys () { if $readd || $remove ; then $readd && logdebug "re-add key $key" $remove && logdebug "remove key $key" - 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)" + 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)" fi else logdebug "key: $key is not loaded -> load it" - #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)" + #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)" fi done fi @@ -308,24 +309,24 @@ agent-load-identity-keys () { if [[ ${fingerprints[*]} =~ "$tokenfingerprint" ]]; then logdebug "token: $key ($tokenfingerprint) is loaded" - check-pubkeysonly + check_pubkeysonly if $readd || $remove ; then $readd && logdebug "re-add token $key" $remove && logdebug "remove token $key" echo agentfile1 $agentfile \$SSH_ADD_OPTIONS $key >&2 - logdebug "$(ssh-runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -e "${key}" 2>&1)" - ssh-runinagent $agentfile echo $SSH_AUTH_SOCK >&2 - $remove || logdebug "$(ssh-runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -s "${key}" 2>&1)" + logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -e "${key}" 2>&1)" + ssh_runinagent $agentfile echo $SSH_AUTH_SOCK >&2 + $remove || logdebug "$(ssh_runinagent $agentfile ssh-add ${SSH_ADD_OPTIONS} -s "${key}" 2>&1)" fi else logdebug "token: $key is not loaded -> load it" - 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)" + 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)" fi done fi - loginfo "currently loaded keys after action: $(ssh-runinagent $agentfile ssh-add -l|wc -l)" - logdebug "$(ssh-runinagent $agentfile ssh-add -l)" + loginfo "currently loaded keys after action: $(ssh_runinagent $agentfile ssh-add -l|wc -l)" + logdebug "$(ssh_runinagent $agentfile ssh-add -l)" else logwarning "ssh-identity $ssh_identity is not configured. Please create $identitydir and add keys" fi @@ -336,10 +337,10 @@ agent-load-identity-keys () { } -function check-pubkeysonly () { +function check_pubkeysonly () { if [ ${#pubkeysonly[*]} -gt 0 ] ; then 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 else 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" } -ssh-runinagent () { +ssh_runinagent () { local agentfile @@ -375,13 +376,13 @@ ssh-runinagent () { } 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 res=1 else logdebug "run with local ssh-agent" - agent-start-or-restart $ssh_identity - ! $createonly && agent-load-identity-keys $ssh_identity + agent_start_or_restart $ssh_identity + ! $createonly && agent_load_identity_keys $ssh_identity res=0 fi SCRIPTEXIT