#!/bin/sh # /usr/lib/ddns/dynamic_dns_updater.sh # # Original written by Eric Paul Bishop, January 2008 # Distributed under the terms of the GNU General Public License (GPL) version 2.0 # (Loosely) based on the script on the one posted by exobyte in the forums here: # http://forum.openwrt.org/viewtopic.php?id=14040 # # extended and partial rewritten in August 2014 # by Christian Schoenebeck # to support: # - IPv6 DDNS services # - DNS Server to retrieve registered IP including TCP transport (Ticket 7820) # - Proxy Server to send out updates # - force_interval=0 to run once (Luci Ticket 538) # - the usage of BIND's host command instead of BusyBox's nslookup if installed # - extended Verbose Mode and log file support for better error detection # - wait for interface to fully come up, before the first update is done # # variables in small chars are read from /etc/config/ddns # variables in big chars are defined inside these scripts as global vars # variables in big chars beginning with "__" are local defined inside functions only #set -vx #script debugger [ $# -lt 1 -o -n "${2//[0-3]/}" -o ${#2} -gt 1 ] && { echo -e "\n USAGE:" echo -e " $0 [SECTION] [VERBOSE_MODE]\n" echo " [SECTION] - service section as defined in /etc/config/ddns" echo " [VERBOSE_MODE] - '0' NO output to console" echo " '1' output to console" echo " '2' output to console AND logfile" echo " + run once WITHOUT retry on error" echo " '3' output to console AND logfile" echo " + run once WITHOUT retry on error" echo -e " + NOT sending update to DDNS service\n" exit 1 } . /usr/lib/ddns/dynamic_dns_functions.sh # global vars are also defined here SECTION_ID="$1" VERBOSE_MODE=${2:-1} # default mode is log to console # set file names PIDFILE="$RUNDIR/$SECTION_ID.pid" # Process ID file UPDFILE="$RUNDIR/$SECTION_ID.update" # last update successful send (system uptime) DATFILE="$RUNDIR/$SECTION_ID.dat" # save stdout data of WGet and other extern programs called ERRFILE="$RUNDIR/$SECTION_ID.err" # save stderr output of WGet and other extern programs called LOGFILE="$LOGDIR/$SECTION_ID.log" # log file # VERBOSE_MODE > 1 delete logfile if exist to create an empty one # only with this data of this run for easier diagnostic # new one created by write_log function [ $VERBOSE_MODE -gt 1 -a -f $LOGFILE ] && rm -f $LOGFILE # TRAP handler trap "trap_handler 0 \$?" 0 # handle script exit with exit status trap "trap_handler 1" 1 # SIGHUP Hangup / reload config trap "trap_handler 2" 2 # SIGINT Terminal interrupt trap "trap_handler 3" 3 # SIGQUIT Terminal quit #trap "trap_handler 9" 9 # SIGKILL no chance to trap trap "trap_handler 15" 15 # SIGTERM Termination ################################################################################ # Leave this comment here, to clearly document variable names that are expected/possible # Use load_all_config_options to load config options, which is a much more flexible solution. # # config_load "ddns" # config_get $SECTION_ID