From 6119d7673d5ea561584e5a20a1c0f2933257328c Mon Sep 17 00:00:00 2001 From: linux-insideDE <39219399+linux-insideDE@users.noreply.github.com> Date: Mon, 14 May 2018 22:08:52 +0200 Subject: [PATCH] chnages by shellcheck --- dnsapi/dns_netcup.sh | 79 ++++++++++++++++++++++++-------------------- 1 file changed, 44 insertions(+), 35 deletions(-) diff --git a/dnsapi/dns_netcup.sh b/dnsapi/dns_netcup.sh index 85928e4f..a07e16f8 100644 --- a/dnsapi/dns_netcup.sh +++ b/dnsapi/dns_netcup.sh @@ -1,11 +1,11 @@ #!/usr/bin/env sh - #Requirments: jq +#by linux-insideDE NC_Apikey="${NC_Apikey:-$(_readaccountconf_mutable NC_Apikey)}" NC_Apipw="${NC_Apipw:-$(_readaccountconf_mutable NC_Apipw)}" NC_CID="${NC_CID:-$(_readaccountconf_mutable NC_CID)}" -end=https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON +end="https://ccp.netcup.net/run/webservice/servers/endpoint.php?JSON" client="" dns_netcup_add() { @@ -18,10 +18,11 @@ dns_netcup_add() { txtvalue=$2 tld="" domain="" - exit=0 - for (( i=20; i>0; i--)) - do - tmp=$(cut -d'.' -f$i <<< $fulldomain) + exit=0 + i=20 + while [ "$i" -gt 0 ]; + do + tmp=$(echo "$fulldomain" | cut -d'.' -f$i) if [ "$tmp" != "" ]; then if [ "$tld" = "" ]; then tld=$tmp @@ -30,10 +31,12 @@ dns_netcup_add() { exit=$i break; fi - fi - done + fi + i=$((i - 1)) + done inc="" - for (( i=1; i<($exit); i++)) + i=1 + while [ "$i" -lt "$exit" ]; do if [ "$((exit-1))" = "$i" ]; then inc="$inc$i" @@ -44,12 +47,14 @@ dns_netcup_add() { else inc="$inc$i," fi - fi + fi + i=$((i + 1)) done - tmp=$(cut -d'.' -f$inc <<< $fulldomain) - msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$domain.$tld\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"\", \"hostname\": \"$tmp\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"false\", \"state\": \"yes\"} ]}}}" $end "" "POST") + + tmp=$(echo "$fulldomain" | cut -d'.' -f$inc) + msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$domain.$tld\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"\", \"hostname\": \"$tmp\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"false\", \"state\": \"yes\"} ]}}}" "$end" "" "POST") _debug "$msg" - if [ $(echo $msg | jq -r .status) != "success" ]; then + if [ "$(echo "$msg" | jq -r .status)" != "success" ]; then _err "$msg" return 1 fi @@ -62,10 +67,11 @@ dns_netcup_rm() { txtvalue=$2 tld="" domain="" - exit=0 - for (( i=20; i>0; i--)) + exit=0 + i=20 + while [ "$i" -gt 0 ]; do - tmp=$(cut -d'.' -f$i <<< $fulldomain) + tmp=$(echo "$fulldomain" | cut -d'.' -f$i) if [ "$tmp" != "" ]; then if [ "$tld" = "" ]; then tld=$tmp @@ -75,9 +81,11 @@ dns_netcup_rm() { break; fi fi + i=$((i - 1)) done - inc="" - for (( i=1; i<($exit); i++)) + inc="" + i=1 + while [ "$i" -lt "$exit" ]; do if [ "$((exit-1))" = "$i" ]; then inc="$inc$i" @@ -86,17 +94,18 @@ dns_netcup_rm() { if [ "$inc" = "" ]; then inc="$i," else - inc="$inc$i," - fi - fi + inc="$inc$i," + fi + fi + i=$((i + 1)) done - tmp=$(cut -d'.' -f$inc <<< $fulldomain) + tmp=$(echo "$fulldomain" | cut -d'.' -f$inc) doma="$domain.$tld" - rec=$(getRecords $doma) - ids=$(echo $rec | jq -r ".[]|select(.destination==\"$txtvalue\")|.id") - msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$doma\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"$ids\", \"hostname\": \"$tmp\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"TRUE\", \"state\": \"yes\"} ]}}}" $end "" "POST") + rec=$(getRecords "$doma") + ids=$(echo "$rec" | jq -r ".[]|select(.destination==\"$txtvalue\")|.id") + msg=$(_post "{\"action\": \"updateDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\",\"clientrequestid\": \"$client\" , \"domainname\": \"$doma\", \"dnsrecordset\": { \"dnsrecords\": [ {\"id\": \"$ids\", \"hostname\": \"$tmp\", \"type\": \"TXT\", \"priority\": \"\", \"destination\": \"$txtvalue\", \"deleterecord\": \"TRUE\", \"state\": \"yes\"} ]}}}" "$end" "" "POST") _debug "$msg" - if [ $(echo $msg | jq -r .status) != "success" ]; then + if [ "$(echo "$msg" | jq -r .status)" != "success" ]; then _err "$msg" return 1 fi @@ -104,29 +113,29 @@ dns_netcup_rm() { } login() { - tmp=$(_post '{"action": "login", "param": {"apikey": "'$NC_Apikey'", "apipassword": "'$NC_Apipw'", "customernumber": "'$NC_CID'"}}' $end "" "POST") - sid=$(echo ${tmp} | jq -r .responsedata.apisessionid) + tmp=$(_post "{\"action\": \"login\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apipassword\": \"$NC_Apipw\", \"customernumber\": \"$NC_CID\"}}" "$end" "" "POST") + sid=$(echo "$tmp" | jq -r .responsedata.apisessionid) _debug "$tmp" - if [ $(echo $tmp | jq -r .status) != "success" ]; then + if [ "$(echo "$tmp" | jq -r .status)" != "success" ]; then _err "$tmp" return 1 fi } logout() { - tmp=$(_post '{"action": "logout", "param": {"apikey": "'$NC_Apikey'", "apisessionid": "'$sid'", "customernumber": "'$NC_CID'"}}' $end "" "POST") + tmp=$(_post "{\"action\": \"logout\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\"}}" "$end" "" "POST") _debug "$tmp" - if [ $(echo $tmp | jq -r .status) != "success" ]; then + if [ "$(echo "$tmp" | jq -r .status)" != "success" ]; then _err "$tmp" return 1 fi } getRecords() { - tmp2=$(_post "{\"action\": \"infoDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\", \"domainname\": \"$1\"}}" $end "" "POST") - xxd=$(echo ${tmp2} | jq -r '.responsedata.dnsrecords | .[]') - xcd=$(echo $xxd | sed 's/} {/},{/g') + tmp2=$(_post "{\"action\": \"infoDnsRecords\", \"param\": {\"apikey\": \"$NC_Apikey\", \"apisessionid\": \"$sid\", \"customernumber\": \"$NC_CID\", \"domainname\": \"$1\"}}" "$end" "" "POST") + xxd=$(echo "$tmp2" | jq -r ".responsedata.dnsrecords | .[]") + xcd=$(echo $xxd | sed 's/} {/},{/g') echo "[ $xcd ]" _debug "$tmp2" - if [ $(echo $tmp2 | jq -r .status) != "success" ]; then + if [ "$(echo "$tmp2" | jq -r .status)" != "success" ]; then _err "$tmp2" return 1 fi