Browse Source

Update own dog food to v0.0.6

It looks .dirty as we had to update in 2 steps due to a bug in v0.0.5
Alois Mahdal 9 years ago
parent
commit
68af743ce2
5 changed files with 135 additions and 31 deletions
  1. 62
    17
      utils/mkit/include/build.sh
  2. 37
    10
      utils/mkit/include/deploy.sh
  3. 27
    2
      utils/mkit/include/mkit.sh
  4. 4
    1
      utils/mkit/make
  5. 5
    1
      utils/mkit/mkit.mk

+ 62
- 17
utils/mkit/include/build.sh View File

@@ -19,17 +19,41 @@ build1() {
19 19
     #
20 20
     # Process one skeleton
21 21
     #
22
-    local srcpath dstpath
23
-    srcpath=$1
24
-    dstpath=${srcpath%.skel}
25
-    case $dstpath in
26
-        *.md) <"$srcpath" expand_includes | expand_variables >"$dstpath" ;;
27
-        *)    <"$srcpath"                   expand_variables >"$dstpath" ;;
28
-    esac
22
+    local srcpath="$1"
23
+    local dstpath="$2"
24
+    local ftype="$3"
25
+    test -n "$dstpath"  || dstpath=${srcpath%.skel}
26
+    test -n "$ftype"    || ftype=$(guess_ftype "$dstpath")
27
+    debug_var srcpath dstpath ftype
28
+    <"$srcpath" build1_ftype "$ftype" >"$dstpath"
29 29
     mkdir -p "$MKIT_LOCAL"
30 30
     echo "$dstpath" >> "$MKIT_LOCAL/built.lst"
31 31
 }
32 32
 
33
+guess_ftype() {
34
+    #
35
+    # Guess file type from destination path $1
36
+    #
37
+    local dstpath="$1"
38
+    case $dstpath in
39
+        *.md) echo markdown    ;;
40
+        *)    echo MKIT_COMMON ;;
41
+    esac
42
+}
43
+
44
+build1_ftype() {
45
+    #
46
+    # Build a file of type $1
47
+    #
48
+    local ftype="$1"
49
+    case $ftype in
50
+        MKIT_COMMON)    expand_variables "vars" ;;
51
+        markdown)       expand_includes | expand_variables "vars" ;;
52
+        rpmstuff)       expand_variables "vars" "rpmstuff:vars" ;;
53
+        *)              die "unknown file type: $ftype" ;;
54
+    esac
55
+}
56
+
33 57
 build_manpages() {
34 58
     local manfile mdfile
35 59
     if command -v ronn >/dev/null;
@@ -64,16 +88,32 @@ dist() {
64 88
     #
65 89
     # Create distributable tarball
66 90
     #
91
+    #FIXME: lacking Makefile skills, we do this step twice fot
92
+    #       rpmstuff, hence -f hack for gzip
93
+    #
67 94
     local version=$(get_version)
68 95
     local dirname=$MKIT_PKGNAME-$version
69 96
     mkdir -p "$dirname"
70 97
     ini values "lists:dist" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
71 98
     sed -i -e "s/^VERSION = .*/VERSION = $version/" "$dirname/config.mk"
72 99
     tar -cf "$dirname.tar" "$dirname"
73
-    gzip "$dirname.tar"
100
+    gzip -f "$dirname.tar"      # see above FIXME
101
+    mkdir -p "$MKIT_LOCAL"
102
+    echo "$dirname.tar.gz" >> "$MKIT_LOCAL/built.lst"
74 103
     rm -rf "$dirname"
75 104
 }
76 105
 
106
+rpmstuff() {
107
+    #
108
+    # Build specfile
109
+    #
110
+    local specname="$(ini 1value ENV:PKGNAME).spec"
111
+    local specsrc="$(ini 1value "rpmstuff:spec_skel")"
112
+    test -n "$specsrc" || die "rpmstuff:spec_skel not specified"
113
+    test -f "$specsrc" || die "specfile template not found: $specsrc"
114
+    build1 "$specsrc" "$specname"
115
+}
116
+
77 117
 expand_includes() {
78 118
     #
79 119
     # Expand include directives
@@ -101,19 +141,24 @@ expand_includes() {
101 141
 
102 142
 expand_variables() {
103 143
     #
104
-    # Expand variable values
144
+    # Expand variables from sections $@
105 145
     #
106 146
     local script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
107
-    local varname varvalue
108
-    ini lskeys "vars" \
109
-      | while read varname;
110
-        do
111
-            varvalue="$(ini 1value "vars:$varname" | sed -e 's/\$/\\$/' )"
112
-            echo "s|$varname|$varvalue|;" >> "$script"
113
-        done
147
+    local section varname varvalue
148
+    for section in "$@";
149
+    do
150
+        debug_var section
151
+        ini lskeys "$section" \
152
+          | while read varname;
153
+            do
154
+                varvalue="$(ini 1value "$section:$varname" | sed -e 's/\$/\\$/' )"
155
+                echo "s|$varname|$varvalue|;" >> "$script"
156
+                debug_var varname varvalue
157
+            done
158
+    done
114 159
     echo "s|__CODENAME__|$CODENAME|;"     >> "$script"
115 160
     echo "s|__VERSION__|$(get_version)|;" >> "$script"
116
-    perl -wp "$script"
161
+    perl -wp "$script" || die "expand_variables failed"
117 162
     rm "$script"
118 163
 }
119 164
 

+ 37
- 10
utils/mkit/include/deploy.sh View File

@@ -1,12 +1,25 @@
1 1
 #!/bin/bash
2 2
 
3
+_maybe() {
4
+    #
5
+    # Call the deploy command $1 $@ unless in dry mode
6
+    #
7
+    debug "$@"
8
+    local cmd="$1"; shift
9
+    $MKIT_DRY && return
10
+    case "$cmd" in
11
+        cp|rm|rmdir|chmod|mkdir) $cmd "$@" ;;
12
+        install)                 command -p install "$@" ;;
13
+        *)                       die "bad command called";;
14
+    esac
15
+}
3 16
 
4 17
 check_env() {
5 18
     #
6
-    # Check that environment variables have been set properly
19
+    # Check that critical variables are set correctly
7 20
     #
8
-    PREFIX="$(readlink -m "$PREFIX")"
9
-    test -d "$PREFIX" || die "PREFIX points to non-existent directory: $PREFIX"
21
+    test -n "$destdir" || die "could not determine DESTDIR"
22
+    test -d "$destdir" || die "DESTDIR: no such directory: $destdir"
10 23
 }
11 24
 
12 25
 deploy_item() {
@@ -37,14 +50,26 @@ deploy_item() {
37 50
     local mode="${3:-$MKIT_DEFAULT_MODE}"
38 51
     if test -d "$src";
39 52
     then
40
-        mkdir -p "$(dirname "$dst")"
41
-        cp -Tvr "$src" "$dst"
53
+        _maybe mkdir -vp "$(dirname "$dst")"
54
+        _maybe cp -Tvr "$src" "$dst"
42 55
         find "$dst" -type f -print0 | xargs -0 chmod -c "$mode"
43 56
     else
44
-        command -p install -DTvm "$mode" "$src" "$dst"
57
+        _maybe install -DTvm "$mode" "$src" "$dst"
45 58
     fi
46 59
 }
47 60
 
61
+get_destdir() {
62
+    #
63
+    # Get DESTDIR: first from ENV:DESTDIR, then the default
64
+    #
65
+    {
66
+        ini 1value ENV:DESTDIR | grep . && return
67
+        echo "$MKIT_DEFAULT_DESTDIR"
68
+    } \
69
+      | xargs readlink -m \
70
+      | grep -m 1 .
71
+}
72
+
48 73
 get_dst() {
49 74
     #
50 75
     # Find out target path for src file $2 of group $1
@@ -61,15 +86,16 @@ get_root() {
61 86
     local grp="$1"
62 87
     local root=$(ini 1value "roots:$grp")
63 88
     test -n "$root" || die "missing in config.ini: roots:$grp"
64
-    echo "$root"
89
+    echo "$destdir/$root"
65 90
 }
66 91
 
67 92
 install() {
68 93
     #
69 94
     # Install product
70 95
     #
71
-    check_env
72 96
     local dst group mode src
97
+    local destdir=$(get_destdir)
98
+    check_env
73 99
     ini values "lists:group" \
74 100
       | while read group;
75 101
         do
@@ -89,8 +115,9 @@ uninstall() {
89 115
     #
90 116
     # Uninstall product
91 117
     #
92
-    check_env
93 118
     local dst group src
119
+    local destdir=$(get_destdir)
120
+    check_env
94 121
     ini values "lists:group" \
95 122
       | while read group;
96 123
         do
@@ -98,7 +125,7 @@ uninstall() {
98 125
               | while read src;
99 126
                 do
100 127
                     dst=$(get_dst "$group" "$src")
101
-                    rm -vrf "$dst"
128
+                    _maybe rm -vrf "$dst"
102 129
                 done
103 130
         done
104 131
 }

+ 27
- 2
utils/mkit/include/mkit.sh View File

@@ -26,6 +26,31 @@ mkit_init() {
26 26
      || die "MKIT_LOCAL must be non-blank: '$MKIT_LOCAL'"
27 27
 }
28 28
 
29
+debug() {
30
+    #
31
+    # Print debug message
32
+    #
33
+    $MKIT_DEBUG || return 0
34
+    echo "MKIT_DEBUG: ${FUNCNAME[1]}()" "$@" >&2
35
+}
36
+
37
+debug_var() {
38
+    #
39
+    # Print debug message
40
+    #
41
+    $MKIT_DEBUG || return 0
42
+    local __mkit_debug_var_name__
43
+    for __mkit_debug_var_name__ in "$@";
44
+    do
45
+        {
46
+            echo -n "MKIT_DEBUG: ${FUNCNAME[1]}():"
47
+            echo -n " $__mkit_debug_var_name__"
48
+            echo -n "='${!__mkit_debug_var_name__}'"
49
+            echo
50
+        } >&2
51
+    done
52
+}
53
+
29 54
 die() {
30 55
     #
31 56
     # Exit with message and non-zero exit status
@@ -46,10 +71,10 @@ route() {
46 71
     # Call correct function based on $1
47 72
     #
48 73
     case $1 in
49
-        build|build_manpages|clean|dist|install|release_?|uninstall)
74
+        build|build_manpages|clean|dist|rpmstuff|install|release_?|uninstall)
50 75
             $1
51 76
             ;;
52 77
         *)
53
-            echo "usage: $(basename "$0") build|clean|dist|install|uninstall" >&2
78
+            echo "usage: $(basename "$0") build|clean|dist|rpmstuff|install|uninstall" >&2
54 79
     esac
55 80
 }

+ 4
- 1
utils/mkit/make View File

@@ -6,10 +6,13 @@ die() {
6 6
     echo "$@" && exit 9
7 7
 }
8 8
 
9
-export MKIT_VERSION=0.0.4
9
+export MKIT_VERSION=0.0.6+dirty
10 10
 
11 11
 export MKIT_DIR=${MKIT_DIR:-$(dirname "$0")}
12 12
 export MKIT_LOCAL=${MKIT_LOCAL:-.mkit}
13
+export MKIT_DRY=${MKIT_DRY:-false}
14
+export MKIT_DEFAULT_DESTDIR=${MKIT_DEFAULT_DESTDIR:-/}
15
+export MKIT_DEBUG=${MKIT_DEBUG:-false}
13 16
 
14 17
 . "$MKIT_DIR/include/mkit.sh" || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"
15 18
 

+ 5
- 1
utils/mkit/mkit.mk View File

@@ -9,6 +9,7 @@ options:
9 9
 	@echo build options:
10 10
 	@echo "VERSION  = ${VERSION}"
11 11
 	@echo "PRERELEASE = ${PRERELEASE}"
12
+	@echo "DESTDIR   = ${DESTDIR}"
12 13
 	@echo "PREFIX   = ${PREFIX}"
13 14
 
14 15
 build:
@@ -23,6 +24,9 @@ clean:
23 24
 dist: clean
24 25
 	@$(MKIT_DIR)/make dist
25 26
 
27
+rpmstuff: dist
28
+	@$(MKIT_DIR)/make rpmstuff
29
+
26 30
 install: all
27 31
 	@$(MKIT_DIR)/make install
28 32
 
@@ -38,4 +42,4 @@ release_z:
38 42
 uninstall:
39 43
 	@$(MKIT_DIR)/make uninstall
40 44
 
41
-.PHONY: all options clean dist install uninstall release_x release_y release_z
45
+.PHONY: all options clean dist rpmstuff install uninstall release_x release_y release_z