diff -r 5cd99761fe4d -r a81206440be2 bin/update --- a/bin/update Thu Feb 26 19:49:10 2015 +0200 +++ b/bin/update Thu Feb 26 21:38:09 2015 +0200 @@ -1,135 +1,21 @@ #!/bin/bash -# vim: set ft=sh : - -# Bootstrap -if [ $0 == './update' ]; then - SRV=$(pwd) - OPT=/opt/pvl-verkko - LIB=/opt/pvl-dns/lib -else - SRV=${SRV:-/srv/verkko} - OPT=${SRV:-/opt/pvl-verkko} - LIB=/opt/pvl-dns/lib - cd $SRV -fi - -source $LIB/update - -function commit { - ## Commit - # pre-commit check - log "Testing hosts..." - for hosts in $(list_files etc/hosts); do - log_warn "TODO: check_hosts $hosts" - done - - # commit, unless noop'd - log "Commit..." - update_commit etc -} - -function update { - if hg_modified etc; then - serial=$(unix_time) - log_warn "Using local unix time for uncommited changes: $serial" - else - serial=$(hg_time etc) - log_update "Using HG commit timestamp: $serial" - fi - - ## Hosts - log "Updating forward host zones..." - for zone in $(list_dirs etc/hosts/forward); do - update_hosts_forward "var/zones/hosts/forward/$zone" "$zone" \ - etc/hosts/forward/$zone/* - done - - log "Updating DHCP hosts..." - for hosts in $(list etc/hosts/dhcp); do - update_hosts_dhcp "var/dhcp/hosts/$hosts.conf" $hosts \ - $(expand_files "etc/hosts/dhcp/$hosts") - done - - log "Updating reverse host zones..." - for zone in $(list_dirs etc/hosts/reverse); do - update_hosts_reverse "var/zones/hosts/reverse/$zone" "$zone" \ - etc/hosts/reverse/$zone/* - done - - ## Zones - log "Copying zone includes..." - for zone in $(list_files etc/zones/includes); do - copy "var/zones/includes/$zone" "etc/zones/includes/$zone" - done - log "Updating zone serials..." - for zone in $(list_files etc/zones); do - update_serial "var/serials/$zone" $serial \ - "etc/zones/$zone" $(zone_includes var/include-cache/$zone etc/zones/$zone var/zones/) - done - - log "Updating zones..." - for zone in $(list_files etc/zones); do - update_zone "var/zones/$zone" "etc/zones/$zone" "var/serials/$zone" \ - $(zone_includes var/include-cache/$zone etc/zones/$zone var/zones/) - done - - log "Updating DHCP confs..." - for conf in $(list_files etc/dhcp); do - update_dhcp_conf "var/dhcp/$conf" "etc/dhcp/$conf" - done -} - -function deploy { - ## Check - log "Testing zones..." - for zone in $(list_files etc/zones); do - check_zone "var/zones/$zone" $zone - done - - log "Testing DHCP confs..." - for conf in var/dhcp/*.conf; do - check_dhcp $conf - done - - log "Reload zones..." - reload_zones +SRV=${SRV:-.} +SRC=${OPT:-.} +OPT=${OPT:-./opt} +ETC=${ETC:-$SRV/etc} +LIB=${LIB:-$SRC/lib} +VAR=${VAR:-$SRV/var} - log "Reload dhcp..." - reload_dhcp - -} - -## Main entry point -function main { - log_init - - parse_args "$@" - ## Input dirs - for dir in etc etc/zones etc/hosts; do - [ -d $dir ] || die "Missing directory: $dir" - done - - ## Output dirs - ensure_dir var - for dir in var/dhcp var/zones var/include-cache var/serials; do - ensure_dir $dir - done - for dir in var/dhcp/hosts; do - ensure_dir $dir - done - for dir in var/zones/includes var/zones/hosts; do - ensure_dir $dir - done - for dir in var/zones/hosts/forward var/zones/hosts/reverse; do - ensure_dir $dir - done +. $LIB/pvl/main.sh - ## Go - commit - update - deploy -} +MODULES=(log commit apply update) +MODULE=update + +. $LIB/pvl/commit.sh +. $LIB/pvl/apply.sh + +. $LIB/pvl/hosts/update.sh main "$@"