Browse Source

Add dry mode to skip actyal deploying/removing

Alois Mahdal 9 years ago
parent
commit
73d65fbd25
2 changed files with 17 additions and 4 deletions
  1. 16
    4
      src/include/deploy.sh
  2. 1
    0
      src/make.skel

+ 16
- 4
src/include/deploy.sh View File

1
 #!/bin/bash
1
 #!/bin/bash
2
 
2
 
3
+_maybe() {
4
+    #
5
+    # Call the deploy command $1 $@ unless in dry mode
6
+    #
7
+    local cmd="$1"; shift
8
+    $MKIT_DRY && echo "MKIT_DRY: $cmd" "$@" && return
9
+    case "$cmd" in
10
+        cp|rm|rmdir|chmod|mkdir) $cmd "$@" ;;
11
+        install)                 command -p install "$@" ;;
12
+        *)                       die "bad command called";;
13
+    esac
14
+}
3
 
15
 
4
 check_env() {
16
 check_env() {
5
     #
17
     #
37
     local mode="${3:-$MKIT_DEFAULT_MODE}"
49
     local mode="${3:-$MKIT_DEFAULT_MODE}"
38
     if test -d "$src";
50
     if test -d "$src";
39
     then
51
     then
40
-        mkdir -vp "$(dirname "$dst")"
41
-        cp -Tvr "$src" "$dst"
52
+        _maybe mkdir -vp "$(dirname "$dst")"
53
+        _maybe cp -Tvr "$src" "$dst"
42
         find "$dst" -type f -print0 | xargs -0 chmod -c "$mode"
54
         find "$dst" -type f -print0 | xargs -0 chmod -c "$mode"
43
     else
55
     else
44
-        command -p install -DTvm "$mode" "$src" "$dst"
56
+        _maybe install -DTvm "$mode" "$src" "$dst"
45
     fi
57
     fi
46
 }
58
 }
47
 
59
 
98
               | while read src;
110
               | while read src;
99
                 do
111
                 do
100
                     dst=$(get_dst "$group" "$src")
112
                     dst=$(get_dst "$group" "$src")
101
-                    rm -vrf "$dst"
113
+                    _maybe rm -vrf "$dst"
102
                 done
114
                 done
103
         done
115
         done
104
 }
116
 }

+ 1
- 0
src/make.skel View File

10
 
10
 
11
 export MKIT_DIR=${MKIT_DIR:-$(dirname "$0")}
11
 export MKIT_DIR=${MKIT_DIR:-$(dirname "$0")}
12
 export MKIT_LOCAL=${MKIT_LOCAL:-.mkit}
12
 export MKIT_LOCAL=${MKIT_LOCAL:-.mkit}
13
+export MKIT_DRY=${MKIT_DRY:-false}
13
 
14
 
14
 . "$MKIT_DIR/include/mkit.sh" || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"
15
 . "$MKIT_DIR/include/mkit.sh" || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"
15
 
16