From 97fd399b4d1f2c28452ad1e04f00c70e1950dcb0 Mon Sep 17 00:00:00 2001 From: primal Date: Mon, 26 Jan 2026 15:40:55 -0500 Subject: [PATCH] Refactor DDNS updater: switch to Alpine, support multiple domains - Replace golang base image with alpine for smaller footprint - Add bash/curl dependencies explicitly - Refactor script to support multiple domains via arrays - Improve logging with timestamps and status messages - Simplify docker-compose configuration - Remove obsolete build scripts and env files Co-Authored-By: Claude Opus 4.5 --- Dockerfile | 13 +++++++++---- arg | 2 -- build | 2 -- compose.yaml | 12 ------------ ddns.bash | 42 +++++++++++++++++++++++++++++------------- docker-compose.yml | 11 +++++++++++ env | 2 -- 7 files changed, 49 insertions(+), 35 deletions(-) delete mode 100644 arg delete mode 100755 build delete mode 100644 compose.yaml create mode 100644 docker-compose.yml delete mode 100644 env diff --git a/Dockerfile b/Dockerfile index bdf5d5e..a58c4a4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,9 @@ -FROM golang:latest -WORKDIR /root -ADD ddns.bash . -CMD [ "/root/ddns.bash" ] +FROM alpine:latest + +RUN apk add --no-cache bash curl + +WORKDIR /app +COPY ddns.bash . +RUN chmod +x ddns.bash + +CMD ["./ddns.bash"] diff --git a/arg b/arg deleted file mode 100644 index b28271c..0000000 --- a/arg +++ /dev/null @@ -1,2 +0,0 @@ -PROJECT=apps -SERVICE=ddns diff --git a/build b/build deleted file mode 100755 index e1e506a..0000000 --- a/build +++ /dev/null @@ -1,2 +0,0 @@ -docker pull golang:latest -docker build -t primal/ddns . diff --git a/compose.yaml b/compose.yaml deleted file mode 100644 index 6d98185..0000000 --- a/compose.yaml +++ /dev/null @@ -1,12 +0,0 @@ -networks: - ddns: - -services: - ddns: - build: . - env_file: - - env - hostname: apps_ddns - image: ${IMAGE}:${VERSION} - networks: - - ddns diff --git a/ddns.bash b/ddns.bash index 8aa353b..ac061db 100755 --- a/ddns.bash +++ b/ddns.bash @@ -1,16 +1,32 @@ #!/bin/bash -DOMN=primal.host -PASS=35f5fa4e1fc04d539260a4afaeb42371 \ -IP0='' +# Namecheap Dynamic DNS Updater +# https://www.namecheap.com/support/knowledgebase/article.aspx/29/11/how-to-dynamically-update-the-hosts-ip-with-an-https-request/ + +declare -a domains + domains=( "primal.host" ) +declare -a ipAddrs + ipAddrs=( "0.0.0.0" ) +declare -a passwords + passwords=( "4e6b91f434284c6d9261d5779b1d560f" ) + while true ; do - IP1=$(curl --no-progress-meter 'https://api.ipify.org?format=text') - if [[ "${IP1}" != "${IP0}" && "${IP1}" != '' ]] ; then - OP0=$(curl --no-progress-meter -X GET -d 'host=@' -d "domain=${DOMN}" -d "password=${PASS}" -d "ip=${IP1}" -G 'https://dynamicdns.park-your-domain.com/update') - OP1=$(curl --no-progress-meter -X GET -d 'host=*' -d "domain=${DOMN}" -d "password=${PASS}" -d "ip=${IP1}" -G 'https://dynamicdns.park-your-domain.com/update') - echo $(date) ${IP0} ${IP1} - IP0=${IP1} - else - echo $(date) ${IP0} ${IP1} . - fi - sleep 3661 + ipPublic=$(curl --no-progress-meter 'https://api.ipify.org?format=text') + echo "$(date '+%Y-%m-%d %H:%M:%S') Public IP: ${ipPublic}" + for i in ${!domains[@]} ; do + domain=${domains[$i]} + ipAddr=${ipAddrs[$i]} + password=${passwords[$i]} + if [[ "$ipPublic" != "$ipAddr" ]] ; then + for host in '@' '*' ; do + response="$(curl --no-progress-meter -G -d "host=$host" -d "domain=$domain" -d "password=$password" -d "ip=$ipPublic" https://dynamicdns.park-your-domain.com/update)" + if [[ $(echo $response | grep -c "0" -) -ne 1 ]] ; then + echo " ERROR updating ${host}.${domain}: $response" + else + ipAddrs[${i}]="$ipPublic" + echo " Updated ${host}.${domain} -> ${ipPublic}" + fi + done + fi + done + sleep 3600 done diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..25a00c0 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,11 @@ +services: + ddns: + build: . + container_name: ddns + restart: unless-stopped + networks: + - proxy + +networks: + proxy: + external: true diff --git a/env b/env deleted file mode 100644 index 5ed6d11..0000000 --- a/env +++ /dev/null @@ -1,2 +0,0 @@ -VERSION=v1.0.0 -IMAGE=gitea.primal.host/wehrv/ddns