mirror of
https://github.com/tunix/digitalocean-dyndns
synced 2024-12-22 04:49:52 +00:00
Add duplicate DNS record handling
This commit is contained in:
parent
339ad33f39
commit
89fd57cfe8
1 changed files with 19 additions and 4 deletions
23
dyndns.sh
23
dyndns.sh
|
@ -33,20 +33,35 @@ while ( true ); do
|
||||||
ip="$(curl -s $service | grep '[0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{3\}')"
|
ip="$(curl -s $service | grep '[0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{3\}')"
|
||||||
test -n "$ip" && break
|
test -n "$ip" && break
|
||||||
done
|
done
|
||||||
|
|
||||||
echo "Found IP address $ip"
|
echo "Found IP address $ip"
|
||||||
|
|
||||||
if [[ -n $ip ]]; then
|
if [[ -n $ip ]]; then
|
||||||
# disable glob expansion
|
# disable glob expansion
|
||||||
set -f
|
set -f
|
||||||
|
|
||||||
for sub in ${NAME//;/ }; do
|
for sub in ${NAME//;/ }; do
|
||||||
record_id=$(echo $domain_records| jq ".domain_records[] | select(.type == \"A\" and .name == \"$sub\") | .id")
|
record_id=$(echo $domain_records| jq ".domain_records[] | select(.type == \"A\" and .name == \"$sub\") | .id")
|
||||||
record_data=$(echo $domain_records| jq -r ".domain_records[] | select(.type == \"A\" and .name == \"$sub\") | .data")
|
record_data=$(echo $domain_records| jq -r ".domain_records[] | select(.type == \"A\" and .name == \"$sub\") | .data")
|
||||||
|
|
||||||
|
if [ $(echo "$record_id" | wc -l) -ge 2 ]; then :
|
||||||
|
echo "'$sub' domain name has duplicate DNS records, removing duplicates"
|
||||||
|
record_id_to_delete=$(echo "$record_id"| tail -n +1)
|
||||||
|
record_id=$(echo "$record_id"| head -1)
|
||||||
|
record_data=$(echo "$record_data"| head -1)
|
||||||
|
echo "record_id_to_delete = $record_id_to_delete record_id = $record_id record_data = $record_data"
|
||||||
|
|
||||||
|
while IFS= read -r line; do
|
||||||
|
curl -s -X DELETE \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
||||||
|
"$dns_list/$line" &> /dev/null
|
||||||
|
done <<< "$record_id_to_delete"
|
||||||
|
fi
|
||||||
|
|
||||||
# re-enable glob expansion
|
# re-enable glob expansion
|
||||||
set +f
|
set +f
|
||||||
|
|
||||||
data="{\"type\": \"A\", \"name\": \"$sub\", \"data\": \"$ip\"}"
|
data="{\"type\": \"A\", \"name\": \"$sub\", \"data\": \"$ip\"}"
|
||||||
url="$dns_list/$record_id"
|
url="$dns_list/$record_id"
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue