--- a/lib/update.updates Tue Dec 17 01:17:49 2013 +0200
+++ b/lib/update.updates Tue Dec 17 02:06:53 2013 +0200
@@ -10,7 +10,7 @@
# Returns true if the output file needs to be updated.
function check_update {
# target
- local out=$1; shift
+ local out="$1"; shift
debug "$out"
@@ -21,7 +21,7 @@
debug " update: unknown deps"
update=y
- elif [ ! -e $out ]; then
+ elif [ ! -e "$out" ]; then
debug " update: dest missing"
update=y
@@ -37,9 +37,9 @@
# check
if [ ! -e "$dep" ]; then
- fail "$out: Missing source: $dep"
+ warn "$out: Missing source: $dep"
- elif [ $out -ot "$dep" ]; then
+ elif [ "$out" -ot "$dep" ]; then
debug " update: $dep"
update=y
else
@@ -60,18 +60,18 @@
# Writes output to a temporary .new file, optionally shows a diff of changes, and commits
# the new version to $out (unless noop'd).
function do_update {
- local out=$1; shift
- local tmp=$out.new
+ local out="$1"; shift
+ local tmp="$out.new"
debug "$out"
- cmd "$@" > $tmp
+ cmd "$@" > "$tmp"
# compare
- if [ -e $out ] && [ $UPDATE_DIFF ]; then
+ if [ -e "$out" ] && [ $UPDATE_DIFF ]; then
debug " changes:"
# terse
- indent " " diff --unified=1 $out $tmp || true
+ indent " " diff --unified=1 "$out" "$tmp" || true
fi
# deploy
@@ -79,33 +79,15 @@
# cleanup
debug " no-op"
- cmd rm $tmp
+ cmd rm "$tmp"
else
# commit
debug " deploy"
- cmd mv $tmp $out
+ cmd mv "$tmp" "$out"
fi
}
-## Look for a link target:
-#
-# find_link $lnk $tgt...
-#
-# Outputs the first given target to exist, skipping any that are the same as the given $lnk.
-# If no $tgt matches, outputs the last one, or '-'.
-function choose_link {
- local lnk=$1; shift
- local tgt=-
-
- for tgt in "$@"; do
- [ $tgt != $out ] && [ -e $tgt ] && break
- done
-
- echo $tgt
-}
-
-
## Compare symlink to target:
#
# check_link $lnk $tgt && do_link $lnk $tgt || ...
@@ -113,12 +95,12 @@
# Tests if the symlink exists, and the target matches.
# Fails if the target does not exist.
function check_link {
- local lnk=$1
- local tgt=$2
+ local lnk="$1"
+ local tgt="$2"
- [ ! -e $tgt ] && fail "$tgt: target does not exist"
+ [ ! -e "$tgt" ] && fail "$tgt: target does not exist"
- [ ! -e $lnk ] || [ $(readlink $lnk) != $tgt ]
+ [ ! -e "$lnk" ] || [ $(readlink "$lnk") != "$tgt" ]
}
## Update symlink to point to target:
@@ -126,9 +108,28 @@
# do_link $lnk $tgt
#
function do_link {
- local lnk=$1
- local tgt=$2
+ local lnk="$1"
+ local tgt="$2"
- cmd ln -sf $tgt $lnk
+ cmd ln -sf "$tgt" "$lnk"
}
+## Read include paths from file
+function read_zone_includes {
+ cmd sed -n -E 's/^\$INCLUDE\s+"(.+)"/\1/p' "$@"
+}
+
+## (cached) include paths for zone file
+function zone_includes {
+ local cache="$1"
+ local src="$2"
+ local dir="$3"
+
+ if [ ! -e "$cache" -o "$cache" -ot "$src" ]; then
+ read_zone_includes "$src" > "$cache"
+ fi
+
+ while read include; do
+ echo -n "$dir/$include "
+ done < "$cache"
+}