Skip to content

Commit 1a567ab

Browse files
committed
ddns-scripts: add multiple DNS records support for aliyun ddns
Added logic to extract and match DNS record ID from parameters, with fallback to default selection if no match is found.
1 parent e367c1d commit 1a567ab

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

net/ddns-scripts/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ include $(TOPDIR)/rules.mk
88

99
PKG_NAME:=ddns-scripts
1010
PKG_VERSION:=2.8.2
11-
PKG_RELEASE:=83
11+
PKG_RELEASE:=84
1212

1313
PKG_LICENSE:=GPL-2.0
1414

net/ddns-scripts/files/usr/lib/ddns/update_aliyun_com.sh

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,52 @@ json_get_var __RECORD_COUNT TotalCount
113113
# select the first DNS record
114114
json_select DomainRecords
115115
json_select Record
116-
json_select 1
117-
# get the record id of the first DNS record
118-
json_get_var __RECORD_ID RecordId
119-
json_get_var __RECORD_VALUE Value
116+
# Log the original parameter
117+
write_log 7 "param_enc: `echo ${param_enc}`"
118+
paramEnc=${param_enc}
119+
120+
# Initialize variables
121+
specRecordId=""
122+
found_match=false
123+
124+
# Extract RecordId from parameters
125+
if [ -n "$(echo "${paramEnc}" | grep RecordId)" ]; then
126+
specRecordId=$(echo "$paramEnc" | grep -o 'RecordId=[^&]*' | cut -d'=' -f2)
127+
fi
128+
129+
# If RecordId is successfully extracted, try to match it
130+
if [ -n "$specRecordId" ]; then
131+
write_log 7 "specRecordId: ${specRecordId}"
132+
idx=1
133+
while json_is_a $idx object
134+
do
135+
json_select $idx
136+
json_get_var tmp RecordId
137+
write_log 7 "The $idx Domain RecordId: ${tmp}"
138+
if [ "$tmp" = "$specRecordId" ]; then
139+
__RECORD_ID=$specRecordId
140+
json_get_var __RECORD_VALUE Value
141+
write_log 7 "The $idx Domain Record Value: ${__RECORD_VALUE}"
142+
found_match=true
143+
break
144+
fi
145+
idx=$((idx+1))
146+
json_select ..
147+
done
148+
fi
149+
150+
# Fallback to default logic if no match found
151+
if [ "$found_match" = false ]; then
152+
write_log 7 "Using default logic to select record"
153+
# If multiple records are found, only use the first one
154+
if [ "$__RECORD_COUNT" -gt 1 ]; then
155+
write_log 4 "WARNING: found multiple records of $__HOST, only use the first one"
156+
fi
157+
json_select 1
158+
# Get the record id of the first DNS record
159+
json_get_var __RECORD_ID RecordId
160+
json_get_var __RECORD_VALUE Value
161+
fi
120162

121163
# dont update if the ip has not changed
122164
[ "$__RECORD_VALUE" = "$__IP" ] && {

0 commit comments

Comments
 (0)