From af5a652e88887cdc5024e91c24aa60ddc31402b5 Mon Sep 17 00:00:00 2001 From: jinhill Date: Sat, 26 Sep 2020 13:21:03 +0800 Subject: [PATCH] Fixed regex in string array Fixed grep regex in string array. --- dnsapi/dns_geos.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/dnsapi/dns_geos.sh b/dnsapi/dns_geos.sh index 423ff883..3cd8997e 100644 --- a/dnsapi/dns_geos.sh +++ b/dnsapi/dns_geos.sh @@ -1,4 +1,4 @@ -#!/usr/bin/bash +#!/usr/bin/env sh ######################################################################## # GeoScaling hook script for acme.sh # @@ -70,10 +70,11 @@ dns_geos_rm() { _count() { echo "$1" | awk -F"$2" '{print NF-1}' } - -#$1:fullname,eg:_acme-challenge.us.domain.com -#ret:return root domain,us.domain.com domain.com +#Usage: local -a domains=(); _get_domain "_acme-challenge.us.domain.com" domains +#$1:fullname +#$2:return root domain array,us.domain.com domain.com _get_domain() { + local -n arr=$2 #use nameref for indirection i=2 c=$(_count "$1" ".") while [ $i -le "$c" ]; do @@ -81,7 +82,7 @@ _get_domain() { if [ -z "$h" ]; then return 1 fi - echo "$h" + arr+=("$h") i=$(_math "$i" + 1) done return 0 @@ -121,13 +122,15 @@ _get_zone() { response=$(_get "https://www.geoscaling.com/dns2/index.php?module=domains") table=$(echo "$response" | tr -d "\n" | grep -oP "(?<=).*?(?=
)") items=$(echo "$table" | grep -oP "(?<=)") - domains=$(_get_domain "$1") + #_debug "items=$items" + domains=() + _get_domain "$1" domains || return 1 for d in "${domains[@]}"; do id=$(echo "$items" | grep -oP "id=[0-9]*.*$d" | cut -d "'" -f 1) if [ -n "$id" ]; then _sub_domain=${1//.$d/} _zone_id=${id##*=} - #echo "$_zone_id" + _debug "zone_id=$_zone_id" return 0 fi done