--- a/bin/update Sat Dec 21 22:43:38 2013 +0200
+++ b/bin/update Sun Dec 22 15:33:32 2013 +0200
@@ -43,9 +43,9 @@
done
log "Updating DHCP hosts..."
- for hosts in $(list_files etc/hosts); do
- update_hosts_dhcp "var/dhcp/hosts/$hosts.conf" \
- "etc/hosts/$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..."
--- a/lib/update Sat Dec 21 22:43:38 2013 +0200
+++ b/lib/update Sun Dec 22 15:33:32 2013 +0200
@@ -4,6 +4,8 @@
## Strict errors
set -ue
+shopt -s globstar nullglob
+
## Library includes
for lib in lib/update.*; do
source $lib
--- a/lib/update.operations Sat Dec 21 22:43:38 2013 +0200
+++ b/lib/update.operations Sun Dec 22 15:33:32 2013 +0200
@@ -72,16 +72,17 @@
function update_hosts_dhcp {
local out=$1; shift
- local src=$1; shift
+ local domain="$1"; shift
- if check_update $out $src "$@"; then
- log_update "Generating DHCP hosts $out <- $src..."
+ if check_update $out "$@"; then
+ log_update "Generating DHCP hosts $out @ $domain <- $@..."
do_update $out $OPT/bin/pvl.hosts-dhcp \
--hosts-charset=$CHARSET \
- $src "$@"
+ --hosts-domain=$domain \
+ "$@"
else
- log_skip "Generating DHCP hosts $out <- $src: not changed"
+ log_skip "Generating DHCP hosts $out <- $@: not changed"
fi
}
--- a/lib/update.utils Sat Dec 21 22:43:38 2013 +0200
+++ b/lib/update.utils Sun Dec 22 15:33:32 2013 +0200
@@ -60,36 +60,40 @@
echo "$SRV/$path"
}
+function _list {
+ local glob="$1"
+ local test="$2"
+ local prefix="$3"
+
+ for file in $glob; do
+ [ $test "$file" ] || continue
+ [ -n "$prefix" ] && file="${file#$prefix}"
+
+ echo -n "$file "
+ done
+}
+
+## List names of all files in dir
+function list {
+ _list "$1/*" '-e' ${2:-$1/}
+}
+
## List names of files in dir:
#
-# list_files $dir $glob
+# list_files $dir
#
function list_files {
- local dir="$1"
- local glob="${2:-*}"
- local name=
-
- for file in $dir/$glob; do
- # only files
- [ -f "$file" ] || continue
-
- # strip prefix
- name=${file#$dir/}
- name=${name%$glob}
-
- echo -n "$name "
- done
+ _list "$1/*" '-f' ${2:-$1/}
}
## List names of dirs in dir:
function list_dirs {
- local dir="$1"
+ _list "$1/*" '-d' ${2:-$1/}
+}
- for file in $dir/*; do
- [ -d "$file" ] || continue
-
- echo -n "${file#$dir/} "
- done
+## List names of any files underneath dir or file:
+function expand_files {
+ _list "$1 $1/**" '-f' ''
}
## Get current unix (utc) timestamp