diff --git a/ingress.tjo.cloud/root/etc/default/dyndns b/ingress.tjo.cloud/root/etc/default/dyndns index 5017ab0..11fd19c 100644 --- a/ingress.tjo.cloud/root/etc/default/dyndns +++ b/ingress.tjo.cloud/root/etc/default/dyndns @@ -4,15 +4,6 @@ ## Default: "" ## ServiceRestart: dydns -# 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) -REMOVE_DUPLICATES=true - -# Polling time in seconds. -# (default: 300) -SLEEP_INTERVAL=600 - # The domain your subdomain is registered at. (i.e. foo.com for home.foo.com) DOMAIN=ingress.tjo.cloud diff --git a/ingress.tjo.cloud/root/usr/local/bin/dyndns b/ingress.tjo.cloud/root/usr/local/bin/dyndns index 30cb876..7da10a0 100755 --- a/ingress.tjo.cloud/root/usr/local/bin/dyndns +++ b/ingress.tjo.cloud/root/usr/local/bin/dyndns @@ -4,8 +4,7 @@ set -euo pipefail api_host="https://api.dnsimple.com/v2" sleep_interval=${SLEEP_INTERVAL:-300} -remove_duplicates=${REMOVE_DUPLICATES:-"false"} -record_ttl=${RECORD_TTL:-300} +record_ttl=${RECORD_TTL:-600} # Only services with ipv6 supported are listed here. # And are not using cloudflare or similar services @@ -38,15 +37,18 @@ configure_record() { # disable glob expansion set -f - ip=$1 - type=$2 + domain_records=$1 + ip=$2 + type=$3 for sub in ${NAME//;/ }; do - record_id=$(echo "$domain_records" | jq ".data[] | select(.type == \"$type\" and .content == \"$sub\") | .id") - record_data=$(echo "$domain_records" | jq -r ".data[] | select(.type == \"$type\" and .content == \"$sub\") | .content") + record_id=$(echo "$domain_records" | jq ".data[] | select(.type == \"$type\" and .name == \"$sub\") | .id") + record_data=$(echo "$domain_records" | jq -r ".data[] | select(.type == \"$type\" and .name == \"$sub\") | .content") - if [ "$(echo "$record_id" | wc -l)" -ge 2 ]; then - if [[ "${remove_duplicates}" == "true" ]]; then + # For all subdomains except "any" + # we remove duplicates and only keep one A and AAAA records. + if [[ "${sub}" != "any" ]]; then + 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 +2) record_id=$(echo "$record_id" | head -1) @@ -58,9 +60,6 @@ configure_record() { -H "Authorization: Bearer $DNSIMPLE_TOKEN" \ "$dns_list/$line" &>/dev/null done <<<"$record_id_to_delete" - else - warn "Unable to update '$sub' domain name as it has duplicate DNS records. Set REMOVE_DUPLICATES='true' to remove them." - continue fi fi @@ -119,14 +118,14 @@ while (true); do warn "IPv4 wasn't retrieved within allowed interval. Will try $sleep_interval seconds later.." else info "Found IPv4 address $ipv4" - configure_record "$ipv4" "A" + configure_record "$domain_records" "$ipv4" "A" fi if [[ -z $ipv6 ]]; then warn "IPv6 wasn't retrieved within allowed interval. Will try $sleep_interval seconds later.." else info "Found IPv6 address $ipv6" - configure_record "$ipv6" "AAAA" + configure_record "$domain_records" "$ipv6" "AAAA" fi sleep "$sleep_interval"