--- a/lib/update.operations Mon Dec 16 21:53:41 2013 +0200
+++ b/lib/update.operations Tue Dec 17 00:04:00 2013 +0200
@@ -3,7 +3,7 @@
#
# Operations on zonefiles/hosts/whatever
-function link_generic {
+function link {
local out=$1
local tgt=$2
@@ -17,7 +17,7 @@
fi
}
-function copy_generic {
+function copy {
local out=$1
local src=$2
@@ -25,7 +25,7 @@
log_update "Copying $out <- $src..."
do_update $out \
- cat $ROOT/$src
+ cat $src
else
log_skip "Copying $out <- $src: not changed"
fi
@@ -33,9 +33,9 @@
## Run check-command on given file, outputting results:
#
-# check_generic $src $cmd $args...
+# check $src $cmd $args...
#
-function check_generic {
+function check {
local src=$1; shift
local cmd=$1; shift
@@ -65,25 +65,38 @@
local out=$zone
local src=$base
- copy_generic $out $src
+ copy $out $src
}
-## Generate hosts from input zone data using $BIN/process-zone:
-#
-# update_hosts $ZONES/$zone $DATA/$base
+## Generate forward zone from hosts hosts using pvl.hosts-dns:
#
-# Writes process-zone'd data to $zone, deps on $base.
-function update_hosts {
- local zone=$1; shift
- local base=$1; shift
+# update_hosts out/hosts/$hosts in/hosts/$hosts
+function update_hosts_forward {
+ local out=$1
+ local src=$2
- if check_update $zone $base; then
- log_update "Generating hosts $zone <- $base..."
+ if check_update $out $src; then
+ log_update "Generating hosts zone $out <- $src..."
+
+ do_update $out $OPT/bin/pvl.hosts-dns $src \
+ --hosts-charset=$CHARSET
+
+ else
+ log_skip "Generating hosts $out <- $src: not changed"
+ fi
+}
- do_update $zone \
- $BIN/process-zone $HOSTS_FILE_ARGS $ROOT/$base "$@"
+function update_hosts_dhcp {
+ local out=$1
+ local src=$2
+
+ if check_update $out $src; then
+ log_update "Generating DHCP hosts $out <- $src..."
+
+ do_update $out $OPT/bin/pvl.hosts-dhcp $src \
+ --hosts-charset=$CHARSET
else
- log_skip "Generating hosts $zone <- $base: not changed"
+ log_skip "Generating DHCP hosts $out <- $src: not changed"
fi
}
@@ -96,29 +109,26 @@
local serial=$1
# read
- local old=$(test -e $ROOT/$serial && cat $ROOT/$serial || echo '')
+ local old=$(test -e $serial && cat $serial || echo '')
-
- cmd $BIN/update-serial $ROOT/$serial
+ cmd $OPT/bin/pvl.dns-serial $serial
# read
- local new=$(cat $ROOT/$serial)
+ local new=$(cat $serial)
debug " $old -> $new"
}
-## Generate new serial for zone using $BIN/update-serial, if the zone data has changed:
+## Generate new serial for zone using pvl.dns-serial, if the zone data has changed:
#
# update_serial $zone $deps...
#
# Supports SERIAL_FORCE/NOOP.
# Updates $SERIALS/$zone.serial.
function update_serial {
- local zone=$1; shift
+ local serial=$1; shift
- local serial=$SERIALS/$zone.serial
-
# test
if [ $SERIAL_FORCE ]; then
log_force "Updating $serial: forced"
@@ -148,7 +158,7 @@
local out=$SERIALS/$zone.serial
local tgt=$SERIALS/$base.serial
- link_generic $out $tgt
+ link $out $tgt
}
## Update zone file verbatim from source:
@@ -164,7 +174,7 @@
local out=$ZONES/$view/$zone
local src=$DATA/$base
- copy_generic $out $src
+ copy $out $src
}
## Return the first zone that exists under $DATA/$name.zone
@@ -183,29 +193,19 @@
die "Unable to find zone in $DATA/*.zone: $@"
}
-## Expand zone file from source using $BIN/expand-zone:
+## Expand zone file from source using pvl.dns-zone:
#
# update_zone $view $zone [$base]
-#
-# Updates $ZONES/$view/$zone from $DATA/$base.{zone,serial} using $BIN/expand-zone.
function update_zone {
- local view=$1
- local zone=$2
- local base=${3:-$zone}
-
- # zones <- data+serial file
- local out=$ZONES/$view/$zone
- local src=$DATA/$base.zone
- local serial=$SERIALS/$base.serial
+ local out=$1
+ local src=$2
+ local serial=$3
if check_update $out $src $serial; then
log_update "Generating $out <- $src..."
- do_update $out \
- $BIN/expand-zone $ROOT/$src \
- --serial $ROOT/$serial \
- --expand zones=$(abspath $ZONES) \
- --expand view=$view
+ do_update $out $OPT/bin/pvl.dns-zone $src \
+ --serial $(cat $serial)
else
log_skip "Generating $out <- $src: not changed"
fi
@@ -226,7 +226,7 @@
local out=$ZONES/$view/$zone
local tgt=$(choose_link $out $ZONES/$view/$base $ZONES/common/$base)
- link_generic $out $tgt
+ link $out $tgt
}
## Link dhcp file directly from data to $DHCP
@@ -237,7 +237,7 @@
local out=$DHCP/$conf.conf
local tgt=$(choose_link $out $DHCP/$base.conf $DHCP_DATA/$base.conf)
- link_generic $out $tgt
+ link $out $tgt
}
## Copy dhcp conf from data to $DHCP
@@ -248,56 +248,29 @@
local out=$DHCP/$conf.conf
local src=$DHCP_DATA/$base.conf
- copy_generic $out $src
+ copy $out $src
}
-## Test hosts zone for validity:
+## Test hosts zone for validity using pvl.hosts-check:
#
-# check_hosts $DATA/$hosts --check-exempt ...
-#
-# Fails if the check fails.
+# check_hosts .../hosts
function check_hosts {
local hosts=$1; shift 1
-
- local cmd=($BIN/process-zone $HOSTS_FILE_ARGS $ROOT/$hosts --check-hosts "$@")
-
- if "${cmd[@]}" -q; then
- log_skip "Check $hosts: OK"
- else
- log_error " Check $hosts: Failed"
-
- indent " " "${cmd[@]}"
-
- exit 1
- fi
+
+ # TODO
+ check $hosts \
+ $OPT/bin/pvl.hosts-check $hosts
}
## Test zone file for validity using named-checkzone:
#
-# check_zone $view $zone $origin
-#
-# Uses the zonefile at $ZONES/$view/$zone, loading it with given initial $ORIGIN.
-# Fails if the check fails.
+# check_zone ..../$zone $origin
function check_zone {
- local view=$1
- local zone=$2
- local origin=$3
-
- local src=$ZONES/$view/$zone
+ local zone=$1
+ local origin=$2
- local cmd=($NAMED_CHECKZONE $origin $ROOT/$src)
-
- # test
- # XXX: checkzone is very specific about the order of arguments, -q must be first
- if cmd_test $NAMED_CHECKZONE -q $origin $ROOT/$src; then
- log_skip "Check $src ($origin): OK"
- else
- log_error " Check $src ($origin): Failed:"
-
- indent " " "${cmd[@]}"
-
- exit 1
- fi
+ # checkzone is very specific about the order of arguments, -q must be first
+ check $zone $NAMED_CHECKZONE $origin $zone
}
## Test DHCP configuration for validity using dhcpd -t:
@@ -314,7 +287,7 @@
return 0
fi
- check_generic $conf \
+ check $conf \
$DHCPD -cf $conf -t
}
@@ -328,26 +301,8 @@
check_dhcp $DHCP_DATA/$conf.conf
}
-## Test DHCP hosts source configuration for invalid fixed-address stanzas:
-#
-# check_dhcp_hosts $hosts_conf
-#
-function check_dhcp_hosts {
- local hosts=$1
-
- # XXX: still too unclear
- local src=$hosts #$DHCP_DATA/$hosts.conf
-
- # set in do_reload_zones below
- if [ $RELOAD_ZONES ]; then
- check_generic $src \
- $BIN/check-dhcp-hosts $DHCP_FILE_ARGS $ROOT/$src
- else
- log_noop "Check $src: skipped; did not reload DNS zones"
- fi
-}
-
-# Run rndc reload
+### Deploy
+## Run rndc reload
function do_reload_zones {
# run
indent " rndc: " \
@@ -432,7 +387,8 @@
fi
}
-## Perform `hg commit` for $DATA
+### Commit
+## Perform `hg commit`
function do_commit {
local msg=$1
@@ -442,16 +398,15 @@
}
-## Commit changes in $DATA to version control:
+## Commit changes to version control:
#
# commit_data
#
-# Invokes `hg commit` in the $REPO, first showing the diff.
+# Invokes `hg commit`, first showing the diff.
function commit_data {
- local repo=$REPO
local commit_msg="$COMMIT_MSG"
- local msg="Commit changes in $repo"
+ local msg="Commit changes"
# operate?
if [ $COMMIT_FORCE ]; then
@@ -473,4 +428,3 @@
do_commit "$commit_msg"
fi
}
-