mirror of
https://github.com/tunix/digitalocean-dyndns
synced 2024-12-22 04:49:52 +00:00
Add REMOVE_DUPLICATES env variable
This commit is contained in:
parent
b97eb27a22
commit
3c754751b1
2 changed files with 17 additions and 10 deletions
|
@ -16,6 +16,7 @@ Pick one of the options below using the following settings:
|
||||||
* **DOMAIN:** The domain your subdomain is registered at. (i.e. `foo.com` for `home.foo.com`)
|
* **DOMAIN:** The domain your subdomain is registered at. (i.e. `foo.com` for `home.foo.com`)
|
||||||
* **NAME:** Subdomain to use. (name in A record) (i.e. `home` for `home.foo.com`). Multiple subdomains must be separated by semicolons `;`
|
* **NAME:** Subdomain to use. (name in A record) (i.e. `home` for `home.foo.com`). Multiple subdomains must be separated by semicolons `;`
|
||||||
* **SLEEP_INTERVAL:** Polling time in seconds. (default: 300)
|
* **SLEEP_INTERVAL:** Polling time in seconds. (default: 300)
|
||||||
|
* **REMOVE_DUPLICATES:** If set to `"true"`, removes extra DNS records if more than one A record is found on a subdomain. *Note that if this is not enabled, the script will NOT update subdomains with more than one A record* (default: false)
|
||||||
|
|
||||||
### Docker (Recommended)
|
### Docker (Recommended)
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ $ docker run -d --name dyndns \
|
||||||
-e DOMAIN="yourdomain.com" \
|
-e DOMAIN="yourdomain.com" \
|
||||||
-e NAME="subdomain" \
|
-e NAME="subdomain" \
|
||||||
-e SLEEP_INTERVAL=2 \
|
-e SLEEP_INTERVAL=2 \
|
||||||
|
-e REMOVE_DUPLICATES="true" \
|
||||||
tunix/digitalocean-dyndns
|
tunix/digitalocean-dyndns
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
api_host="https://api.digitalocean.com/v2"
|
api_host="https://api.digitalocean.com/v2"
|
||||||
sleep_interval=${SLEEP_INTERVAL:-300}
|
sleep_interval=${SLEEP_INTERVAL:-300}
|
||||||
|
remove_duplicates=${REMOVE_DUPLICATES:-"false"}
|
||||||
|
|
||||||
services=(
|
services=(
|
||||||
"ifconfig.co"
|
"ifconfig.co"
|
||||||
|
@ -45,6 +46,7 @@ while ( true ); do
|
||||||
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 :
|
if [ $(echo "$record_id" | wc -l) -ge 2 ]; then :
|
||||||
|
if [[ "${remove_duplicates}" == "true" ]]; then :
|
||||||
echo "'$sub' domain name has duplicate DNS records, removing duplicates"
|
echo "'$sub' domain name has duplicate DNS records, removing duplicates"
|
||||||
record_id_to_delete=$(echo "$record_id"| tail -n +2)
|
record_id_to_delete=$(echo "$record_id"| tail -n +2)
|
||||||
record_id=$(echo "$record_id"| head -1)
|
record_id=$(echo "$record_id"| head -1)
|
||||||
|
@ -56,6 +58,9 @@ while ( true ); do
|
||||||
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
-H "Authorization: Bearer $DIGITALOCEAN_TOKEN" \
|
||||||
"$dns_list/$line" &> /dev/null
|
"$dns_list/$line" &> /dev/null
|
||||||
done <<< "$record_id_to_delete"
|
done <<< "$record_id_to_delete"
|
||||||
|
else :
|
||||||
|
echo "Unable to update '$sub' domain name as it has duplicate DNS records. Set REMOVE_DUPLICATES='true' to remove them."
|
||||||
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# re-enable glob expansion
|
# re-enable glob expansion
|
||||||
|
|
Loading…
Reference in a new issue