lib/update.utils
branchdns-new
changeset 82 26a307558602
parent 69 88a7683efc54
child 83 5a83f2abc0dd
--- a/lib/update.utils	Mon Dec 16 21:53:41 2013 +0200
+++ b/lib/update.utils	Tue Dec 17 00:04:00 2013 +0200
@@ -1,9 +1,7 @@
 #!/bin/bash
-# vim: set ft=sh :
 #
 # Utility functions
 
-
 ### Command execution
 ## Execute command, possibly logging its execution.
 #
@@ -16,7 +14,6 @@
     "$@" || die "Failed"
 }
 
-### Command execution
 ## Execute command as a test, logging its execution at log_cmd
 #
 #   cmd_test $cmd... && ... || ...
@@ -32,12 +29,9 @@
 #   indent  "    " $cmd...
 #
 # Output is kept on stdout, exit status is that of the given command.
-# Also logs the executed command at log_cmd level..
 function indent () {
     local indent=$1; shift
 
-    log_cmd "$@"
-
     "$@" | sed "s/^/$indent/"
 
     return ${PIPESTATUS[0]}
@@ -45,24 +39,25 @@
 
 
 ### FS utils
-# Create dir in $ROOT if not exists.
+# Create dir if not exists.
 function ensure_dir {
     local dir=$1
 
-    if [ ! -d $ROOT/$dir ]; then
+    if [ ! -d $dir ]; then
         log_warn "Creating output dir: $dir"
-        cmd mkdir $ROOT/$dir
+        cmd mkdir $dir
     fi
 }
 
-## Output absolute path from $ROOT:
+## Output absolute path
 #
 #   abspath $path
 #
+# XXX: improve...?
 function abspath () {
     local path=$1
 
-    echo "$ROOT/$path"
+    echo "$SRV/$path"
 }
 
 ## List names of files in dir:
@@ -71,10 +66,13 @@
 #
 function list_files {
     local dir=$1
-    local glob=$2
+    local glob=${2:-*}
     local name=
 
     for file in $dir/$glob; do
+        # only files
+        [ -f $file ] || continue
+
         # strip prefix
         name=${file#$dir/}
         name=${name%$glob}
@@ -83,50 +81,11 @@
     done
 }
 
-### HG wrappers
-# Run `hg ...` within $REPO.
-function hg {
-    local repo=$REPO
-
-    cmd $HG -R $ROOT/$repo "${HG_ARGS[@]}" "$@"
-}
-
-# Does the repo have local modifications?
-function hg_modified {
-    hg id | grep -q '+'
+## List names of files in dirs..
+function list_dirs {
+    for dir in "$@"; do
+        for file in $dir/*; do
+            echo -n "${file#$dir/}"
+        done
+    done
 }
-
-# Output possible -u flag for commit.
-function hg_user {
-    if [ ${SUDO_USER:-} ]; then
-        echo '-u' "$SUDO_USER"
-
-    elif [ $HOME ] && [ -e $HOME/.hgrc ]; then
-        debug "using .hgrc user"
-        echo ''
-
-    else
-        echo '-u' "$USER"
-    fi
-}
-
-# Show changes in repo
-function hg_diff {
-    # just stat hidden files, but show the rest
-    hg diff --stat -I "$REPO/$REPO_HIDE"
-    hg diff -X "$REPO/$REPO_HIDE"
-}
-
-## Commit changes in repo, with given message:
-#
-#   hg_commit   $msg
-#
-function hg_commit {
-    local msg=$1
-    local user_opt=$(hg_user)
-    
-    debug "$user_opt: $msg"
-    hg commit $user_opt -m "$msg"
-}
-
-