#!/bin/sh # # $Id$ # # Point the DNS for a domain to this server (the primary server) # if this server can access the internet. # # This script should be run periodically on the primary host. # # Which DNS records are updated is determined by the ddclient # configuration file (e.g. $HOME/.ddclient..conf). # # You must set the following variables in ~/.checkdns # domain name of A record to redirect # primary public host name of server that should serve domain whenever possible ### # FUNCTIONS if test -f "${HOME}/bin/functions" then . "${HOME}/bin/functions" else echo "${0##/*/}: Cannot find function library, exiting" exit 1 fi ### # CONFIGURATION # defaults debug= quiet= sms=true syslog=true while getopts "c:dq" flag do case $flag in d) debug=true quiet= ;; q) quiet=true debug= ;; *) error "Invalid option -$flag" exit 2 esac done # Read local configuration. if test -f "${HOME}/.checkdns" then . "${HOME}/.checkdns" else error "Cannot find configuration file ${HOME}/.checkdns" exit 1 fi # Configuration file for ddclient. conf=$HOME/.ddclient.$domain.conf ### # INITIALIZATION tmpdir="$(get_temporary_directory)" if test $? -ne 0 then error "Cannot use temporary directory" exit 1 fi trap 'test -f "${tmpfile}" && rm -f ${tmpfile}' EXIT ### # MAIN primaryaddress="$(get_address_of ${primary})" if test $? -eq 0 then debug "Address of primary server for ${domain} is ${primaryaddress}" else error "Cannot get address of primary host ${primary}" exit 1 fi domainaddress="$(get_address_of ${domain})" if test $? -eq 0 then debug "Address of ${domain} is ${domainaddress}" else error "Cannot get address of domain ${domain}" exit 1 fi if test "${domainaddress}" != "${primaryaddress}" then notice "Primary server for ${domain} is up, redirecting to ${primary} (${primaryaddress})" run /usr/sbin/ddclient -file "${conf}" -cache /dev/null -use=ip -ip "${primaryaddress}" if test $? -eq 0 then info "Redirected ${domain} to ${primary}" else error "Error redirecting ${domain} to ${primary}" exit 1 fi else info "Primary server for ${domain} is already in charge, not redirecting" fi