Browse Source

cleanup according to styleguide / ShellCheck

pull/2843/head
der-berni 5 years ago
committed by GitHub
parent
commit
da7b1fb014
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 13
      dnsapi/dns_one.sh

13
dnsapi/dns_one.sh

@ -7,6 +7,9 @@
# Fixed by: @der-berni # Fixed by: @der-berni
# Modified: 2020-04-07 # Modified: 2020-04-07
# #
# Use ONECOM_KeepCnameProxy to keep the CNAME DNS record
# export ONECOM_KeepCnameProxy="1"
#
# export ONECOM_User="username" # export ONECOM_User="username"
# export ONECOM_Password="password" # export ONECOM_Password="password"
# #
@ -56,14 +59,14 @@ dns_one_add() {
#Check if the TXT exists #Check if the TXT exists
_dns_one_getrecord "TXT" "$subdomain" "$txtvalue" _dns_one_getrecord "TXT" "$subdomain" "$txtvalue"
if [ ! -z "$id" ]; then
if [ -n "$id" ]; then
_info "$(__green "Txt record with the same value found. Skip adding.")" _info "$(__green "Txt record with the same value found. Skip adding.")"
return 0 return 0
fi fi
_dns_one_addrecord "TXT" "$subdomain" "$txtvalue" _dns_one_addrecord "TXT" "$subdomain" "$txtvalue"
if [ -z "$id" ]; then if [ -z "$id" ]; then
_err "Add CNAME record error."
_err "Add TXT record error."
return 1 return 1
else else
_info "$(__green "Added, OK ($id)")" _info "$(__green "Added, OK ($id)")"
@ -103,7 +106,7 @@ dns_one_rm() {
else else
#Check if the CNAME exists #Check if the CNAME exists
_dns_one_getrecord "CNAME" "$_sub_domain" "$subdomain.$maindomain" _dns_one_getrecord "CNAME" "$_sub_domain" "$subdomain.$maindomain"
if [ ! -z "$id" ]; then
if [ -n "$id" ]; then
_info "$(__red "Removing CNAME Proxy record: '$(__green "\"$_sub_domain\" => \"$subdomain.$maindomain\"")'")" _info "$(__red "Removing CNAME Proxy record: '$(__green "\"$_sub_domain\" => \"$subdomain.$maindomain\"")'")"
_dns_one_delrecord "$id" _dns_one_delrecord "$id"
fi fi
@ -118,7 +121,6 @@ dns_one_rm() {
fi fi
# delete entry # delete entry
if _dns_one_delrecord "$id"; then if _dns_one_delrecord "$id"; then
_info "$(__green Removed, OK)" _info "$(__green Removed, OK)"
return 0 return 0
@ -162,6 +164,7 @@ _dns_one_login() {
# get credentials # get credentials
ONECOM_KeepCnameProxy="${ONECOM_KeepCnameProxy:-$(_readaccountconf_mutable ONECOM_KeepCnameProxy)}" ONECOM_KeepCnameProxy="${ONECOM_KeepCnameProxy:-$(_readaccountconf_mutable ONECOM_KeepCnameProxy)}"
ONECOM_KeepCnameProxy="${ONECOM_KeepCnameProxy:-0}"
ONECOM_User="${ONECOM_User:-$(_readaccountconf_mutable ONECOM_User)}" ONECOM_User="${ONECOM_User:-$(_readaccountconf_mutable ONECOM_User)}"
ONECOM_Password="${ONECOM_Password:-$(_readaccountconf_mutable ONECOM_Password)}" ONECOM_Password="${ONECOM_Password:-$(_readaccountconf_mutable ONECOM_Password)}"
if [ -z "$ONECOM_User" ] || [ -z "$ONECOM_Password" ]; then if [ -z "$ONECOM_User" ] || [ -z "$ONECOM_Password" ]; then
@ -173,6 +176,7 @@ _dns_one_login() {
fi fi
#save the api key and email to the account conf file. #save the api key and email to the account conf file.
_saveaccountconf_mutable ONECOM_KeepCnameProxy "$ONECOM_KeepCnameProxy"
_saveaccountconf_mutable ONECOM_User "$ONECOM_User" _saveaccountconf_mutable ONECOM_User "$ONECOM_User"
_saveaccountconf_mutable ONECOM_Password "$ONECOM_Password" _saveaccountconf_mutable ONECOM_Password "$ONECOM_Password"
@ -225,7 +229,6 @@ _dns_one_getrecord() {
id=$(printf -- "%s" "$response" | sed -n "s/.*{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"${name}\",\"type\":\"${type}\",\"content\":\"${value}\",\"priority\":0,\"ttl\":600}.*/\1/p") id=$(printf -- "%s" "$response" | sed -n "s/.*{\"type\":\"dns_custom_records\",\"id\":\"\([^\"]*\)\",\"attributes\":{\"prefix\":\"${name}\",\"type\":\"${type}\",\"content\":\"${value}\",\"priority\":0,\"ttl\":600}.*/\1/p")
fi fi
if [ -z "$id" ]; then if [ -z "$id" ]; then
_err "Record not found."
return 1 return 1
fi fi
return 0 return 0

Loading…
Cancel
Save