# HG changeset patch # User Tero Marttila # Date 1332240231 -7200 # Node ID ef5bcc4145deca176e519ed12961104a60360924 # Parent baae373b787ebe3b6db2dac2027f86255bc605bd debug with func_caller; update_serial deps diff -r baae373b787e -r ef5bcc4145de bin/update --- a/bin/update Tue Mar 20 12:19:16 2012 +0200 +++ b/bin/update Tue Mar 20 12:43:51 2012 +0200 @@ -192,10 +192,18 @@ done } +function func_caller { + caller 1 | cut -d ' ' -f 2 +} + +function debug { + printf -v prefix "%s" $(func_caller) + + log_debug "$prefix: $*" +} + function fail { - func=$(caller 1 | cut -d ' ' -f 2) - - log_error "$func: $*" + log_error "$(func_caller): $*" exit 2 } @@ -258,7 +266,7 @@ echo '-u' "$SUDO_USER" elif [ $HOME ] && [ -e $HOME/.hgrc ]; then - log_debug "using .hgrc user" + debug "using .hgrc user" echo '' else @@ -274,7 +282,7 @@ local msg=$2 local user_opt=$(hg_user) - log_debug "commit: $user_opt: $msg" + debug "$user_opt: $msg" hg commit $user_opt -m "$msg" } @@ -284,13 +292,21 @@ # target local dst=$1; shift - log_debug "check_update: $dst" + debug "$dst" # need update? local update= - if [ ! -e $dst ] || [ $UPDATE_FORCE ]; then - log_debug " update forced" + if [ ${#@} == 0 ]; then + debug " update: unknown deps" + update=y + + elif [ ! -e $dst ]; then + debug " update: dest missing" + update=y + + elif [ $UPDATE_FORCE ]; then + debug " update: forced" update=y fi @@ -304,12 +320,14 @@ fail "$dst: Missing source: $dep" elif [ $ROOT/$dst -ot $ROOT/$dep ]; then - log_debug " changed: $dep" + debug " update: $dep" update=y + else + debug " check: $dep" fi done - [ ! $update ] && log_debug " up-to-date" + [ ! $update ] && debug " up-to-date" # return [ $update ] @@ -319,12 +337,12 @@ local dst=$1; shift local tmp=$dst.new - log_debug "update: $dst" + debug "$dst" cmd "$@" > $ROOT/$tmp # compare if [ -e $ROOT/$dst ] && [ $UPDATE_DIFF ]; then - log_debug " changes:" + debug " changes:" # terse indent " " diff --unified=1 $ROOT/$dst $ROOT/$tmp || true @@ -332,12 +350,12 @@ if [ $UPDATE_NOOP ]; then # cleanup - log_debug " no-op" + debug " no-op" cmd rm $ROOT/$tmp else # commit - log_debug " update" + debug " commit" cmd mv $ROOT/$tmp $ROOT/$dst fi @@ -370,7 +388,7 @@ do_update $dst "${cmd[@]}" else - log_debug "$msg: not changed" + log_skip "$msg: not changed" fi } @@ -422,22 +440,38 @@ ## actions # serial -function update_serial { - local zone=$1; shift - - local serial=$SERIALS/$zone.serial - +function do_update_serial { + local serial=$1 + # read local old=$(test -e $ROOT/$serial && cat $ROOT/$serial || echo '') - log_info "Updating $serial..." cmd $BIN/update-serial $ROOT/$serial # read local new=$(cat $ROOT/$serial) - log_debug " $old -> $new" + debug " $old -> $new" +} + +function update_serial { + local zone=$1; shift + + local serial=$SERIALS/$zone.serial + + # test + if ! check_update $serial "$@"; then + log_skip "Updating $serial: not changed" + + elif [ $SERIAL_NOUPDATE ]; then + log_skip "Updating $serial: skipped" + + else + log_info "Updating $serial..." + + do_update_serial $serial + fi } function link_serial { @@ -628,20 +662,22 @@ copy_zone includes paivola.services paivola.zone.services # serials - if [ $SERIAL_NOUPDATE ]; then - log "Updating serials: skipped" - - else - log "Updating serials..." + log "Updating serials..." - # zone base - update_serial pvl - link_serial 10 pvl - link_serial 192.168 pvl + # zone *deps + update_serial pvl $ZONES/hosts/pvl $DATA/pvl.zone + update_serial 10 $ZONES/hosts/10 $DATA/10.zone + update_serial 192.168 $ZONES/hosts/192.168 $DATA/192.168.zone - update_serial paivola - update_serial 194.197.235 - fi + update_serial paivola \ + $ZONES/hosts/paivola:* \ + $DATA/paivola.zone \ + $ZONES/includes/paivola:* \ + $ZONES/includes/paivola.* + + update_serial 194.197.235 \ + $ZONES/hosts/194.197.235 \ + $DATA/194.197.235.zone # zones log "Updating zones..."