diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..9472716 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,20 @@ +FROM debian:bookworm + +RUN apt-get update && apt-get install -y ca-certificates + +RUN useradd -m dyndns + +COPY entrypoint.sh /home/dyndns/entrypoint.sh +RUN chmod +x /home/dyndns/entrypoint.sh + +COPY DynDNS /home/dyndns/DynDNS +COPY .env /home/dyndns/.env + +RUN chown -R dyndns:dyndns /home/dyndns +RUN chmod +x /home/dyndns/DynDNS + +USER dyndns + +WORKDIR /home/dyndns + +CMD ["./entrypoint.sh"] \ No newline at end of file diff --git a/DynDNS b/DynDNS index 52a4811..538de2a 100755 Binary files a/DynDNS and b/DynDNS differ diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..503fe0a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,6 @@ +services: + dyndns: + build: + context: . + dockerfile: Dockerfile + restart: always diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 0000000..ce56a36 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +# Function to run the DynDNS update +run_dyndns() { + echo "Running DynDNS update at $(date)" + ./DynDNS +} + +# Then run every 5 minutes +while true; do + run_dyndns + sleep 300 +done diff --git a/publicIp/ip.go b/publicIp/ip.go index e4a4e7f..775c82d 100644 --- a/publicIp/ip.go +++ b/publicIp/ip.go @@ -7,17 +7,20 @@ import ( ) func ReadIp() (string, error) { - ip, err := _readIpFromIpify() - if err == nil { + fmt.Printf("Reading IP address ...\n") + ip, errIpify := _readIpFromIpify() + if errIpify == nil { + fmt.Printf("IP address from ipify: %s\n", ip) return ip, nil } - ip, err = _readIpFromIdentMe() - if err == nil { + ip, errIdentMe := _readIpFromIdentMe() + if errIdentMe == nil { + fmt.Printf("IP address from identme: %s\n", ip) return ip, nil } - return "", fmt.Errorf("error getting IP from all services: %v", err) + return "", fmt.Errorf("error getting IP from all services: %v, %v", errIpify, errIdentMe) } func _readIpFromIpify() (string, error) { @@ -35,6 +38,8 @@ func _readIpFromIpify() (string, error) { return "", fmt.Errorf("error reading IP from ipify: %v", err) } + fmt.Printf("IP address from ipify: %s\n", string(ip)) + return string(ip), nil } @@ -53,5 +58,7 @@ func _readIpFromIdentMe() (string, error) { return "", fmt.Errorf("error reading IP from identme: %v", err) } + fmt.Printf("IP address from identme: %s\n", string(ip)) + return string(ip), nil }