bin/update
changeset 575 b68b8615c512
parent 574 c486df8ea68a
child 577 b474e2e6f54e
equal deleted inserted replaced
574:c486df8ea68a 575:b68b8615c512
     1 #!/bin/bash
     1 #!/bin/bash
     2 # vim: set ft=sh :
     2 # vim: set ft=sh :
     3 
     3 
     4 set -ue
     4 set -ue
     5 
     5 
     6 
     6 # resolve $0 -> bin/update
     7 ### Paths
       
     8 ROOT=$(pwd)
       
     9 
       
    10 # resolve $0
       
    11 self=$0
     7 self=$0
    12 while [ -L $self ]; do
     8 while [ -L $self ]; do
    13     tgt=$(readlink $self)
     9     tgt=$(readlink $self)
    14 
    10 
    15     if [ "${tgt:0:1}" == "/" ]; then
    11     if [ "${tgt:0:1}" == "/" ]; then
    20 done
    16 done
    21 
    17 
    22 # Our bin dir, with scripts
    18 # Our bin dir, with scripts
    23 BIN=$(dirname $self)
    19 BIN=$(dirname $self)
    24 
    20 
    25 # Data files
    21 # code root
       
    22 CODE=$(dirname $BIN)
       
    23 
       
    24 
       
    25 LIB=$CODE/lib
       
    26 
       
    27 ## Data paths
       
    28 # absolute path to data files; can be changed using -d
       
    29 ROOT=$(pwd)
       
    30 
    26 DATA=settings
    31 DATA=settings
    27 ZONES=zones
    32 ZONES=zones
    28 SERIALS=$DATA
    33 SERIALS=$DATA
       
    34 
       
    35 # hg repo to commit
    29 REPO=$DATA
    36 REPO=$DATA
    30 
    37 
    31 # hide files under repo in diff output..
    38 ## Settings used in lib
       
    39 # Hide files under repo in commit diff output..
    32 REPO_HIDE='*.serial'
    40 REPO_HIDE='*.serial'
    33 
    41 
    34 # Script/data args
    42 # XXX: hosts data input charset?
    35 PROCESS_ARGS='--input-charset latin-1'
    43 PROCESS_ARGS='--input-charset latin-1'
    36 
    44 
    37 # external progs
    45 # External bins
    38 NAMED_CHECKZONE=/usr/sbin/named-checkzone
    46 NAMED_CHECKZONE=/usr/sbin/named-checkzone
    39 HG=/usr/bin/hg
    47 HG=/usr/bin/hg
    40 RNDC=/usr/sbin/rndc
    48 RNDC=/usr/sbin/rndc
       
    49 
       
    50 # Path to rndc key, must be readable to run..
    41 RNDC_KEY=/etc/bind/rndc.key
    51 RNDC_KEY=/etc/bind/rndc.key
    42 
    52 
    43 ### Command-line argument handling
    53 ## Library includes
    44 
    54 # Command-line argument handling
    45 IS_TTY=
    55 source $LIB/update.args
    46 
    56 
    47 ## Options
    57 # Logging
    48 LOG_ERROR=y
    58 source $LIB/update.logging
    49 LOG_WARN=y
    59 
    50 LOG=y
    60 # Utility functions
    51 LOG_FORCE=y
    61 source $LIB/update.utils
    52 LOG_UPDATE=y
    62 
    53 LOG_NOOP=y
    63 # Dependency-based updates
    54 LOG_SKIP=
    64 source $LIB/update.updates
    55 LOG_DEBUG=
    65 
    56 LOG_CMD=
    66 # Operations
    57 
    67 source $LIB/update.operations
    58 UPDATE_FORCE=
    68 
    59 UPDATE_NOOP=
       
    60 UPDATE_DIFF=
       
    61 
       
    62 SERIAL_NOOP=
       
    63 SERIAL_FORCE=
       
    64 
       
    65 COMMIT_SKIP=
       
    66 COMMIT_FORCE=
       
    67 COMMIT_MSG=' '
       
    68 
       
    69 DEPLOY_SKIP=
       
    70 
       
    71 ## Output command-line argument help.
       
    72 function help_args {
       
    73     local prog=$1
       
    74 
       
    75     cat <<END
       
    76 Usage: $prog [options]
       
    77 
       
    78 General:
       
    79     -h      display this help text
       
    80     -d DIR  datadir
       
    81 
       
    82 Logging:    
       
    83     -q      quiet
       
    84     -v      verbose
       
    85     -D      debug
       
    86     -V      debug commands
       
    87     
       
    88 Updates:
       
    89     -p      show changes
       
    90     -F      force-updates without checking src mtime
       
    91     -S      do not update serial
       
    92     -s      update serials
       
    93     -n      no-op/mock-update; don't actually change/deploy anything; implies -SpC
       
    94 
       
    95 Commit:
       
    96     -C      do not commit changes
       
    97     -c      commit changes
       
    98     -m MSG  commit message
       
    99 END
       
   100 }
       
   101 
       
   102 ## Parse any command-line arguments, setting the global options vars.
       
   103 function parse_args {
       
   104     OPTIND=1
       
   105 
       
   106     while getopts 'hd:qvDVpFSsnCcm:' opt "$@"; do
       
   107         case $opt in
       
   108             h)  
       
   109                 help_args $0
       
   110                 exit 0
       
   111             ;;
       
   112 
       
   113             d)  ROOT="$OPTARG" ;;
       
   114 
       
   115             q)  
       
   116                 LOG= 
       
   117                 LOG_WARN=
       
   118                 LOG_UPDATE=
       
   119                 LOG_FORCE=
       
   120                 LOG_NOOP=
       
   121                 ;;
       
   122 
       
   123             v)  LOG_SKIP=y ;;
       
   124             D)  
       
   125                 LOG_DEBUG=y
       
   126                 LOG_INFO=y
       
   127                 ;;
       
   128             V)  LOG_CMD=y ;;
       
   129 
       
   130             p)  UPDATE_DIFF=y   ;;
       
   131             F)  UPDATE_FORCE=y  ;;
       
   132             S)  SERIAL_NOOP=y   ;;
       
   133             s)  SERIAL_FORCE=y  ;;
       
   134  
       
   135             n)  
       
   136                 UPDATE_NOOP=y 
       
   137                 # implies -Sp
       
   138                 UPDATE_DIFF=y
       
   139                 SERIAL_NOUPDATE=y
       
   140                 COMMIT_SKIP=y
       
   141                 DEPLOY_SKIP=y
       
   142                 ;;
       
   143 
       
   144             C)  COMMIT_SKIP=y ;;
       
   145             c)  COMMIT_FORCE=y ;;
       
   146             m)  COMMIT_MSG="$OPTARG" ;;
       
   147            
       
   148             ?)  
       
   149                 die 
       
   150             ;;
       
   151         esac
       
   152 
       
   153     done
       
   154 }
       
   155 
       
   156 ### Logging
       
   157 # Output message to stderr.
       
   158 function log_msg {
       
   159     echo "$*" >&2
       
   160 }
       
   161 
       
   162 # Output message to stderr, optionally with given color, if TTY.
       
   163 function log_color {
       
   164     local code=$1; shift
       
   165 
       
   166     if [ $IS_TTY ]; then
       
   167         echo $'\e['${code}'m'"$*"$'\e[00m' >&2
       
   168     else
       
   169         echo "$*" >&2
       
   170     fi
       
   171 }
       
   172 
       
   173 ## Log at various log-levels
       
   174 
       
   175 function log_error {
       
   176     [ $LOG_ERROR ] && log_color '31' "$*"
       
   177 }
       
   178 
       
   179 function log_warn {
       
   180     [ $LOG_WARN ] && log_color '33' "$*" || true
       
   181 }
       
   182 
       
   183 # plain
       
   184 function log {
       
   185     [ $LOG ] && log_msg "$*" || true
       
   186 }
       
   187 
       
   188 function log_force {
       
   189     [ $LOG_FORCE ] && log_color '2;33' "  $*" || true
       
   190 }
       
   191 
       
   192 function log_update {
       
   193     [ $LOG_UPDATE ] && log_color '36' "  $*" || true
       
   194 }
       
   195 
       
   196 function log_noop {
       
   197     [ $LOG_NOOP ] && log_color '2;34' "  $*" || true
       
   198 }
       
   199 
       
   200 function log_skip {
       
   201     [ $LOG_SKIP ] && log_color '1;34' "  $*" || true
       
   202 }
       
   203 
       
   204 function log_debug {
       
   205     [ $LOG_DEBUG ] && log_color 32 "    $*" || true
       
   206 }
       
   207 
       
   208 function log_cmd {
       
   209     [ $LOG_CMD ] && log_color 35 "        \$ $*" || true
       
   210 }
       
   211 
       
   212 # Output stacktrace, broken.
       
   213 function log_stack {
       
   214     local level=1
       
   215 
       
   216     while info=$(caller $level); do
       
   217         echo $info | read line sub file
       
   218 
       
   219         log_msg "$file:$lineno $sub()"
       
   220 
       
   221         level=$(($level + 1))
       
   222     done
       
   223 }
       
   224 
       
   225 # Output calling function's name.
       
   226 function func_caller {
       
   227     caller 1 | cut -d ' ' -f 2
       
   228 }
       
   229 
       
   230 ### High-level logging output
       
   231 # Log with func_caller at log_debug
       
   232 function debug {
       
   233     printf -v prefix "%s" $(func_caller)
       
   234 
       
   235     log_debug "$prefix: $*"
       
   236 }
       
   237 
       
   238 # Log with func_caller at log_error and exit, intended for internal errors...
       
   239 function fail {
       
   240     log_error "$(func_caller): $*"
       
   241 
       
   242     exit 2
       
   243 }
       
   244 
       
   245 # Log at log_error and exit
       
   246 function die {
       
   247     log_error "$*"
       
   248     exit 1
       
   249 }
       
   250 
       
   251 ### Command execution
       
   252 ## Execute command, possibly logging its execution.
       
   253 #
       
   254 #   cmd     $cmd...
       
   255 #
       
   256 # Fails if the command returns an error exit code.
       
   257 function cmd {
       
   258     log_cmd "$@"
       
   259 
       
   260     "$@" || die "Failed"
       
   261 }
       
   262 
       
   263 function indent () {
       
   264     local indent=$1; shift
       
   265 
       
   266     log_cmd "$@"
       
   267 
       
   268     "$@" | sed "s/^/$indent/"
       
   269 
       
   270     return ${PIPESTATUS[0]}
       
   271 }
       
   272 
       
   273 
       
   274 ### FS utils
       
   275 # Create dir in $ROOT if not exists.
       
   276 function ensure_dir {
       
   277     local dir=$1
       
   278 
       
   279     if [ ! -d $ROOT/$dir ]; then
       
   280         log_warn "Creating output dir: $dir"
       
   281         cmd mkdir $ROOT/$dir
       
   282     fi
       
   283 }
       
   284 
       
   285 ## Output absolute path from $ROOT:
       
   286 #
       
   287 #   abspath $path
       
   288 #
       
   289 function abspath () {
       
   290     local path=$1
       
   291 
       
   292     echo "$ROOT/$path"
       
   293 }
       
   294 
       
   295 ### HG wrappers
       
   296 # Run `hg ...` within $REPO.
       
   297 function hg {
       
   298     local repo=$REPO
       
   299 
       
   300     cmd $HG -R $ROOT/$repo "$@"
       
   301 }
       
   302 
       
   303 # Does the repo have local modifications?
       
   304 function hg_modified {
       
   305     hg id | grep -q '+'
       
   306 }
       
   307 
       
   308 # Output possible -u flag for commit.
       
   309 function hg_user {
       
   310     if [ ${SUDO_USER:-} ]; then
       
   311         echo '-u' "$SUDO_USER"
       
   312 
       
   313     elif [ $HOME ] && [ -e $HOME/.hgrc ]; then
       
   314         debug "using .hgrc user"
       
   315         echo ''
       
   316 
       
   317     else
       
   318         echo '-u' "$USER"
       
   319     fi
       
   320 }
       
   321 
       
   322 # Show changes in repo
       
   323 function hg_diff {
       
   324     hg diff -X "$REPO/$REPO_HIDE"
       
   325 }
       
   326 
       
   327 ## Commit changes in repo, with given message:
       
   328 #
       
   329 #   hg_commit   $msg
       
   330 #
       
   331 function hg_commit {
       
   332     local msg=$1
       
   333     local user_opt=$(hg_user)
       
   334     
       
   335     debug "$user_opt: $msg"
       
   336     hg commit $user_opt -m "$msg"
       
   337 }
       
   338 
       
   339 
       
   340 ### Dependency-based updates
       
   341 
       
   342 ## Compare the given output file with all given source files:
       
   343 #
       
   344 #   check_update $out ${deps[@]} && do_update $out ... || ...
       
   345 #
       
   346 # Returns true if the output file needs to be updated.
       
   347 function check_update {
       
   348     # target
       
   349     local out=$1; shift
       
   350 
       
   351     debug "$out"
       
   352 
       
   353     # need update?
       
   354     local update=
       
   355 
       
   356     if [ ${#@} == 0 ]; then
       
   357         debug "  update: unknown deps"
       
   358         update=y
       
   359 
       
   360     elif [ ! -e $out ]; then
       
   361         debug "  update: dest missing"
       
   362         update=y
       
   363         
       
   364     elif [ $UPDATE_FORCE ]; then
       
   365         debug "  update: forced"
       
   366         update=y
       
   367     fi
       
   368 
       
   369     # check deps
       
   370     for dep in "$@"; do
       
   371         # don't bother checking if already figured out
       
   372         [ $update ] && continue
       
   373 
       
   374         # check
       
   375         if [ ! -e $ROOT/$dep ]; then
       
   376             fail "$dst: Missing source: $dep"
       
   377 
       
   378         elif [ $ROOT/$out -ot $ROOT/$dep ]; then
       
   379             debug "  update: $dep"
       
   380             update=y
       
   381         else
       
   382             debug "  check: $dep"
       
   383         fi
       
   384     done
       
   385 
       
   386     [ ! $update ] && debug "  up-to-date"
       
   387 
       
   388     # return
       
   389     [ $update ]
       
   390 }
       
   391 
       
   392 ## Generate updated output file from given command's stdout:
       
   393 #
       
   394 #   do_update $out $BIN/cmd --args
       
   395 #
       
   396 # Writes output to a temporary .new file, optionally shows a diff of changes, and commits
       
   397 # the new version to $out (unless noop'd).
       
   398 function do_update {
       
   399     local out=$1; shift
       
   400     local tmp=$out.new
       
   401 
       
   402     debug "$out"
       
   403     cmd "$@" > $ROOT/$tmp
       
   404 
       
   405     # compare
       
   406     if [ -e $ROOT/$out ] && [ $UPDATE_DIFF ]; then
       
   407         debug "  changes:"
       
   408 
       
   409         # terse
       
   410         indent "        " diff --unified=1 $ROOT/$out $ROOT/$tmp || true
       
   411     fi
       
   412     
       
   413     # deploy
       
   414     if [ $UPDATE_NOOP ]; then
       
   415         # cleanup
       
   416         debug "  no-op"
       
   417 
       
   418         cmd rm $ROOT/$tmp
       
   419     else
       
   420         # commit
       
   421         debug "  deploy"
       
   422 
       
   423         cmd mv $ROOT/$tmp $ROOT/$out
       
   424     fi
       
   425 }
       
   426 
       
   427 ## Look for a link target:
       
   428 #
       
   429 #   find_link   $lnk    $tgt...
       
   430 #
       
   431 # Outputs the first given target to exist, skipping any that are the same as the given $lnk.
       
   432 # If no $tgt matches, outputs the last one, or '-'.
       
   433 function choose_link {
       
   434     local lnk=$1; shift
       
   435     local tgt=-
       
   436 
       
   437     for tgt in "$@"; do
       
   438         [ $tgt != $out ] && [ -e $ROOT/$tgt ] && break
       
   439     done
       
   440     
       
   441     echo $tgt
       
   442 }
       
   443 
       
   444 
       
   445 ## Compare symlink to target:
       
   446 #
       
   447 #   check_link $lnk $tgt && do_link $lnk $tgt || ...
       
   448 #
       
   449 # Tests if the symlink exists, and the target matches.
       
   450 # Fails if the target does not exist.
       
   451 function check_link {
       
   452     local lnk=$1
       
   453     local tgt=$2
       
   454 
       
   455     [ ! -e $ROOT/$tgt ] && fail "$tgt: target does not exist"
       
   456     
       
   457     [ ! -e $ROOT/$lnk ] || [ $(readlink $ROOT/$lnk) != $ROOT/$tgt ]
       
   458 }
       
   459 
       
   460 ## Update symlink to point to target:
       
   461 #
       
   462 #   do_link $lnk $tgt
       
   463 #
       
   464 function do_link {
       
   465     local lnk=$1
       
   466     local tgt=$2
       
   467 
       
   468     cmd ln -sf $ROOT/$tgt $ROOT/$lnk
       
   469 }
       
   470 
       
   471 ## Update .serial number:
       
   472 #
       
   473 #   do_update_serial $serial
       
   474 #
       
   475 # Shows old/new serial on debug.
       
   476 function do_update_serial {
       
   477     local serial=$1
       
   478 
       
   479     # read
       
   480     local old=$(test -e $ROOT/$serial && cat $ROOT/$serial || echo '')
       
   481 
       
   482 
       
   483     cmd $BIN/update-serial $ROOT/$serial
       
   484     
       
   485     # read
       
   486     local new=$(cat $ROOT/$serial)
       
   487         
       
   488     debug "  $old -> $new"
       
   489 }
       
   490 
       
   491 ## Perform `hg commit` for $DATA
       
   492 function do_commit {
       
   493     local msg=$1
       
   494 
       
   495     indent "    " hg_diff
       
   496 
       
   497     hg_commit "$msg"
       
   498 }
       
   499 
       
   500 ### Hosts
       
   501 ## Update hosts from verbatim from input zone data:
       
   502 #
       
   503 #   copy_hosts      $ZONES/$zone    $DATA/$base
       
   504 #
       
   505 # Writes updated zone to $zone, deps on $base.
       
   506 function copy_hosts {
       
   507     local zone=$1
       
   508     local base=$2
       
   509 
       
   510     if check_update $zone $base; then
       
   511         log_update "Copying hosts $zone <- $base..."
       
   512 
       
   513         do_update $zone \
       
   514             cat $ROOT/$base
       
   515     else
       
   516         log_skip "Copying hosts $zone <- $base: not changed"
       
   517     fi
       
   518 }
       
   519 
       
   520 ## Generate hosts from input zone data using $BIN/process-zone:
       
   521 #
       
   522 #   update_hosts    $ZONES/$zone    $DATA/$base
       
   523 #
       
   524 # Writes process-zone'd data to $zone, deps on $base.
       
   525 function update_hosts {
       
   526     local zone=$1; shift
       
   527     local base=$1; shift
       
   528 
       
   529     if check_update $zone $base; then
       
   530         log_update "Generating hosts $zone <- $base..."
       
   531 
       
   532         do_update $zone \
       
   533             $BIN/process-zone $PROCESS_ARGS $ROOT/$base "$@"
       
   534     else
       
   535         log_skip "Generating hosts $zone <- $base: not changed"
       
   536     fi
       
   537 }
       
   538 
       
   539 ## Generate new serial for zone using $BIN/update-serial, if the zone data has changed:
       
   540 #
       
   541 #   update_serial   $zone   $deps...
       
   542 #
       
   543 # Supports SERIAL_FORCE/NOOP.
       
   544 # Updates $SERIALS/$zone.serial.
       
   545 function update_serial {
       
   546     local zone=$1; shift
       
   547     
       
   548     local serial=$SERIALS/$zone.serial
       
   549 
       
   550     # test
       
   551     if [ $SERIAL_FORCE ]; then
       
   552         log_force "Updating $serial: forced"
       
   553 
       
   554         do_update_serial $serial
       
   555 
       
   556     elif ! check_update $serial "$@"; then
       
   557         log_skip "Updating $serial: not changed"
       
   558 
       
   559     elif [ $SERIAL_NOOP ]; then
       
   560         log_noop "Updating $serial: skipped"
       
   561 
       
   562     else
       
   563         log_update "Updating $serial..."
       
   564 
       
   565         do_update_serial $serial
       
   566     fi
       
   567 }
       
   568 
       
   569 ## Link serial for zone from given base-zone:
       
   570 #
       
   571 #   link_serial $zone $base
       
   572 function link_serial {
       
   573     local zone=$1
       
   574     local base=$2
       
   575 
       
   576     local lnk=$SERIALS/$zone.serial
       
   577     local tgt=$SERIALS/$base.serial
       
   578 
       
   579     if check_link $lnk $tgt; then
       
   580         log_update "Linking $lnk -> $tgt..."
       
   581 
       
   582         do_link $lnk $tgt
       
   583 
       
   584     else
       
   585         log_skip "Linking $lnk -> $tgt: not changed"
       
   586     fi
       
   587 }
       
   588 
       
   589 ## Update zone file verbatim from source:
       
   590 #
       
   591 #   copy_zone   $view   $zone   [$base]
       
   592 #
       
   593 # Copies changed $DATA/$base zone data to $ZONES/$view/$zone.
       
   594 function copy_zone {
       
   595     local view=$1
       
   596     local zone=$2
       
   597     local base=${3:-$zone}
       
   598 
       
   599     local out=$ZONES/$view/$zone
       
   600     local src=$DATA/$base
       
   601 
       
   602     if check_update $out $src; then
       
   603         log_update "Copying $out <- $src..."
       
   604 
       
   605         do_update $out \
       
   606             cat $ROOT/$src
       
   607     else
       
   608         log_skip "Copying $out <- $src: not changed"
       
   609     fi
       
   610 }
       
   611 
       
   612 ## Expand zone file from source using $BIN/expand-zone:
       
   613 #
       
   614 #   update_zone $view   $zone   [$base]
       
   615 #
       
   616 # Processed $DATA/$base zone data through $BIN/expand-zone, writing output to $ZONES/$view/$zone.
       
   617 function update_zone {
       
   618     local view=$1
       
   619     local zone=$2
       
   620     local base=${3:-$zone}
       
   621 
       
   622     local out=$ZONES/$view/$zone
       
   623     local src=$DATA/$base.zone
       
   624     local lnk=$ZONES/$base
       
   625 
       
   626     local serial=$SERIALS/$base.serial
       
   627 
       
   628     if check_update $out $src $serial; then
       
   629         log_update "Generating $out <- $src..." 
       
   630 
       
   631         do_update $out \
       
   632             $BIN/expand-zone $ROOT/$src \
       
   633                 --serial $ROOT/$serial              \
       
   634                 --expand zones=$(abspath $ZONES)    \
       
   635                 --expand view=$view
       
   636     else
       
   637         log_skip "Generating $out <- $src: not changed" 
       
   638     fi
       
   639 }
       
   640 
       
   641 ## Link zone file to ues given shared zone.
       
   642 #
       
   643 #   link_zone   $view   $zone   [$base]
       
   644 #
       
   645 # Looks for shared zone at:
       
   646 #   $ZONES/$view/$base
       
   647 #   $ZONES/common/$base
       
   648 function link_zone {
       
   649     local view=$1
       
   650     local zone=$2
       
   651     local base=${3:-$zone}
       
   652 
       
   653     local out=$ZONES/$view/$zone
       
   654     local tgt=$(choose_link $out $ZONES/$view/$base $ZONES/common/$base)
       
   655 
       
   656     if check_link $out $tgt; then
       
   657         log_update "Linking $out -> $tgt..."
       
   658 
       
   659         do_link $out $tgt
       
   660 
       
   661     else
       
   662         log_skip "Linking $out -> $tgt: not changed"
       
   663     fi
       
   664 }
       
   665 
       
   666 ## Test hosts zone for validity:
       
   667 #
       
   668 #   check_hosts     $DATA/$hosts    --check-exempt ...
       
   669 #
       
   670 # Fails if the check fails.
       
   671 function check_hosts {
       
   672     local hosts=$1; shift 1
       
   673 
       
   674     local cmd=($BIN/process-zone $PROCESS_ARGS $ROOT/$hosts --check-hosts "$@")
       
   675 
       
   676     if "${cmd[@]}" -q; then
       
   677         log_skip "Check $hosts: OK"
       
   678     else
       
   679         log_error "  Check $hosts: Failed"
       
   680 
       
   681         indent "    " "${cmd[@]}"
       
   682 
       
   683         exit 1
       
   684     fi
       
   685 }
       
   686 
       
   687 ## Test zone file for validity using named-checkzone:
       
   688 #
       
   689 #   check_zone      $view       $zone       $origin
       
   690 #
       
   691 # Uses the zonefile at $ZONES/$view/$zone, loading it with given initial $ORIGIN.
       
   692 # Fails if the check fails.
       
   693 function check_zone {
       
   694     local view=$1
       
   695     local zone=$2
       
   696     local origin=$3
       
   697 
       
   698     local src=$ZONES/$view/$zone
       
   699 
       
   700     local cmd=($NAMED_CHECKZONE $origin $ROOT/$src)
       
   701 
       
   702     # test
       
   703     # XXX: checkzone is very specific about the order of arguments, -q must be first
       
   704     if $NAMED_CHECKZONE -q $origin $ROOT/$src; then
       
   705         log_skip "Check $src ($origin): OK"
       
   706     else
       
   707         log_error "  Check $src ($origin): Failed:"
       
   708 
       
   709         indent "    " "${cmd[@]}"
       
   710         
       
   711         exit 1
       
   712     fi
       
   713 }
       
   714 
       
   715 ## Load update zonefiles into bind:
       
   716 #
       
   717 #   deploy_zones    
       
   718 #
       
   719 # Invokes `rndc reload`, showing its output.
       
   720 function deploy_zones {
       
   721     local msg="Reload zones"
       
   722 
       
   723     if [ $DEPLOY_SKIP ]; then
       
   724         log_skip    "$msg: skipped"
       
   725     
       
   726     elif [ ! -r $RNDC_KEY ]; then
       
   727         log_error   "  $msg: rndc: permission denied: $RNDC_KEY"
       
   728 
       
   729     else
       
   730         log_update  "$msg..."
       
   731 
       
   732         # run
       
   733         indent "        rndc: " \
       
   734             $RNDC reload
       
   735     fi
       
   736 }
       
   737 ## Commit changes in $DATA to version control:
       
   738 #
       
   739 #   commit_data
       
   740 #
       
   741 # Invokes `hg commit` in the $REPO, first showing the diff.
       
   742 function commit_data {
       
   743     local repo=$REPO
       
   744     local commit_msg="$COMMIT_MSG"
       
   745 
       
   746     local msg="Commit changes in $repo"
       
   747 
       
   748     # operate?
       
   749     if [ $COMMIT_FORCE ]; then
       
   750         log_force   "$msg..."
       
   751 
       
   752         do_commit "$commit_msg"
       
   753 
       
   754     elif ! hg_modified; then
       
   755         log_skip    "$msg: no changes"
       
   756 
       
   757     elif [ $COMMIT_SKIP ]; then
       
   758         log_noop    "$msg: skipped"
       
   759 
       
   760     else
       
   761         log_update  "$msg..."
       
   762 
       
   763         do_commit "$commit_msg"
       
   764     fi
       
   765 }
       
   766 
    69 
   767 ## Site settings, used as arguments to scripts
    70 ## Site settings, used as arguments to scripts
   768 # MX record to generate in hosts --forward-zone
    71 # MX record to generate in hosts --forward-zone
   769 FORWARD_MX=mail
    72 FORWARD_MX=mail
   770 
    73