diff --git a/plugins/register/ssh.sh b/plugins/register/ssh.sh index fcaaa1c4594bd814cafb5a9ac31b0b85a5939fc5..3c2318bc064b1a030d9d0ce9edfcd08e6f459db5 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 } # --------------------------------------------------------------------------------