From 768bcb7817435956996c6e2dec4ffad3733bcdfb Mon Sep 17 00:00:00 2001 From: shm0rt Date: Thu, 10 Jul 2025 17:25:17 +0200 Subject: [PATCH] init --- ddns-updater.sh | 158 ++++++++++++++++++++++++++++++++++++++++++++++ new-structure.md | 54 ++++++++++++++++ pdns-ddns.service | 10 --- pdns-ddns.timer | 10 --- 4 files changed, 212 insertions(+), 20 deletions(-) create mode 100644 ddns-updater.sh create mode 100644 new-structure.md delete mode 100644 pdns-ddns.service delete mode 100644 pdns-ddns.timer diff --git a/ddns-updater.sh b/ddns-updater.sh new file mode 100644 index 0000000..32edc8b --- /dev/null +++ b/ddns-updater.sh @@ -0,0 +1,158 @@ +#!/usr/bin/env sh + +# ════════════════════════════════════════════════════════════════════════════ +# FUNCTIONS (Must be defined before use!) +# ════════════════════════════════════════════════════════════════════════════ +show_help() { + cat << EOF +update-ddns - Dynamic DNS updater for PowerDNS and Infomaniak + +USAGE: + update-ddns [OPTIONS] + +OPTIONS: + -h, --help Show this help message + -v, --verbose Enable verbose output (debug messages) + -f, --force Force update even if IP hasn't changed + --config-file FILE Use custom config file (default: /etc/update-ddns.conf) + --list-changes + +FILES: + /etc/update-ddns.conf Configuration file + /var/lib/update-ddns/ State and history files + +EOF +} + +log() { + local level="$1" + local message="$2" + + case "$level" in + "info") + echo "[INFO] $message" + ;; + "warning") + echo "[WARNING] $message" >&2 + ;; + "error") + echo "[ERROR] $message" >&2 + exit 1 + ;; + "debug") + [ "$VERBOSE" = "1" ] && echo "[DEBUG] $message" + ;; + esac +} + +# ════════════════════════════════════════════════════════════════════════════ +# COMMAND LINE PARSING +# ════════════════════════════════════════════════════════════════════════════ + +# Default values +VERBOSE=0 +FORCE=0 +CONFIG_FILE="/etc/update-ddns.conf" +HISTORY_FILE="/var/lib/update-ddns/ip.history" + +# Parse command line arguments +while [ $# -gt 0 ]; do + case "$1" in + --help|-h) + show_help + exit 0 + ;; + --config-file) + shift + if [ -z "$1" ]; then + log error "--config-file requires a filename" + fi + CONFIG_FILE="$1" + ;; + --verbose|-v) + VERBOSE=1 + ;; + --force|-f) + FORCE=1 + ;; + --list-changes) + shift + lines="${1:-5}" + + if [ ! -f "$HISTORY_FILE" ]; then + log error "History file not found" + exit 1 + fi + + # Validate number + case "$lines" in + ''|*[!0-9]*) lines=5 ;; + esac + + echo "Last "$lines" IP changes:" + tail -n "$lines" "$HISTORY_FILE" + exit 0 + ;; + *) + echo "Unknown option: $1" + echo "Use --help or -h for usage information" + exit 1 + ;; + esac + shift +done + +# ════════════════════════════════════════════════════════════════════════════ +# CHECK DEPENDENCIES & FILES +# ════════════════════════════════════════════════════════════════════════════ +# cron, curl, wget, pdnsutil, sh, dig +# (-v --version) +check_dependencies() { + +} +check_files() { + +} + + +# ════════════════════════════════════════════════════════════════════════════ +# CHECK FOR ACCESS DIR AND ACCESS FILES AND CREATE IF NOT CREATED (POPULATE) +# ════════════════════════════════════════════════════════════════════════════ +# config +# init_function + + +# ════════════════════════════════════════════════════════════════════════════ +# IP CHANGE DETECTION +# ════════════════════════════════════════════════════════════════════════════ +# check_infomaniak_ip +# providers: cloudflare, quad9, google, amazon, opendns, akamai +# check_for_ip_change +# check_infomaniak_zone +# check_pdns_zones +check_for_ip_change() { + +} + +# ════════════════════════════════════════════════════════════════════════════ +# UPDATE IP +# ════════════════════════════════════════════════════════════════════════════ +# update_infomaniak_ip +# update_infomaniak_zone +# update_pdns_zones + + +# ════════════════════════════════════════════════════════════════════════════ +# MAIN EXECUTION +# ════════════════════════════════════════════════════════════════════════════ +main() { + log info "Starting update-ddns" + check_dependencies + check_files + check_for_ip_change +} + + + + +main diff --git a/new-structure.md b/new-structure.md new file mode 100644 index 0000000..e4d6191 --- /dev/null +++ b/new-structure.md @@ -0,0 +1,54 @@ +# Pdns-ddns +## check dependencies: +- cron +- curl +- wget +- pdnsutil +(- pdnscontrol) +- sh +- dig +- syslog +(-v --version) + +## check for access dir and access files and create if not created (populate) +config +init_function + +## parameter +--help|-h +--config-file +--verbose|-v +--force|-f + + +## logging functions +info, error, warnings + +## ip change detection +check_infomaniak_ip +providers: cloudflare, quad9, google, amazon, opendns, akamai +check_for_ip_change +check_infomaniak_zone +check_pdns_zones + +## update ip +update_infomaniak_ip +### update infomaniak zone +update_infomaniak_zone +### update powerdns zones +update_pdns_zones + +main + + + + + + + + + +/usr/local/bin/update-ddns # Script +/etc/update-ddns.conf # Config +/var/lib/update-ddns/ip.history # State + History +#### syslog für events diff --git a/pdns-ddns.service b/pdns-ddns.service deleted file mode 100644 index 8c0be62..0000000 --- a/pdns-ddns.service +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=PowerDNS DDNS Updater -After=network.target - -[Service] -Type=oneshot -ExecStart=/usr/local/bin/pdns-ddns -User=root -StandardOutput=journal -StandardError=journal diff --git a/pdns-ddns.timer b/pdns-ddns.timer deleted file mode 100644 index 346d943..0000000 --- a/pdns-ddns.timer +++ /dev/null @@ -1,10 +0,0 @@ -[Unit] -Description=Run PowerDNS DDNS update every minute -Requires=pdns-ddns.service - -[Timer] -OnCalendar=*:* -Persistent=true - -[Install] -WantedBy=timers.target