#!/bin/sh # /usr/lib/ddns/dynamic_dns_updater.sh # #.Distributed under the terms of the GNU General Public License (GPL) version 2.0 # Original written by Eric Paul Bishop, January 2008 # (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 #.2014-2016 Christian Schoenebeck # # 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 . $(dirname $0)/dynamic_dns_functions.sh # global vars are also defined here [ $# -lt 1 -o -n "${2//[0-3]/}" -o ${#2} -gt 1 ] && { local __ME=$(basename $0) cat << EOF ddns-scripts Version: $VERSION Usage: $__ME -V display version and exit $__ME --version display version and exit $__ME
service section as defined in /etc/config/ddns '0' NO output to console '1' output to console '2' output to console AND logfile + run once WITHOUT retry on error '3' output to console AND logfile + run once WITHOUT retry on error + NOT sending update to DDNS service EOF exit 1 } [ "$1" = "-V" -o "$1" = "--version" ] && { printf %s\\n "ddns-scripts $VERSION" exit 0 } 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