mirror of
https://github.com/tunix/digitalocean-dyndns
synced 2024-12-23 05:19:52 +00:00
Compare commits
No commits in common. "9d6d48e00df4a57b596a3b3265a2600d03755a68" and "339ad33f39478af0e5f098d18e24a982d3436f39" have entirely different histories.
9d6d48e00d
...
339ad33f39
2 changed files with 4 additions and 26 deletions
|
@ -16,7 +16,6 @@ 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`)
|
||||
* **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)
|
||||
* **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)
|
||||
|
||||
|
@ -27,7 +26,6 @@ $ docker run -d --name dyndns \
|
|||
-e DOMAIN="yourdomain.com" \
|
||||
-e NAME="subdomain" \
|
||||
-e SLEEP_INTERVAL=2 \
|
||||
-e REMOVE_DUPLICATES="true" \
|
||||
tunix/digitalocean-dyndns
|
||||
```
|
||||
|
||||
|
|
28
dyndns.sh
28
dyndns.sh
|
@ -2,7 +2,6 @@
|
|||
|
||||
api_host="https://api.digitalocean.com/v2"
|
||||
sleep_interval=${SLEEP_INTERVAL:-300}
|
||||
remove_duplicates=${REMOVE_DUPLICATES:-"false"}
|
||||
|
||||
services=(
|
||||
"ifconfig.co"
|
||||
|
@ -34,39 +33,20 @@ while ( true ); do
|
|||
ip="$(curl -s $service | grep '[0-9]\{1,3\}\(\.[0-9]\{1,3\}\)\{3\}')"
|
||||
test -n "$ip" && break
|
||||
done
|
||||
|
||||
|
||||
echo "Found IP address $ip"
|
||||
|
||||
if [[ -n $ip ]]; then
|
||||
# disable glob expansion
|
||||
set -f
|
||||
|
||||
|
||||
for sub in ${NAME//;/ }; do
|
||||
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")
|
||||
|
||||
if [ $(echo "$record_id" | wc -l) -ge 2 ]; then :
|
||||
if [[ "${remove_duplicates}" == "true" ]]; then :
|
||||
echo "'$sub' domain name has duplicate DNS records, removing duplicates"
|
||||
record_id_to_delete=$(echo "$record_id"| tail -n +2)
|
||||
record_id=$(echo "$record_id"| head -1)
|
||||
record_data=$(echo "$record_data"| head -1)
|
||||
|
||||
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"
|
||||
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
|
||||
set +f
|
||||
|
||||
|
||||
data="{\"type\": \"A\", \"name\": \"$sub\", \"data\": \"$ip\"}"
|
||||
url="$dns_list/$record_id"
|
||||
|
||||
|
|
Loading…
Reference in a new issue