feat: api
Some checks failed
/ lint (push) Failing after 41s

This commit is contained in:
Tine 2025-01-03 20:06:20 +01:00
parent 0e6ab847a3
commit 123397c708
Signed by: mentos1386
SSH key fingerprint: SHA256:MNtTsLbihYaWF8j1fkOHfkKNlnN1JQfxEU/rBU8nCGw
2 changed files with 12 additions and 22 deletions

View file

@ -4,15 +4,6 @@
## Default: "" ## Default: ""
## ServiceRestart: dydns ## 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) # The domain your subdomain is registered at. (i.e. foo.com for home.foo.com)
DOMAIN=ingress.tjo.cloud DOMAIN=ingress.tjo.cloud

View file

@ -4,8 +4,7 @@ set -euo pipefail
api_host="https://api.dnsimple.com/v2" api_host="https://api.dnsimple.com/v2"
sleep_interval=${SLEEP_INTERVAL:-300} sleep_interval=${SLEEP_INTERVAL:-300}
remove_duplicates=${REMOVE_DUPLICATES:-"false"} record_ttl=${RECORD_TTL:-600}
record_ttl=${RECORD_TTL:-300}
# Only services with ipv6 supported are listed here. # Only services with ipv6 supported are listed here.
# And are not using cloudflare or similar services # And are not using cloudflare or similar services
@ -38,15 +37,18 @@ configure_record() {
# disable glob expansion # disable glob expansion
set -f set -f
ip=$1 domain_records=$1
type=$2 ip=$2
type=$3
for sub in ${NAME//;/ }; do for sub in ${NAME//;/ }; do
record_id=$(echo "$domain_records" | jq ".data[] | select(.type == \"$type\" and .content == \"$sub\") | .id") 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 .content == \"$sub\") | .content") record_data=$(echo "$domain_records" | jq -r ".data[] | select(.type == \"$type\" and .name == \"$sub\") | .content")
# 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 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)
@ -58,9 +60,6 @@ configure_record() {
-H "Authorization: Bearer $DNSIMPLE_TOKEN" \ -H "Authorization: Bearer $DNSIMPLE_TOKEN" \
"$dns_list/$line" &>/dev/null "$dns_list/$line" &>/dev/null
done <<<"$record_id_to_delete" 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
fi fi
@ -119,14 +118,14 @@ while (true); do
warn "IPv4 wasn't retrieved within allowed interval. Will try $sleep_interval seconds later.." warn "IPv4 wasn't retrieved within allowed interval. Will try $sleep_interval seconds later.."
else else
info "Found IPv4 address $ipv4" info "Found IPv4 address $ipv4"
configure_record "$ipv4" "A" configure_record "$domain_records" "$ipv4" "A"
fi fi
if [[ -z $ipv6 ]]; then if [[ -z $ipv6 ]]; then
warn "IPv6 wasn't retrieved within allowed interval. Will try $sleep_interval seconds later.." warn "IPv6 wasn't retrieved within allowed interval. Will try $sleep_interval seconds later.."
else else
info "Found IPv6 address $ipv6" info "Found IPv6 address $ipv6"
configure_record "$ipv6" "AAAA" configure_record "$domain_records" "$ipv6" "AAAA"
fi fi
sleep "$sleep_interval" sleep "$sleep_interval"