From bfc82285044ab9e864dfa3a80ad3e56617611950 Mon Sep 17 00:00:00 2001 From: Eddict Date: Sun, 25 Feb 2024 21:37:04 +0100 Subject: [PATCH] shellcheck improvements --- deploy/directadmin.sh | 22 +++++++++------------- deploy/eddict.sh | 7 +++++++ dnsapi/dns_da_ef.sh | 36 ++++++++++++++++++------------------ 3 files changed, 34 insertions(+), 31 deletions(-) diff --git a/deploy/directadmin.sh b/deploy/directadmin.sh index bb7a6c1d91..cb2d19b35d 100644 --- a/deploy/directadmin.sh +++ b/deploy/directadmin.sh @@ -74,9 +74,8 @@ _da_get_api() { data=$2 domain=$3 _debug "$domain; $data" - response=$(_get "$DA_Api/$cmd?$data") - - if [ "$?" != "0" ]; then + + if ! response=$(_get "$DA_Api/$cmd?$data"); then _err "error $cmd" return 1 fi @@ -129,7 +128,6 @@ _DA_setSSL() { fi fi - curData="domain=${_cdomain}&view=cacert&json=yes" _debug "Calling _DA_da_get_api_getSSL: '${curData}' '${DA_Api}/CMD_API_SSL'" _da_get_api CMD_API_SSL "${curData}" "${_cdomain}" @@ -162,8 +160,8 @@ _DA_setSSL() { if [ "$cacert_flat" != "$cca_flat" ]; then sameCaCert=0 -# cat <<< $cacert > ~/cacert.txt -# cat <<< $cca > ~/_cca.txt + # cat <<< $cacert > ~/cacert.txt + # cat <<< $cca > ~/_cca.txt _info "Domain '${_cdomain}' is using $(__red 'a different') CA certificate." else _info "Domain '${_cdomain}' is using the same CA certificate." @@ -176,7 +174,6 @@ _DA_setSSL() { fi fi - name="key" sameKey=1 if _contains "$cert_response" "$name"; then @@ -186,8 +183,8 @@ _DA_setSSL() { if [ "$key_flat" != "$ckey_flat" ]; then sameKey=0 -# cat <<< $key > ~/key.txt -# cat <<< $ckey > ~/_ckey.txt + # cat <<< $key > ~/key.txt + # cat <<< $ckey > ~/_ckey.txt _info "Domain '${_cdomain}' is using $(__red 'a different') private key." else _info "Domain '${_cdomain}' is using the same private key." @@ -200,11 +197,11 @@ _DA_setSSL() { cert="$(echo "$cert_response" | jq -r .$name)" cert_flat="$(echo "$cert" | tr -d '\r' | tr -d '\n')" _debug2 "$name" "$cert" - + if [ "$cert_flat" != "$ccert_flat" ]; then sameCert=0 -# cat <<< $cert > ~/cert.txt -# cat <<< $ccert > ~/_ccert.txt + # cat <<< $cert > ~/cert.txt + # cat <<< $ccert > ~/_ccert.txt _info "Domain '${_cdomain}' is using $(__red 'a different') certificate." else _info "Domain '${_cdomain}' is using the same certificate." @@ -256,4 +253,3 @@ _DA_setSSL() { return 0 } - diff --git a/deploy/eddict.sh b/deploy/eddict.sh index ae4640ea72..a6bfd07394 100644 --- a/deploy/eddict.sh +++ b/deploy/eddict.sh @@ -81,10 +81,17 @@ eddict_deploy() { # https://stackoverflow.com/a/42101141 # needed to call ssh_deploy() in ssh.sh +# shellcheck source-path=SCRIPTDIR . "$(dirname "$0")/deploy/ssh.sh" # needed to call directadmin_deploy() in directadmin.sh +# shellcheck source-path=SCRIPTDIR . "$(dirname "$0")/deploy/directadmin.sh" +# # shellcheck source-path=SCRIPTDIR +# here="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +# . "$here/config.sh" +# . "$here/utils.sh" + #/usr/local/bin/ssh not working #/usr/local/bin/ssh: /lib/libc.so.6: version `GLIBC_2.20' not found (required by /usr/local/bin/ssh) export DEPLOY_SSH_CMD="/usr/bin/ssh -T" diff --git a/dnsapi/dns_da_ef.sh b/dnsapi/dns_da_ef.sh index 882fdc7dec..ed5922ddc3 100644 --- a/dnsapi/dns_da_ef.sh +++ b/dnsapi/dns_da_ef.sh @@ -107,7 +107,7 @@ _da_api() { data=$2 domain=$3 _debug "$domain; $data" -response="$(_post "$data" "$DA_Api/$cmd" "" "POST")" + response="$(_post "$data" "$DA_Api/$cmd" "" "POST")" if [ "$?" != "0" ]; then _err "error $cmd" @@ -116,23 +116,23 @@ response="$(_post "$data" "$DA_Api/$cmd" "" "POST")" _debug response "$response" case "${cmd}" in - CMD_API_DNS_CONTROL) - # Parse the result in general - # error=0&text=Records Deleted&details= - # error=1&text=Cannot View Dns Record&details=No domain provided - err_field="$(_getfield "$response" 1 '&')" - txt_field="$(_getfield "$response" 2 '&')" - details_field="$(_getfield "$response" 3 '&')" - error="$(_getfield "$err_field" 2 '=')" - text="$(_getfield "$txt_field" 2 '=')" - details="$(_getfield "$details_field" 2 '=')" - _debug "error: ${error}, text: ${text}, details: ${details}" - if [ "$error" != "0" ]; then - _err "error $response" - return 1 - fi - ;; - CMD_API_SHOW_DOMAINS) ;; + CMD_API_DNS_CONTROL) + # Parse the result in general + # error=0&text=Records Deleted&details= + # error=1&text=Cannot View Dns Record&details=No domain provided + err_field="$(_getfield "$response" 1 '&')" + txt_field="$(_getfield "$response" 2 '&')" + details_field="$(_getfield "$response" 3 '&')" + error="$(_getfield "$err_field" 2 '=')" + text="$(_getfield "$txt_field" 2 '=')" + details="$(_getfield "$details_field" 2 '=')" + _debug "error: ${error}, text: ${text}, details: ${details}" + if [ "$error" != "0" ]; then + _err "error $response" + return 1 + fi + ;; + CMD_API_SHOW_DOMAINS) ;; esac return 0 }