Changeset 1971

Show
Ignore:
Timestamp:
10/04/07 20:50:41 (7 months ago)
Author:
anarcat
Message:

add debugging mode (-d) that shows what domains are updated and what wget is doing

do sanity checks on the domain list provided and bail out on the first error

tell wget to be quiet

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • alternc-slavedns/trunk/slavedns

    r1722 r1971  
    99WGETRC=${HOME}/.wgetrc 
    1010WGET=wget 
    11 WGETFLAGS="
     11WGETFLAGS="-q
    1212NAMED="/etc/init.d/bind restart"  
    1313DEFAULTS="defaults.conf" 
    1414DEFAULTSFILE="${CONFDIR}/${DEFAULTS}" 
     15DEBUG=false 
    1516 
    1617for i 
    1718do 
    18     if [ "$i" = "-f" ] 
    19     then 
    20         FORCE=yes 
    21     else 
    22         CONFIGS="${CONFIGS} ${i}" 
    23     fi 
     19    case "$i"  
     20    in 
     21         -f) 
     22             FORCE=yes 
     23             ;; 
     24         -d) 
     25             DEBUG=true 
     26             ;; 
     27         *) 
     28             CONFIGS="${CONFIGS} ${i}" 
     29             ;; 
     30    esac 
    2431done 
    2532 
     
    3542CreateBindConf() { 
    3643    CFILE="$1" 
    37     rm -f ${BINDDIR}/${CFILE} 
     44    # create a new config for this host, in a tempfile 
    3845    while read domain 
    3946    do 
     47      # check if the data is valid, this will also display the domain in debug mode 
     48      if ! echo $domain | grep -i '^\([a-z][a-z0-9]*\.\)*[a-z][a-z0-9]*$' | MaybeCat 
     49      then 
     50          echo invalid domain listing: $domain, skipping file $CFILE >&2 
     51          return 
     52      fi 
    4053      cat >> ${BINDDIR}/${CFILE}.$$ <<EOF 
    4154zone "$domain" { 
     
    6982ResetWgetConf() { 
    7083    mv -f ${WGETRC}.$$ ${WGETRC} 2>/dev/null || rm -f ${WGETRC} 
     84} 
     85 
     86MaybeCat() { 
     87    if $DEBUG 
     88    then 
     89        cat 
     90    else 
     91        cat > /dev/null 
     92    fi 
     93    return 0 
    7194} 
    7295 
     
    105128      rm -f ${CACHEDIR}/${conf}.temp 
    106129      [ "${LOGIN}" ] && SetWgetPass ${LOGIN} ${PASSWORD} 
    107       ${WGET} ${URL} ${WGETFLAGS} -O ${CACHEDIR}/${conf}.temp -t 1 -T ${TIMEOUT} 2>/dev/null 
     130      ${WGET} ${URL} ${WGETFLAGS} -O ${CACHEDIR}/${conf}.temp -t 1 -T ${TIMEOUT} 2>&1 | MaybeCat 
    108131      [ "${LOGIN}" ] && ResetWgetConf 
    109132      if [ -s "${CACHEDIR}/${conf}.temp" ]