#!/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 . /usr/lib/ddns/dynamic_dns_functions.sh # global vars are also defined here [ $# -lt 1 -o -n "${2//[0-3]/}" -o ${#2} -gt 1 ] && { echo -e "\n ddns-scripts Version: $VERSION" echo -e "\n USAGE:" echo " $0 [OPTION]" echo " [OPTION] '-V' or '--version' display version and exit" echo -e "\n $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 } [ "$1" = "-V" -o "$1" = "--version" ] && { echo -e "ddns-scripts $VERSION\n" 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