lib/pvl: fixfix
authorTero Marttila <tero.marttila@aalto.fi>
Thu, 26 Feb 2015 22:53:26 +0200
changeset 629 7214fe5c6fac
parent 628 b10ad946d01d
child 630 18939b861476
lib/pvl: fixfix
lib/pvl/apply.sh
lib/pvl/apply/cat.sh
lib/pvl/apply/cmd.sh
lib/pvl/commit.sh
lib/pvl/commit/git.sh
lib/pvl/commit/hg.sh
lib/pvl/hosts/dhcp.sh
lib/pvl/hosts/update.sh
lib/pvl/hosts/zone.sh
lib/pvl/test.sh
--- a/lib/pvl/apply.sh	Thu Feb 26 22:36:05 2015 +0200
+++ b/lib/pvl/apply.sh	Thu Feb 26 22:53:26 2015 +0200
@@ -47,14 +47,14 @@
     debug "$out"
 
     if [ ${#@} -eq 1 ]; then
-        debug "  update: unknown deps"
-        return 2
+        debug "  update: empty deps"
+        return 0
 
     elif [ ! -e "$out" ]; then
         debug "  update: dest missing"
         return 2
         
-    elif [ "$APPLY" = 1]; then
+    elif [ "$APPLY" = 1 ]; then
         debug "  update: forced"
         return 2
     fi
--- a/lib/pvl/apply/cat.sh	Thu Feb 26 22:36:05 2015 +0200
+++ b/lib/pvl/apply/cat.sh	Thu Feb 26 22:53:26 2015 +0200
@@ -7,7 +7,7 @@
     elif [ "$APPLY" = 0 ]; then
         log_noop "$out: noop cat: $tgt"
     else
-        log_update "$out: cat ${src@}"
+        log_apply "$out: cat ${src@}"
 
         cmd_apply "$out" \
             cat "${src[@]}"
--- a/lib/pvl/apply/cmd.sh	Thu Feb 26 22:36:05 2015 +0200
+++ b/lib/pvl/apply/cmd.sh	Thu Feb 26 22:53:26 2015 +0200
@@ -16,7 +16,7 @@
         debug "  changes:"
 
         # terse
-        indent "        " diff --unified=1 "$out" "$tmp" || true
+        cmd_indent "        " diff --unified=1 "$out" "$tmp" || true
     fi
     
     # deploy
@@ -27,7 +27,7 @@
         cmd rm "$tmp"
     else
         # commit
-        debug "  deploy"
+        debug "  apply"
 
         cmd mv "$tmp" "$out"
     fi
--- a/lib/pvl/commit.sh	Thu Feb 26 22:36:05 2015 +0200
+++ b/lib/pvl/commit.sh	Thu Feb 26 22:53:26 2015 +0200
@@ -3,7 +3,7 @@
 . $LIB/pvl/commit/git.sh
 . $LIB/pvl/commit/hg.sh
 
-commit_GETOPTS='cCm:'
+commit_GETOPTS='cCm:M'
 
 COMMIT=
 COMMIT_DIFF=
@@ -15,6 +15,7 @@
     -C      do not commit changes
     -c      commit changes
     -m MSG  commit message
+    -M      interactive commit message
 END
 }
 
@@ -27,6 +28,7 @@
         C)  COMMIT=0 ;;
 
         m)  COMMIT_MSG="$optarg" ;;
+        M)  COMMIT_MSG= ;;
         
         n)  COMMIT=0 ;;
         p)  COMMIT_DIFF=1 ;;
@@ -68,7 +70,7 @@
     if [ "$COMMIT" = 1 ]; then
         log_force   "$repo: force commit"
 
-        [ "$COMMIT_DIFF" ] && indent "    " ${commit}_diff "$repo" || true
+        [ "$COMMIT_DIFF" ] && cmd_indent "    " ${commit}_diff "$repo" || true
 
         ${commit}_commit "$repo" "$commit_msg"
 
@@ -79,11 +81,11 @@
         log_noop    "$repo: skip commit"
         
         # still show diff, though
-        [ "$COMMIT_DIFF" ] && indent "    " ${commit}_diff "$repo" || true
+        [ "$COMMIT_DIFF" ] && cmd_indent "    " ${commit}_diff "$repo" || true
     else
         log_apply   "$repo: commit: $commit_msg"
 
-        [ "$COMMIT_DIFF" ] && indent "    " ${commit}_diff "$repo" || true
+        [ "$COMMIT_DIFF" ] && cmd_indent "    " ${commit}_diff "$repo" || true
 
         ${commit}_commit "$repo" "$commit_msg"
     fi
--- a/lib/pvl/commit/git.sh	Thu Feb 26 22:36:05 2015 +0200
+++ b/lib/pvl/commit/git.sh	Thu Feb 26 22:53:26 2015 +0200
@@ -3,7 +3,6 @@
 GIT=/usr/bin/git
 GIT_ARGS=()
 
-
 function git_probe {
     local repo=$1
 
@@ -13,18 +12,28 @@
 ## Run `git ...` within $REPO.
 function git {
     local repo=$1
-    cmd $GIT -C "$repo" "${GIT_ARGS[@]:-}" "${@:2}"
+    cmd $GIT -C "$repo" ${GIT_ARGS[@]:-} "${@:2}"
+}
+
+function git_test {
+    local repo=$1
+    cmd_test $GIT -C "$repo" ${GIT_ARGS[@]:-} "${@:2}"
 }
 
 ## Does the repo have local modifications?
 function git_modified {
     local repo=$1
 
-    git $repo diff --quiet
+    if git_test $repo diff --quiet; then
+        # unmodified
+        return 1
+    else
+        return 0
+    fi
 }
 
 ## Get the date for the current commit as an unix timestamp
-function hg_time {
+function git_time {
     local repo=$1
 
     git $repo log -1 --format=format:%ct
@@ -54,7 +63,13 @@
     
     if [ "$msg" ]; then
         opts+=('-m' "$msg")
+    else
+        opts+=('--allow-empty-message')
     fi
-   
-    git $repo commit -a "${opts[@]:-}"
+    
+    if [ ${#opts[@]} = 0 ]; then
+        git $repo commit -a
+    else
+        git $repo commit -a "${opts[@]}"
+    fi
 }
--- a/lib/pvl/commit/hg.sh	Thu Feb 26 22:36:05 2015 +0200
+++ b/lib/pvl/commit/hg.sh	Thu Feb 26 22:53:26 2015 +0200
@@ -66,5 +66,9 @@
         opts+=('-m' "$msg")
     fi
    
-    hg $repo commit "${opts[@]:-}"
+    if [ ${#opts[@]} = 0 ]; then
+        hg $repo commit
+    else
+        hg $repo commit "${opts[@]}"
+    fi
 }
--- a/lib/pvl/hosts/dhcp.sh	Thu Feb 26 22:36:05 2015 +0200
+++ b/lib/pvl/hosts/dhcp.sh	Thu Feb 26 22:53:26 2015 +0200
@@ -65,10 +65,10 @@
 #
 # noop's if we haven't reloaded zones
 function reload_dhcp {
-    if [ "$RELOAD" = 1 ]; then
+    if [ "$UPDATE_RELOAD" = 1 ]; then
         log_force "Reload DHCP"
         
-    elif [ "$RELOAD" = 0 ]; then
+    elif [ "$UPDATE_RELOAD" = 0 ]; then
         log_noop "Skip reload DHCP"
 
         return
--- a/lib/pvl/hosts/update.sh	Thu Feb 26 22:36:05 2015 +0200
+++ b/lib/pvl/hosts/update.sh	Thu Feb 26 22:53:26 2015 +0200
@@ -67,7 +67,7 @@
         log_warn "Using local unix time for uncommited changes: $serial"
     else
         serial=$(commit_time $SRV)
-        log_update "Using HG commit timestamp: $serial"
+        log_apply "Using commit timestamp: $serial"
     fi
 
     ## Hosts
--- a/lib/pvl/hosts/zone.sh	Thu Feb 26 22:36:05 2015 +0200
+++ b/lib/pvl/hosts/zone.sh	Thu Feb 26 22:53:26 2015 +0200
@@ -33,10 +33,10 @@
 function update_hosts_reverse {
     local out="$1"
     local src="$2"
-    local srcs=($src/*)
+    local srcs=$src/*
     local msg="$out: Generating reverse hosts zone: $src"
 
-    if apply_check "$out" "${srcs[@]}"; then
+    if apply_check "$out" $srcs; then
         log_skip "$msg"
     else
         log_apply "$msg"
@@ -108,7 +108,7 @@
     local old=$(test -e "$out" && cat "$out" || echo '')
     
     # test
-    if [ "$SERIAL" = 1 ]; then
+    if [ "$UPDATE_SERIAL" = 1 ]; then
         log_force "$out: Force serial $old <- $serial"
 
     elif apply_check "$out" "${@:3}"; then
@@ -116,7 +116,7 @@
         
         return
 
-    elif [ "$SERIAL" = 0 ]; then
+    elif [ "$UPDATE_SERIAL" = 0 ]; then
         log_noop "$out: Noop serial: $old <- $serial"
         
         return
@@ -140,7 +140,7 @@
 
     if [ -n "$serial" -a -f "$serial" ]; then
         serial_opt="--serial=$(cat "$serial")"
-    elif [ "$SERIAL" = 0 ]; then
+    elif [ "$UPDATE_SERIAL" = 0 ]; then
         warn "$out: noop'd serial, omitting"
     else
         fail "$out: missing serial: $serial"
@@ -181,10 +181,10 @@
 #
 # Invokes `rndc reload`, showing its output.
 function reload_zones {
-    if [ "$RELOAD" = 1 ]; then
+    if [ "$UPDATE_RELOAD" = 1 ]; then
         log_force "Reload zones"
         
-    elif [ "$RELOAD" = 0 ]; then
+    elif [ "$UPDATE_RELOAD" = 0 ]; then
         log_noop "Skip reload zones"
         
         return
--- a/lib/pvl/test.sh	Thu Feb 26 22:36:05 2015 +0200
+++ b/lib/pvl/test.sh	Thu Feb 26 22:53:26 2015 +0200
@@ -14,7 +14,7 @@
     else
         log_error "$src: test: Failed"
 
-        indent "    " "$cmd" "${args[@]}"
+        cmd_indent "    " "$cmd" "${args[@]}"
 
         return 1
     fi