Browse Source

Update mkit to version from fastfoo 0.7.0+master.g7e6e358

Alois Mahdal 9 years ago
parent
commit
f80dd649d1

+ 30
- 41
utils/mkit/include/build.sh View File

@@ -1,6 +1,6 @@
1 1
 #!/bin/bash
2 2
 
3
-. $MKIT_DIR/include/ini.sh || die "cannot import ini.sh"
3
+. "$MKIT_DIR/include/ini.sh" || die "cannot import ini.sh"
4 4
 
5 5
 
6 6
 build() {
@@ -23,15 +23,10 @@ build1() {
23 23
     srcpath=$1
24 24
     dstpath=${srcpath%.skel}
25 25
     case $dstpath in
26
-        *.md)   cat $srcpath \
27
-                  | expand_includes \
28
-                  | expand_variables \
29
-                > $dstpath ;;
30
-        *)      cat $srcpath \
31
-                  | expand_variables \
32
-                > $dstpath ;;
26
+        *.md) <"$srcpath" expand_includes | expand_variables >"$dstpath" ;;
27
+        *)    <"$srcpath"                   expand_variables >"$dstpath" ;;
33 28
     esac
34
-    echo $dstpath >> built.list
29
+    echo "$dstpath" >> built.list
35 30
 }
36 31
 
37 32
 build_manpages() {
@@ -41,9 +36,9 @@ build_manpages() {
41 36
         ini lskeys "files:man" \
42 37
           | while read manfile;
43 38
             do
44
-                mdfile=$manfile.md
45
-                ronn -r $mdfile
46
-                echo $manfile >> built.list
39
+                mdfile="$manfile.md"
40
+                ronn -r "$mdfile"
41
+                echo "$manfile" >> built.list
47 42
             done
48 43
     else
49 44
         echo "ronn is not installed"
@@ -56,9 +51,10 @@ clean() {
56 51
     # Clean up tree after building
57 52
     #
58 53
     test -f built.list && {
59
-        cat built.list | xargs rm -f
54
+        <built.list xargs rm -f
60 55
         rm -f built.list
61
-    } || :
56
+    }
57
+    true
62 58
 }
63 59
 
64 60
 dist() {
@@ -67,13 +63,13 @@ dist() {
67 63
     #
68 64
     local version=$(get_version)
69 65
     local dirname=$MKIT_PKGNAME-$version
70
-    mkdir -p $dirname
66
+    mkdir -p "$dirname"
71 67
     local item
72
-    cp -R $(ini values "lists:dist") $dirname
73
-    sed -i -e "s/^VERSION = .*/VERSION = $version/" $dirname/config.mk
74
-    tar -cf $dirname.tar $dirname
75
-    gzip $dirname.tar
76
-    rm -rf $dirname
68
+    cp -R "$(ini values "lists:dist")" "$dirname"
69
+    sed -i -e "s/^VERSION = .*/VERSION = $version/" "$dirname/config.mk"
70
+    tar -cf "$dirname.tar" "$dirname"
71
+    gzip "$dirname.tar"
72
+    rm -rf "$dirname"
77 73
 }
78 74
 
79 75
 expand_includes() {
@@ -111,12 +107,12 @@ expand_variables() {
111 107
       | while read varname;
112 108
         do
113 109
             varvalue="$(ini 1value "vars:$varname" | sed -e 's/\$/\\$/' )"
114
-            echo "s|$varname|$varvalue|;" >> $script
110
+            echo "s|$varname|$varvalue|;" >> "$script"
115 111
         done
116
-    echo "s|__CODENAME__|$CODENAME|;"     >> $script
117
-    echo "s|__VERSION__|$(get_version)|;" >> $script
118
-    perl -wp $script
119
-    rm $script
112
+    echo "s|__CODENAME__|$CODENAME|;"     >> "$script"
113
+    echo "s|__VERSION__|$(get_version)|;" >> "$script"
114
+    perl -wp "$script"
115
+    rm "$script"
120 116
 }
121 117
 
122 118
 get_version() {
@@ -161,10 +157,6 @@ get_version() {
161 157
     # meta-data is to *identify* the code, and provide safe path back
162 158
     # to tree; commit refs are already perfect for that.
163 159
     #
164
-    # FIXME:  The assumpton "if we are in git repo, we can read version
165
-    #         from tags" fails if we are in shallow clone made from
166
-    #         other than a tagged commit.
167
-    #
168 160
     # FIXME:  Using PRERELEASE for release IDs may not be compatible with
169 161
     #         release strategy implemented in release.sh
170 162
     #
@@ -184,19 +176,16 @@ get_version() {
184 176
         then    # the tree is "dirty", i.e. has been edited
185 177
             local dirty=dirty
186 178
         fi
187
-        version=${lasttag:1}
179
+        test -n "$lasttag" && version=${lasttag:1}
188 180
         local suffix=""
189
-        case $prerl:$commit:$dirty in
190
-            ::)        suffix=""                       ;;
191
-            ::dirty)   suffix="+$dirty"                ;;
192
-            :*:)       suffix="+$commit"               ;;
193
-            :*:dirty)  suffix="+$commit"               ;;
194
-            *::)       suffix="-$prerl"                ;;
195
-            *::dirty)  suffix="-$prerl+$dirty"         ;;
196
-            *:*:)      suffix="-$prerl+$commit"        ;;
197
-            *:*:dirty) suffix="-$prerl+$commit.$dirty" ;;
181
+        case "$commit:$dirty" in
182
+            :)       suffix=""                ;;
183
+            :dirty)  suffix="+$dirty"         ;;
184
+            *:)      suffix="+$commit"        ;;
185
+            *:dirty) suffix="+$commit.$dirty" ;;
198 186
         esac
199
-        version=$version$suffix
187
+        test -b "$prerl" && suffix="-$prerl$suffix"
188
+        version="$version$suffix"
200 189
     fi
201
-    echo $version
190
+    echo "$version"
202 191
 }

+ 50
- 5
utils/mkit/include/deploy.sh View File

@@ -1,13 +1,56 @@
1 1
 #!/bin/bash
2 2
 
3 3
 
4
+check_env() {
5
+    #
6
+    # Check that environment variables have been set properly
7
+    #
8
+    PREFIX="$(readlink -m "$PREFIX")"
9
+    test -d "$PREFIX" || die "PREFIX points to non-existent directory: $PREFIX"
10
+}
11
+
12
+deploy_item() {
13
+    #
14
+    # Deploy item and make it look like wanted
15
+    #
16
+    # usage: deploy_item src dst [mode]
17
+    #
18
+    # Both src and dst must be names of actual items[1],
19
+    # whereas dst must not exist.  On update, dst is
20
+    # usually to be replaced but that is uninstall's
21
+    # job!
22
+    #
23
+    #  [1] Ie. src=foo and dst=/foo/bar does *always*
24
+    #      mean that foo will become 'bar'.  This is
25
+    #      different than traditional `cp` behavior,
26
+    #      when this depends if 'bar' already exists
27
+    #      as a directory.
28
+    #
29
+    # If mode is omitted or empty, MKIT_DEFAULT_MODE is
30
+    # used instead.
31
+    #
32
+    # Directories are copied recursively, and mode is
33
+    # applied only to files.
34
+    #
35
+    local src="$1"
36
+    local dst="$2"
37
+    local mode="${3:-$MKIT_DEFAULT_MODE}"
38
+    if test -d "$src";
39
+    then
40
+        cp -Tvr "$src" "$dst"
41
+        find "$dst" -type f -print0 | xargs -0 chmod -c "$mode"
42
+    else
43
+        command -p install -DTvm "$mode" "$src" "$dst"
44
+    fi
45
+}
46
+
4 47
 get_dst() {
5 48
     #
6 49
     # Find out target path for src file $2 of group $1
7 50
     #
8 51
     local grp=$1
9 52
     local src=$2
10
-    echo "$(get_root $grp)/$(ini 1value "files:$grp:$src")"
53
+    echo "$(get_root "$grp")/$(ini 1value "files:$grp:$src")"
11 54
 }
12 55
 
13 56
 get_root() {
@@ -24,26 +67,28 @@ install() {
24 67
     #
25 68
     # Install product
26 69
     #
70
+    check_env
27 71
     local dst group mode src
28 72
     ini values "lists:group" \
29 73
       | while read group;
30 74
         do
31 75
             mode=$(ini 1value "modes:$group")
32
-            mode=${mode:-$MKIT_DEFAULT_MODE}
33 76
             ini lskeys "files:$group" \
34 77
               | while read src;
35 78
                 do
36 79
                     dst=$(get_dst "$group" "$src")
37
-                    command -p install -DTvm $mode $src "$dst"
80
+                    deploy_item "$src" "$dst" "$mode"
38 81
                 done
39 82
         done
40
-    test -f .autoclean && clean || :
83
+    test -f .autoclean && clean
84
+    true
41 85
 }
42 86
 
43 87
 uninstall() {
44 88
     #
45 89
     # Uninstall product
46 90
     #
91
+    check_env
47 92
     local dst group src
48 93
     ini values "lists:group" \
49 94
       | while read group;
@@ -52,7 +97,7 @@ uninstall() {
52 97
               | while read src;
53 98
                 do
54 99
                     dst=$(get_dst "$group" "$src")
55
-                    rm -vf "$dst"
100
+                    rm -vrf "$dst"
56 101
                 done
57 102
         done
58 103
 }

+ 10
- 10
utils/mkit/include/ini.sh View File

@@ -15,7 +15,7 @@ ini() {
15 15
         1value) fn=_ini_greppath; limit="tail -1" ;;
16 16
         *)      die "incorrect use of \`ini()\`"
17 17
     esac
18
-    cat $MKIT_INI | $fn $arg | $limit
18
+    <"$MKIT_INI" $fn "$arg" | $limit
19 19
 }
20 20
 
21 21
 _ini_cat() {
@@ -66,9 +66,9 @@ _ini_greppath() {
66 66
     #     [files:share]
67 67
     #         my/lib.sh   = proj/my/lib.sh
68 68
     #
69
-    local wnt=$1
70
-    local wntkey=${wnt##*:}
71
-    local wntsec=${wnt%:$wntkey}
69
+    local wnt="$1"
70
+    local wntkey="${wnt##*:}"
71
+    local wntsec="${wnt%:$wntkey}"
72 72
     if test "$wntsec" = 'ENV';
73 73
     then
74 74
         local override="${!wntkey}"
@@ -78,14 +78,14 @@ _ini_greppath() {
78 78
             return
79 79
         fi
80 80
     fi
81
-    _ini_grepsec $wntsec | _ini_grepkey $wntkey
81
+    _ini_grepsec "$wntsec" | _ini_grepkey "$wntkey"
82 82
 }
83 83
 
84 84
 _ini_grepsec() {
85 85
     #
86 86
     # Read one INI section
87 87
     #
88
-    local wnt=$1
88
+    local wnt="$1"
89 89
     local ok=false
90 90
     grep '.' \
91 91
       | grep -v '\s*#' \
@@ -105,17 +105,17 @@ _ini_lskeys() {
105 105
     #
106 106
     # List keys from a section
107 107
     #
108
-    local sct=$1
109
-    _ini_grepsec $sct | cut -d= -f1 | sort | uniq
108
+    local sct="$1"
109
+    _ini_grepsec "$sct" | cut -d= -f1 | sort | uniq
110 110
 }
111 111
 
112 112
 _ini_maybe_expand() {
113 113
     #
114 114
     # Decide whether or not to expand
115 115
     #
116
-    if test $MKIT_INI_EXPAND -gt 0;
116
+    if test "$MKIT_INI_EXPAND" -gt 0;
117 117
     then
118
-        MKIT_INI_EXPAND=$(( $MKIT_INI_EXPAND - 1 )) _ini_expand
118
+        MKIT_INI_EXPAND=$(( --MKIT_INI_EXPAND )) _ini_expand
119 119
     else
120 120
         _ini_cat
121 121
     fi

+ 10
- 13
utils/mkit/include/mkit.sh View File

@@ -1,9 +1,9 @@
1 1
 #!/bin/bash
2 2
 
3
-. $MKIT_DIR/include/build.sh  || die "cannot import build.sh"
4
-. $MKIT_DIR/include/deploy.sh || die "cannot import deploy.sh"
5
-. $MKIT_DIR/include/release.sh || die "cannot import release.sh"
6
-. $MKIT_DIR/include/ini.sh    || die "cannot import ini.sh"
3
+. "$MKIT_DIR/include/build.sh"  || die "cannot import build.sh"
4
+. "$MKIT_DIR/include/deploy.sh" || die "cannot import deploy.sh"
5
+. "$MKIT_DIR/include/release.sh" || die "cannot import release.sh"
6
+. "$MKIT_DIR/include/ini.sh"    || die "cannot import ini.sh"
7 7
 
8 8
 MKIT_INI=${MKIT_INI:-mkit.ini}
9 9
 MKIT_INI_EXPAND=2
@@ -15,23 +15,20 @@ mkit_init() {
15 15
     #
16 16
     # Do basic initialization
17 17
     #
18
-    # Check for ini file, load variables from config.mk, resolve
19
-    # and check for PREFIX
18
+    # Check for ini file, load variables from config.mk
20 19
     #
21 20
     test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
22 21
     tmp=$(mktemp)
23
-    sed -e 's/ = /=/' < config.mk > $tmp
24
-    . $tmp
25
-    rm -f $tmp
26
-    PREFIX="$(readlink -f "$PREFIX")"
27
-    test -d "$PREFIX" || die "PREFIX points to bad directory: $PREFIX"
22
+    sed -e 's/ = /=/' < config.mk > "$tmp"
23
+    . "$tmp"
24
+    rm -f "$tmp"
28 25
 }
29 26
 
30 27
 die() {
31 28
     #
32 29
     # Exit with message and non-zero exit status
33 30
     #
34
-    echo "fatal: $@" >&2
31
+    echo "fatal: $*" >&2
35 32
     exit 4
36 33
 }
37 34
 
@@ -51,6 +48,6 @@ route() {
51 48
             $1
52 49
             ;;
53 50
         *)
54
-            echo "usage: $(basename $0) build|clean|dist|install|uninstall" >&2
51
+            echo "usage: $(basename "$0") build|clean|dist|install|uninstall" >&2
55 52
     esac
56 53
 }

+ 11
- 8
utils/mkit/include/release.sh View File

@@ -13,7 +13,7 @@ __make_ver() {
13 13
         z) new="$oldx.$oldy.$((oldz+1))"    ;;
14 14
         *) die "invalid release level: $1"  ;;
15 15
     esac
16
-    echo $new
16
+    echo "$new"
17 17
 }
18 18
 
19 19
 __release() {
@@ -30,23 +30,26 @@ __release() {
30 30
     git rev-parse HEAD >&/dev/null || die "cannot release outside git repo"
31 31
     local lastfile=$(git diff-tree --no-commit-id --name-only -r HEAD)
32 32
     local lasttag=$(git tag | grep ^v | sort -V | tail -n1)
33
-    local changelog="$(git log --oneline $lasttag..HEAD)"
33
+    local changelog="$(git log --oneline "$lasttag..HEAD")"
34 34
     local curbranch=$(git rev-parse --abbrev-ref HEAD)
35 35
     local dirt="$(git diff --shortstat 2>/dev/null)"
36 36
 
37
-    local newver=$(__make_ver $level ${lasttag#v})
37
+    local newver=$(__make_ver "$level" "${lasttag#v}")
38 38
     local newtag=v$newver
39 39
     local higher=$(echo -e "$oldtag\n$newtag" | sort -V | tail -n1)
40 40
 
41
+    test "$lastfile" = config.mk \
42
+     || die "last change must be version bump in config.mk"
43
+
44
+    test -n "$lasttag" \
45
+     || die "cannot find last tag"
46
+
41 47
     test "$newtag" = "$higher" \
42 48
      || die "generated tag looks older: $oldtag<$newtag"
43 49
 
44 50
     grep -qw "$newver" config.mk \
45 51
      || die "new version not in config.mk: $newver"
46 52
 
47
-    test -n "$lasttag" \
48
-     || die "cannot find last tag"
49
-
50 53
     grep '^....... WIP ' <<<"$changelog" \
51 54
      && die "WIP commit since $lasttag"
52 55
 
@@ -59,8 +62,8 @@ __release() {
59 62
     # FIXME: Have user prepare proper message with changelog
60 63
 
61 64
     set -e
62
-    git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" $newtag
63
-    git branch -f $RELDST $newtag
65
+    git tag -m "$MKIT_PROJNAME $newtag - $CODENAME" "$newtag"
66
+    git branch -f "$RELDST" "$newtag"
64 67
 }
65 68
 
66 69
 release_x() {

+ 1
- 1
utils/mkit/make View File

@@ -8,7 +8,7 @@ die() {
8 8
 
9 9
 export MKIT_DIR=${MKIT_DIR:-mkit}
10 10
 
11
-. $MKIT_DIR/include/mkit.sh || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"
11
+. "$MKIT_DIR/include/mkit.sh" || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"
12 12
 
13 13
 mkit_init
14 14