mirror of
https://codeberg.org/shm0rt/ddns-pdns-updater.git
synced 2025-07-29 13:39:06 +02:00
init
This commit is contained in:
parent
fda7113382
commit
768bcb7817
4 changed files with 212 additions and 20 deletions
158
ddns-updater.sh
Normal file
158
ddns-updater.sh
Normal file
|
@ -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
|
54
new-structure.md
Normal file
54
new-structure.md
Normal file
|
@ -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
|
|
@ -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
|
|
|
@ -1,10 +0,0 @@
|
||||||
[Unit]
|
|
||||||
Description=Run PowerDNS DDNS update every minute
|
|
||||||
Requires=pdns-ddns.service
|
|
||||||
|
|
||||||
[Timer]
|
|
||||||
OnCalendar=*:*
|
|
||||||
Persistent=true
|
|
||||||
|
|
||||||
[Install]
|
|
||||||
WantedBy=timers.target
|
|
Loading…
Add table
Add a link
Reference in a new issue