lib/update.operations: implement choose_zone to choose correct base for zone from settings/*.zone
authorTero Marttila <terom@paivola.fi>
Thu, 12 Apr 2012 15:04:34 +0300
changeset 595 a8160670c3cb
parent 594 e0576a968171
child 596 dcb432cfeacc
lib/update.operations: implement choose_zone to choose correct base for zone from settings/*.zone
lib/update.operations
--- a/lib/update.operations	Sat Mar 24 10:38:57 2012 +0200
+++ b/lib/update.operations	Thu Apr 12 15:04:34 2012 +0300
@@ -167,20 +167,35 @@
     copy_generic $out $src
 }
 
+## Return the first zone that exists under $DATA/$name.zone
+#
+#   base=$(choose_zone $name...)
+function choose_zone {
+    # look
+    for name in "$@"; do
+        if [ $name ] && [ -e $DATA/$name.zone ]; then
+            echo $name
+            return 0
+        fi
+    done
+    
+    # failed to find
+    die "Unable to find zone in $DATA/*.zone: $@"
+}
+
 ## Expand zone file from source using $BIN/expand-zone:
 #
 #   update_zone $view   $zone   [$base]
 #
-# Processed $DATA/$base zone data through $BIN/expand-zone, writing output to $ZONES/$view/$zone.
+# 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 lnk=$ZONES/$base
-
     local serial=$SERIALS/$base.serial
 
     if check_update $out $src $serial; then