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
     #
19
     #
20
     # Process one skeleton
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
     mkdir -p "$MKIT_LOCAL"
29
     mkdir -p "$MKIT_LOCAL"
30
     echo "$dstpath" >> "$MKIT_LOCAL/built.lst"
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
 build_manpages() {
57
 build_manpages() {
34
     local manfile mdfile
58
     local manfile mdfile
35
     if command -v ronn >/dev/null;
59
     if command -v ronn >/dev/null;
64
     #
88
     #
65
     # Create distributable tarball
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
     local version=$(get_version)
94
     local version=$(get_version)
68
     local dirname=$MKIT_PKGNAME-$version
95
     local dirname=$MKIT_PKGNAME-$version
69
     mkdir -p "$dirname"
96
     mkdir -p "$dirname"
70
     ini values "lists:dist" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
97
     ini values "lists:dist" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
71
     sed -i -e "s/^VERSION = .*/VERSION = $version/" "$dirname/config.mk"
98
     sed -i -e "s/^VERSION = .*/VERSION = $version/" "$dirname/config.mk"
72
     tar -cf "$dirname.tar" "$dirname"
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
     rm -rf "$dirname"
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
 expand_includes() {
117
 expand_includes() {
78
     #
118
     #
79
     # Expand include directives
119
     # Expand include directives
101
 
141
 
102
 expand_variables() {
142
 expand_variables() {
103
     #
143
     #
104
-    # Expand variable values
144
+    # Expand variables from sections $@
105
     #
145
     #
106
     local script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
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
     echo "s|__CODENAME__|$CODENAME|;"     >> "$script"
159
     echo "s|__CODENAME__|$CODENAME|;"     >> "$script"
115
     echo "s|__VERSION__|$(get_version)|;" >> "$script"
160
     echo "s|__VERSION__|$(get_version)|;" >> "$script"
116
-    perl -wp "$script"
161
+    perl -wp "$script" || die "expand_variables failed"
117
     rm "$script"
162
     rm "$script"
118
 }
163
 }
119
 
164
 

+ 37
- 10
utils/mkit/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
+    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
 check_env() {
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
 deploy_item() {
25
 deploy_item() {
37
     local mode="${3:-$MKIT_DEFAULT_MODE}"
50
     local mode="${3:-$MKIT_DEFAULT_MODE}"
38
     if test -d "$src";
51
     if test -d "$src";
39
     then
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
         find "$dst" -type f -print0 | xargs -0 chmod -c "$mode"
55
         find "$dst" -type f -print0 | xargs -0 chmod -c "$mode"
43
     else
56
     else
44
-        command -p install -DTvm "$mode" "$src" "$dst"
57
+        _maybe install -DTvm "$mode" "$src" "$dst"
45
     fi
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
 get_dst() {
73
 get_dst() {
49
     #
74
     #
50
     # Find out target path for src file $2 of group $1
75
     # Find out target path for src file $2 of group $1
61
     local grp="$1"
86
     local grp="$1"
62
     local root=$(ini 1value "roots:$grp")
87
     local root=$(ini 1value "roots:$grp")
63
     test -n "$root" || die "missing in config.ini: roots:$grp"
88
     test -n "$root" || die "missing in config.ini: roots:$grp"
64
-    echo "$root"
89
+    echo "$destdir/$root"
65
 }
90
 }
66
 
91
 
67
 install() {
92
 install() {
68
     #
93
     #
69
     # Install product
94
     # Install product
70
     #
95
     #
71
-    check_env
72
     local dst group mode src
96
     local dst group mode src
97
+    local destdir=$(get_destdir)
98
+    check_env
73
     ini values "lists:group" \
99
     ini values "lists:group" \
74
       | while read group;
100
       | while read group;
75
         do
101
         do
89
     #
115
     #
90
     # Uninstall product
116
     # Uninstall product
91
     #
117
     #
92
-    check_env
93
     local dst group src
118
     local dst group src
119
+    local destdir=$(get_destdir)
120
+    check_env
94
     ini values "lists:group" \
121
     ini values "lists:group" \
95
       | while read group;
122
       | while read group;
96
         do
123
         do
98
               | while read src;
125
               | while read src;
99
                 do
126
                 do
100
                     dst=$(get_dst "$group" "$src")
127
                     dst=$(get_dst "$group" "$src")
101
-                    rm -vrf "$dst"
128
+                    _maybe rm -vrf "$dst"
102
                 done
129
                 done
103
         done
130
         done
104
 }
131
 }

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

26
      || die "MKIT_LOCAL must be non-blank: '$MKIT_LOCAL'"
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
 die() {
54
 die() {
30
     #
55
     #
31
     # Exit with message and non-zero exit status
56
     # Exit with message and non-zero exit status
46
     # Call correct function based on $1
71
     # Call correct function based on $1
47
     #
72
     #
48
     case $1 in
73
     case $1 in
49
-        build|build_manpages|clean|dist|install|release_?|uninstall)
74
+        build|build_manpages|clean|dist|rpmstuff|install|release_?|uninstall)
50
             $1
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
     esac
79
     esac
55
 }
80
 }

+ 4
- 1
utils/mkit/make View File

6
     echo "$@" && exit 9
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
 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}
14
+export MKIT_DEFAULT_DESTDIR=${MKIT_DEFAULT_DESTDIR:-/}
15
+export MKIT_DEBUG=${MKIT_DEBUG:-false}
13
 
16
 
14
 . "$MKIT_DIR/include/mkit.sh" || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"
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
 	@echo build options:
9
 	@echo build options:
10
 	@echo "VERSION  = ${VERSION}"
10
 	@echo "VERSION  = ${VERSION}"
11
 	@echo "PRERELEASE = ${PRERELEASE}"
11
 	@echo "PRERELEASE = ${PRERELEASE}"
12
+	@echo "DESTDIR   = ${DESTDIR}"
12
 	@echo "PREFIX   = ${PREFIX}"
13
 	@echo "PREFIX   = ${PREFIX}"
13
 
14
 
14
 build:
15
 build:
23
 dist: clean
24
 dist: clean
24
 	@$(MKIT_DIR)/make dist
25
 	@$(MKIT_DIR)/make dist
25
 
26
 
27
+rpmstuff: dist
28
+	@$(MKIT_DIR)/make rpmstuff
29
+
26
 install: all
30
 install: all
27
 	@$(MKIT_DIR)/make install
31
 	@$(MKIT_DIR)/make install
28
 
32
 
38
 uninstall:
42
 uninstall:
39
 	@$(MKIT_DIR)/make uninstall
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