lib/pvl/update/zone: reimplement update_zone using pvl.dns-process --include-trace
--- a/lib/pvl/hosts/update.sh Tue Mar 03 12:43:26 2015 +0200
+++ b/lib/pvl/hosts/update.sh Tue Mar 03 12:43:49 2015 +0200
@@ -98,15 +98,7 @@
log "Updating zones..."
for zone in $(list_files etc/zones); do
- update_zone_includes "var/include-cache/$zone" "etc/zones/$zone"
-
- zone_includes=$(cat "var/include-cache/$zone")
-
- update_zone_serial "var/serials/$zone" $serial \
- "etc/zones/$zone" $zone_includes
-
- update_zone "var/zones/$zone" "etc/zones/$zone" "var/serials/$zone" \
- $zone_includes
+ update_zone -s "$serial" "var/zones/$zone" "etc/zones/$zone" "var/serials/$zone"
done
log "Updating DHCP confs..."
--- a/lib/pvl/hosts/zone.sh Tue Mar 03 12:43:26 2015 +0200
+++ b/lib/pvl/hosts/zone.sh Tue Mar 03 12:43:49 2015 +0200
@@ -51,6 +51,10 @@
fi
}
+## Update zone $INCLUDE file
+#
+# update_zone_include etc/zone/includes/$zone var/zone/includes/$zone
+#
function update_zone_include {
local out="$1"
local src="$2"
@@ -66,45 +70,15 @@
fi
}
-
-## Update list of zone $INCLUDEs from zone file
-#
-# update_zone_includes var/include-cache/$zone etc/zones/$zone
+## Check if the given zone needs to be updated; update serial if so
#
-function update_zone_includes {
- local out="$1"
- local src="$2"
- local includes="$ZONES_INCLUDE"
-
- if [ "$UPDATE_INCLUDES" = 1 ]; then
- log_force "$out: Force zone includes: $src"
-
- elif apply_check "$out" "$src"; then
- log_skip "$out: Skip zone includes: $src"
-
- return
-
- elif [ "$UPDATE_INCLUDES" = 0 ]; then
- log_noop "$out: Noop zone includes: $src"
-
- return
- else
- log_apply "$out: Update zone includes: $src"
- fi
-
- apply_cmd "$out" $OPT/bin/pvl.dns-includes \
- --include-path=$ZONES_INCLUDE \
- "$src"
-}
-
-## Update the cached .serial for the given zone, if the zone has changed:
-#
-# update_serial var/serials/$zone $serial $deps...
+# check_zone_serial var/serials/$zone $serial $zone_deps...
#
# Supports UPDATE_SERIAL=
-function update_zone_serial {
+function check_zone_serial {
local out="$1"
local serial="$2"
+ local srcs=(${@:3})
local old=$(test -e "$out" && cat "$out" || echo '')
@@ -112,51 +86,60 @@
if [ "$UPDATE_SERIAL" = 1 ]; then
log_force "$out: Force serial $old <- $serial"
- elif apply_check "$out" "${@:3}"; then
- log_skip "$out: Skip serial: $old <- $serial"
-
- return
-
elif [ "$UPDATE_SERIAL" = 0 ]; then
log_noop "$out: Noop serial: $old <- $serial"
- return
+ return 0
+
+ elif apply_check "$out" ${srcs[@]:-}; then
+ return 0
else
log_apply "$out: Update serial: $old <- $serial"
fi
echo "$serial" > $out
+
+ return 1
}
## Generate zone file from source using pvl.dns-process:
#
# update_zone var/zones/$zone etc/zones/$zone var/serials/$zone
#
-# Sets the SOA serial, and adjusts the $INCLUDE paths
+# Updates the SOA serial, and adjusts the $INCLUDE paths
function update_zone {
+ local update_serial=
+
+ local OPTIND
+ while getopts 's:' opt; do case $opt in
+ s) update_serial=$OPTARG ;;
+ esac done
+ shift $(($OPTIND - 1))
+
local out="$1"
local src="$2"
local serial="$3"
- local serial_opt=
- local msg="$out: Generate zone: $src"
+ local zone_serial=
- if [ -n "$serial" -a -f "$serial" ]; then
- serial_opt="--serial=$(cat "$serial")"
- elif [ "$UPDATE_SERIAL" = 0 ]; then
- warn "$out: omit noop'd serial"
+ local msg="$out: Generate zone: $src"
+ local include_cache=$(include_cache_path $src)
+ local srcs=($(include_cache $include_cache))
+
+ if check_zone_serial "$serial" $update_serial ${srcs[@]:-}; then
+ zone_serial=$(cat $serial)
+
+ log_skip "$out: Skip zone: $src @ $zone_serial <- $update_serial"
+
else
- fail "$out: missing serial: $serial"
- fi
+ zone_serial=$(cat $serial)
- if apply_check "$out" "${@:2}"; then
- log_skip "$msg"
- else
- log_apply "$msg"
-
+ log_apply "$out: Generate zone: $src @ $zone_serial"
+
apply_cmd "$out" $OPT/bin/pvl.dns-process \
- $serial_opt \
+ --serial=$zone_serial \
--include-path=$ZONES_INCLUDE \
+ --include-trace=$include_cache \
"$src"
fi
}