--- a/lib/update.operations Wed Mar 21 16:45:59 2012 +0200
+++ b/lib/update.operations Wed Mar 21 17:04:21 2012 +0200
@@ -3,6 +3,21 @@
#
# Operations on zonefiles/hosts/whatever
+function link_generic {
+ local out=$1
+ local tgt=$2
+
+ if check_link $out $tgt; then
+ log_update "Linking $out -> $tgt..."
+
+ do_link $out $tgt
+
+ else
+ log_skip "Linking $out -> $tgt: not changed"
+ fi
+}
+
+
## Hosts
## Update hosts from verbatim from input zone data:
#
@@ -100,17 +115,11 @@
local zone=$1
local base=$2
- local lnk=$SERIALS/$zone.serial
+ local out=$SERIALS/$zone.serial
local tgt=$SERIALS/$base.serial
- if check_link $lnk $tgt; then
- log_update "Linking $lnk -> $tgt..."
- do_link $lnk $tgt
-
- else
- log_skip "Linking $lnk -> $tgt: not changed"
- fi
+ link_generic $out $tgt
}
## Update zone file verbatim from source:
@@ -180,14 +189,18 @@
local out=$ZONES/$view/$zone
local tgt=$(choose_link $out $ZONES/$view/$base $ZONES/common/$base)
- if check_link $out $tgt; then
- log_update "Linking $out -> $tgt..."
+ link_generic $out $tgt
+}
- do_link $out $tgt
+## Link dhcp file directly from data to hosts
+function link_dhcp_hosts {
+ local hosts=$1
+ local base=${2:-$hosts}
- else
- log_skip "Linking $out -> $tgt: not changed"
- fi
+ local out=$DHCP/$hosts.conf
+ local tgt=$(choose_link $out $DHCP/$base.conf $DHCP_DATA/$base.conf)
+
+ link_generic $out $tgt
}
## Test hosts zone for validity:
@@ -239,6 +252,39 @@
fi
}
+## Test DHCP configuration for validity using dhcpd -t:
+#
+# check_dhcp [$conf]
+#
+# Defaults to the global $DHCPD_CONF.
+# Fails if the check fails.
+function check_dhcp {
+ local conf=${1:-$DHCPD_CONF}
+
+ local cmd=($DHCPD -cf $conf -t)
+
+ if "${cmd[@]}" -q; then
+ log_skip "Check $conf: OK"
+
+ else
+ log_error " Check $conf: Failed"
+
+ indent " " "${cmd[@]}"
+
+ exit 1
+ fi
+}
+
+## Test DHCP configuration of given hosts file using check_dhcp $DHCP/$host.conf:
+#
+# check_dhcp_hosts $host
+#
+function check_dhcp_hosts {
+ local host=$1
+
+ check_dhcp $DHCP/$host.conf
+}
+
# Run rndc reload
function do_reload {
# run