Format for shfmt check

Format for shfmt check
This commit is contained in:
jinhill 2020-09-25 16:19:11 +08:00 committed by GitHub
parent 257f63ced6
commit a7c237b7fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -19,98 +19,98 @@ export _ACME_CURL="curl -k -s -c $COOKIE_FILE -b $COOKIE_FILE --dump-header $HTT
# Usage: dns_geos_add _acme-challenge.subdomain.domain.com "XyZ123..." # Usage: dns_geos_add _acme-challenge.subdomain.domain.com "XyZ123..."
dns_geos_add() { dns_geos_add() {
_full_domain=$1 _full_domain=$1
_txt_value=$2 _txt_value=$2
_info "Using DNS-01 GeoScaling hook" _info "Using DNS-01 GeoScaling hook"
_login || return 1 _login || return 1
_get_zone "$_full_domain" || return 1 _get_zone "$_full_domain" || return 1
_debug "zone id \"$_zone_id\" will be used." _debug "zone id \"$_zone_id\" will be used."
body="id=${_zone_id}&name=${_sub_domain}&type=TXT&content=${_txt_value}&ttl=300&prio=0" body="id=${_zone_id}&name=${_sub_domain}&type=TXT&content=${_txt_value}&ttl=300&prio=0"
response=$(_post "$body" "https://www.geoscaling.com/dns2/ajax/add_record.php") response=$(_post "$body" "https://www.geoscaling.com/dns2/ajax/add_record.php")
_debug "add:$response" _debug "add:$response"
if _contains "$response" '"code":"OK"'; then if _contains "$response" '"code":"OK"'; then
_info "TXT record added successfully." _info "TXT record added successfully."
else else
_err "Couldn't add the TXT record." _err "Couldn't add the TXT record."
return 1 return 1
fi fi
_debug2 response "$response" _debug2 response "$response"
return 0 return 0
} }
#-- dns_geos_rm() - Remove TXT record ------------------------------------ #-- dns_geos_rm() - Remove TXT record ------------------------------------
# Usage: dns_geos_rm _acme-challenge.subdomain.domain.com "XyZ123..." # Usage: dns_geos_rm _acme-challenge.subdomain.domain.com "XyZ123..."
dns_geos_rm() { dns_geos_rm() {
_full_domain=$1 _full_domain=$1
_txt_value=$2 _txt_value=$2
_info "Cleaning up after DNS-01 GeoScaling hook" _info "Cleaning up after DNS-01 GeoScaling hook"
_login || return 1 _login || return 1
_get_zone "$_full_domain" || return 1 _get_zone "$_full_domain" || return 1
_debug "zone id \"$_zone_id\" will be used." _debug "zone id \"$_zone_id\" will be used."
# Find the record id to clean # Find the record id to clean
record_id=$(_get_record_id "$_zone_id" "$_full_domain") || return 1; record_id=$(_get_record_id "$_zone_id" "$_full_domain") || return 1;
body="id=${_zone_id}&record_id=${record_id}" body="id=${_zone_id}&record_id=${record_id}"
response=$(_post "$body" "https://www.geoscaling.com/dns2/ajax/delete_record.php") response=$(_post "$body" "https://www.geoscaling.com/dns2/ajax/delete_record.php")
_debug "rm:$response" _debug "rm:$response"
if _contains "$response" '"code":"OK"'; then if _contains "$response" '"code":"OK"'; then
_info "Record removed successfully." _info "Record removed successfully."
else else
_err "Could not clean (remove) up the record. Please go to GEOS administration interface and clean it by hand." _err "Could not clean (remove) up the record. Please go to GEOS administration interface and clean it by hand."
return 1 return 1
fi fi
return 0 return 0
} }
########################## PRIVATE FUNCTIONS ########################### ########################## PRIVATE FUNCTIONS ###########################
#$1:string,$2:char,$ret:count #$1:string,$2:char,$ret:count
_count() { _count() {
echo "$1" | awk -F"$2" '{print NF-1}' echo "$1" | awk -F"$2" '{print NF-1}'
} }
#$1:fullname,eg:_acme-challenge.us.domain.com #$1:fullname,eg:_acme-challenge.us.domain.com
#ret:return root domain,us.domain.com domain.com #ret:return root domain,us.domain.com domain.com
_get_domain() { _get_domain() {
i=2 i=2
c=$(_count "$1" ".") c=$(_count "$1" ".")
while [ $i -le "$c" ]; do while [ $i -le "$c" ]; do
h=$(echo "$1" | cut -d . -f $i-) h=$(echo "$1" | cut -d . -f $i-)
if [ -z "$h" ]; then if [ -z "$h" ]; then
return 1 return 1
fi fi
echo "$h" echo "$h"
i=$(_math "$i" + 1) i=$(_math "$i" + 1)
done done
return 0 return 0
} }
_login() { _login() {
GEOS_Username="${GEOS_Username:-$(_readaccountconf_mutable GEOS_Username)}" GEOS_Username="${GEOS_Username:-$(_readaccountconf_mutable GEOS_Username)}"
GEOS_Password="${GEOS_Password:-$(_readaccountconf_mutable GEOS_Password)}" GEOS_Password="${GEOS_Password:-$(_readaccountconf_mutable GEOS_Password)}"
if [ -z "$GEOS_Username" ] || [ -z "$GEOS_Password" ]; then if [ -z "$GEOS_Username" ] || [ -z "$GEOS_Password" ]; then
GEOS_Username= GEOS_Username=
GEOS_Password= GEOS_Password=
_err "No auth details provided. Please set user credentials using the \$GEOS_Username and \$GEOS_Password environment variables." _err "No auth details provided. Please set user credentials using the \$GEOS_Username and \$GEOS_Password environment variables."
return 1 return 1
fi fi
_saveaccountconf_mutable GEOS_Username "$GEOS_Username" _saveaccountconf_mutable GEOS_Username "$GEOS_Username"
_saveaccountconf_mutable GEOS_Password "$GEOS_Password" _saveaccountconf_mutable GEOS_Password "$GEOS_Password"
username_encoded=$(echo -n "${GEOS_Username}" | _url_encode) username_encoded=$(echo -n "${GEOS_Username}" | _url_encode)
password_encoded=$(echo -n "${GEOS_Password}" | _url_encode) password_encoded=$(echo -n "${GEOS_Password}" | _url_encode)
body="username=${username_encoded}&password=${password_encoded}" body="username=${username_encoded}&password=${password_encoded}"
if ! _post "$body" "https://www.geoscaling.com/dns2/index.php?module=auth"; then if ! _post "$body" "https://www.geoscaling.com/dns2/index.php?module=auth"; then
_err "geoscaling login failed for user $GEOS_Username bad RC from _post" _err "geoscaling login failed for user $GEOS_Username bad RC from _post"
return 1 return 1
fi fi
resp_header=$(grep 'HTTP/2 302' "$HTTP_HEADER") resp_header=$(grep 'HTTP/2 302' "$HTTP_HEADER")
if [ -z "$resp_header" ]; then if [ -z "$resp_header" ]; then
_err "geoscaling login failed for user $GEOS_Username. Check $HTTP_HEADER file" _err "geoscaling login failed for user $GEOS_Username. Check $HTTP_HEADER file"
return 1 return 1
fi fi
return 0 return 0
} }
#$1:full domain name,_acme-challenge.www.domain.com #$1:full domain name,_acme-challenge.www.domain.com
@ -118,30 +118,30 @@ _login() {
# _sub_domain=_acme-challenge.www # _sub_domain=_acme-challenge.www
# _zone_id=xxxxxx # _zone_id=xxxxxx
_get_zone(){ _get_zone(){
response=$(_get "https://www.geoscaling.com/dns2/index.php?module=domains") response=$(_get "https://www.geoscaling.com/dns2/index.php?module=domains")
table=$(echo "$response" | tr -d "\n" | grep -oP "(?<=<table border='0' align='center' cellpadding='10' cellspacing='10' class=\"threecolumns\">).*?(?=</table>)") table=$(echo "$response" | tr -d "\n" | grep -oP "(?<=<table border='0' align='center' cellpadding='10' cellspacing='10' class=\"threecolumns\">).*?(?=</table>)")
items=$(echo "$table" | grep -oP "(?<=<a).*?(?=</a>)") items=$(echo "$table" | grep -oP "(?<=<a).*?(?=</a>)")
domains=$(_get_domain "$1") domains=$(_get_domain "$1")
for d in "${domains[@]}";do for d in "${domains[@]}";do
id=$(echo "$items" | grep -oP "id=[0-9]*.*$d" | cut -d "'" -f 1) id=$(echo "$items" | grep -oP "id=[0-9]*.*$d" | cut -d "'" -f 1)
if [ -n "$id" ]; then if [ -n "$id" ]; then
_sub_domain=${1//.$d/} _sub_domain=${1//.$d/}
_zone_id=${id##*=} _zone_id=${id##*=}
#echo "$_zone_id" #echo "$_zone_id"
return 0 return 0
fi fi
done done
return 1 return 1
} }
#$1:domain id,$2:dns fullname #$1:domain id,$2:dns fullname
_get_record_id(){ _get_record_id(){
response=$(_get "https://www.geoscaling.com/dns2/index.php?module=domain&id=$1") response=$(_get "https://www.geoscaling.com/dns2/index.php?module=domain&id=$1")
id=$(echo "$response" | tr -d "\n" | grep -oP "(?<=<table id='records_table').*?(?=</table>)" | grep -oP "id=\"[0-9]*.name\">$2"|cut -d '"' -f 2) id=$(echo "$response" | tr -d "\n" | grep -oP "(?<=<table id='records_table').*?(?=</table>)" | grep -oP "id=\"[0-9]*.name\">$2"|cut -d '"' -f 2)
if [ -z "$id" ]; then if [ -z "$id" ]; then
_err "DNS record $2 not found." _err "DNS record $2 not found."
return 1 return 1
fi fi
echo "${id%%.*}" echo "${id%%.*}"
return 0 return 0
} }