From 664a39b06a1b1fb467972705391aea81ab91b37c Mon Sep 17 00:00:00 2001 From: "Hahn Axel (hahn)" <axel.hahn@iml.unibe.ch> Date: Fri, 11 Feb 2022 08:50:48 +0100 Subject: [PATCH] fix shellcheck; fix returncode of ssh command --- plugins/register/ssh.sh | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/plugins/register/ssh.sh b/plugins/register/ssh.sh index fcaaa1c..3c2318b 100755 --- a/plugins/register/ssh.sh +++ b/plugins/register/ssh.sh @@ -8,6 +8,7 @@ # ah - Axel Hahn <axel.hahn@iml.unibe.ch> # # 2021-05-31 ah v1.0 first lines +# 2022-02-11 ah v1.1 fix shellcheck; fix returncode of ssh command # ================================================================================ # -------------------------------------------------------------------------------- @@ -19,33 +20,36 @@ # param string action; one of register|unregrister|status # param string hostname; given for register and unregister function _runssh(){ - - sProtocol=`j_getFullTarget "" | cut -f 1 -d ":"` - if [ ${sProtocol} = "rsync" -o ${sProtocol} = "scp" -o ${sProtocol} = "sftp" ]; then + local _rc=0 + sProtocol=$(j_getFullTarget "" | cut -f 1 -d ":") + if [ "${sProtocol}" = "rsync" -o "${sProtocol}" = "scp" -o "${sProtocol}" = "sftp" ]; then - sSshTarget=`j_getFullTarget "" | cut -f 3 -d "/"` - if [ ! -z $sSshTarget ]; then + sSshTarget=$(j_getFullTarget "" | cut -f 3 -d "/") + if [ -n "$sSshTarget" ]; then sSshParams= - sFileSshPrivkey=`_j_getvar ${STORAGEFILE} "ssh-privatekey"` - if [ ! -z $sFileSshPrivkey ]; then + sFileSshPrivkey=$(_j_getvar ${STORAGEFILE} "ssh-privatekey") + if [ -n "$sFileSshPrivkey" ]; then sSshParams="${sSshParams} -i ${sFileSshPrivkey}" fi - sSshCmd=`_j_getvar ${STORAGEFILE} "storage-registercmd"` + sSshCmd=$(_j_getvar "${STORAGEFILE}" "storage-registercmd") if [ -z "$sSshCmd" ]; then echo "WARNING: Missing storage-registercmd = ... in ${STORAGEFILE} for a command to execute via SSH." + _rc=1 else - echo ssh ${sSshParams} ${sSshTarget} ${sSshCmd} $* + echo "ssh ${sSshParams} ${sSshTarget} ${sSshCmd} $*" color cmd ssh ${sSshParams} ${sSshTarget} ${sSshCmd} $* + _rc=$? color reset fi fi else - echo INFO: storage protocol is $sProtocol - skipping register via ssh. + echo "INFO: storage protocol is $sProtocol - skipping register via ssh." fi + return $_rc } # -------------------------------------------------------------------------------- -- GitLab