Browse Source

Update MKit to v0.0.20

Alois Mahdal 7 years ago
parent
commit
386085cb35

+ 43
- 34
utils/mkit/include/build.sh View File

6
 
6
 
7
 _build1() {
7
 _build1() {
8
     #
8
     #
9
-    # Process one skeleton
9
+    # Process one skeleton $1 of type $3 (or guessed) to path $2
10
     #
10
     #
11
-    local srcpath="$1"
12
-    local dstpath="$2"
13
-    local ftype="$3"
11
+    local srcpath=$1    # skeleton path
12
+    local dstpath=$2    # destination meaty animal path
13
+    local ftype=$3      # file/builder type
14
     test -n "$dstpath"  || dstpath=${srcpath%.skel}
14
     test -n "$dstpath"  || dstpath=${srcpath%.skel}
15
     test -n "$ftype"    || ftype=$(_guess_ftype "$dstpath")
15
     test -n "$ftype"    || ftype=$(_guess_ftype "$dstpath")
16
     debug_var srcpath dstpath ftype
16
     debug_var srcpath dstpath ftype
21
 
21
 
22
 _build1_ftype() {
22
 _build1_ftype() {
23
     #
23
     #
24
-    # Build a file of type $1
24
+    # Build a file of type $1; fom stdin to stdout
25
     #
25
     #
26
-    local ftype="$1"
26
+    local ftype=$1      # file/builder type
27
     case $ftype in
27
     case $ftype in
28
         MKIT_COMMON)    _expand_tokens "tokens" ;;
28
         MKIT_COMMON)    _expand_tokens "tokens" ;;
29
         markdown)       _expand_includes | _expand_tokens "tokens" ;;
29
         markdown)       _expand_includes | _expand_tokens "tokens" ;;
30
         rpmstuff)       _expand_tokens "tokens" "rpmstuff:tokens" ;;
30
         rpmstuff)       _expand_tokens "tokens" "rpmstuff:tokens" ;;
31
+        debstuff)       _expand_tokens "tokens" "debstuff:tokens" ;;
31
         *)              die "unknown file type: $ftype" ;;
32
         *)              die "unknown file type: $ftype" ;;
32
     esac
33
     esac
33
 }
34
 }
59
 
60
 
60
 _expand_tokens() {
61
 _expand_tokens() {
61
     #
62
     #
62
-    # Expand tokens from sections $@
63
+    # Read stdin, expanding tokens from sections $@
63
     #
64
     #
64
-    local script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
65
-    local section varname varvalue
65
+    local script        # sed script cache
66
+    local section       # each section to expand tokens from
67
+    local varname       # each token name
68
+    local varvalue      # each token value
69
+    script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
66
     {
70
     {
67
-        for section in "$@";
68
-        do
71
+        for section in "$@"; do
69
             debug_var section
72
             debug_var section
70
             ini lskeys "$section" \
73
             ini lskeys "$section" \
71
-              | while read varname;
72
-                do
74
+              | while read -r varname; do
73
                     varvalue="$(ini 1value "$section:$varname" | _qfs )"
75
                     varvalue="$(ini 1value "$section:$varname" | _qfs )"
74
                     echo "s|$varname|$varvalue|g;"
76
                     echo "s|$varname|$varvalue|g;"
75
                     debug_var varname varvalue
77
                     debug_var varname varvalue
93
     #
95
     #
94
     # Guess file type from destination path $1
96
     # Guess file type from destination path $1
95
     #
97
     #
96
-    local dstpath="$1"
98
+    local dstpath=$1    # destination path
97
     case $dstpath in
99
     case $dstpath in
98
         *.md) echo markdown    ;;
100
         *.md) echo markdown    ;;
99
         *)    echo MKIT_COMMON ;;
101
         *)    echo MKIT_COMMON ;;
114
     #
116
     #
115
     # Add meat to all skeletons
117
     # Add meat to all skeletons
116
     #
118
     #
117
-    local srcpath
119
+    local srcpath   # each source path
118
     find -type f -name '*.skel' \
120
     find -type f -name '*.skel' \
119
-     | while read srcpath;
120
-       do
121
+     | while read -r srcpath; do
121
            _build1 "$srcpath"
122
            _build1 "$srcpath"
122
        done
123
        done
123
 }
124
 }
124
 
125
 
125
 build_manpages() {
126
 build_manpages() {
126
-    local manfile mdfile
127
-    if command -v ronn >/dev/null;
128
-    then
127
+    #
128
+    # Build manpages using ronn
129
+    #
130
+    local manfile   # each manual file listed in '[files:man]'
131
+    local mdfile    # each source markdown file
132
+    if command -v ronn >/dev/null; then
129
         ini lskeys "files:man" \
133
         ini lskeys "files:man" \
130
-          | while read manfile;
131
-            do
134
+          | while read -r manfile; do
132
                 mdfile="$manfile.md"
135
                 mdfile="$manfile.md"
133
                 ronn -r "$mdfile"
136
                 ronn -r "$mdfile"
134
                 mkdir -p "$MKIT_LOCAL"
137
                 mkdir -p "$MKIT_LOCAL"
157
     #
160
     #
158
     # Build Debian stuff (eamed tarball, debian dir)
161
     # Build Debian stuff (eamed tarball, debian dir)
159
     #
162
     #
160
-    local version="$(semver)"
163
+    local version       # package version
164
+    local debian_skel   # 'debian' folder skeleton
165
+    local dfsrc         # each source file from ^^
166
+    local dftgt         # each built packaging file
167
+    version=$(semver)
161
 
168
 
162
     # tarball - we should already have by means of 'dist'
169
     # tarball - we should already have by means of 'dist'
163
     #
170
     #
168
 
175
 
169
     # read content of each mandatory file from debian_skel
176
     # read content of each mandatory file from debian_skel
170
     #
177
     #
171
-    local debian_skel=$(ini 1value dist:debstuff)
178
+    debian_skel=$(ini 1value dist:debstuff)
172
     test -n "$debian_skel" || die "dist:debstuff not specified"
179
     test -n "$debian_skel" || die "dist:debstuff not specified"
173
     test -d "$debian_skel" || die "debian directory template found: $debian_skel"
180
     test -d "$debian_skel" || die "debian directory template found: $debian_skel"
174
     mkdir -p debian/source
181
     mkdir -p debian/source
175
-    local dfsrc dftgt
176
     find "$debian_skel" -type f \
182
     find "$debian_skel" -type f \
177
-      | while read dfsrc;
178
-        do
183
+      | while read -r dfsrc; do
179
             dftgt="debian/${dfsrc#$debian_skel}"
184
             dftgt="debian/${dfsrc#$debian_skel}"
180
             mkdir -p "$(dirname "$dftgt")"
185
             mkdir -p "$(dirname "$dftgt")"
181
-            _build1 "$dfsrc" "$dftgt"
186
+            _build1 "$dfsrc" "$dftgt" debstuff
182
         done
187
         done
183
     echo debian >> "$MKIT_LOCAL/built.lst"
188
     echo debian >> "$MKIT_LOCAL/built.lst"
184
 }
189
 }
190
     #FIXME: lacking Makefile skills, we do this step twice fot
195
     #FIXME: lacking Makefile skills, we do this step twice fot
191
     #       rpmstuff, hence -f hack for gzip
196
     #       rpmstuff, hence -f hack for gzip
192
     #
197
     #
193
-    local version=$(semver)
194
-    local git_lasthash=$(git_lasthash)
195
-    local dirname=$MKIT_PROJ_PKGNAME-$version
198
+    local version           # tarball version
199
+    local git_lasthash      # last git commit hash
200
+    local dirname           # directory and tarball name
201
+    version=$(semver)
202
+    dirname=$MKIT_PROJ_PKGNAME-$version
203
+    git_lasthash=$(git_lasthash)
196
     mkdir -p "$dirname"
204
     mkdir -p "$dirname"
197
     ini values "dist:tarball" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
205
     ini values "dist:tarball" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
198
     update_version "$version" "$dirname/mkit.ini"
206
     update_version "$version" "$dirname/mkit.ini"
209
     #
217
     #
210
     # Build specfile
218
     # Build specfile
211
     #
219
     #
212
-    local specname="$MKIT_PROJ_PKGNAME.spec"
213
-    local specsrc="$(ini 1value "dist:rpmstuff")"
220
+    local specname=$MKIT_PROJ_PKGNAME.spec      # .spec filename
221
+    local specsrc                               # source of specfile
222
+    specsrc="$(ini 1value "dist:rpmstuff")"
214
     test -n "$specsrc" || die "dist:rpmstuff not specified"
223
     test -n "$specsrc" || die "dist:rpmstuff not specified"
215
     test -f "$specsrc" || die "specfile template not found: $specsrc"
224
     test -f "$specsrc" || die "specfile template not found: $specsrc"
216
-    _build1 "$specsrc" "$specname"
225
+    _build1 "$specsrc" "$specname" rpmstuff
217
 }
226
 }

+ 25
- 23
utils/mkit/include/deploy.sh View File

23
     # Directories are copied recursively, and mode is
23
     # Directories are copied recursively, and mode is
24
     # applied only to files.
24
     # applied only to files.
25
     #
25
     #
26
-    local src="$1"
27
-    local dst="$2"
28
-    local mode="${3:-$MKIT_DEFAULT_MODE}"
29
-    if test -d "$src";
30
-    then
26
+    local src=$1                            # source path
27
+    local dst=$2                            # destination path
28
+    local mode=${3:-$MKIT_DEFAULT_MODE}     # mode
29
+    local chmod_item                        # each file to chmod in directory
30
+    if test -d "$src"; then
31
         _maybe mkdir -vp "$(dirname "$dst")"
31
         _maybe mkdir -vp "$(dirname "$dst")"
32
         _maybe cp -Tvr "$src" "$dst"
32
         _maybe cp -Tvr "$src" "$dst"
33
         find "$dst" -type f \
33
         find "$dst" -type f \
34
-          | while read chmod_item;
35
-            do
34
+          | while read -r chmod_item; do
36
                 _maybe chmod "$mode" "$chmod_item"
35
                 _maybe chmod "$mode" "$chmod_item"
37
             done
36
             done
38
     else
37
     else
44
     #
43
     #
45
     # Find out target path for src file $2 of group $1
44
     # Find out target path for src file $2 of group $1
46
     #
45
     #
47
-    local grp=$1
48
-    local src=$2
49
-    local dst=$3
46
+    local grp=$1        # deploy group
47
+    local src=$2        # each source
48
+    local dst=$3        # alternative destination name
50
     test -n "$dst" || dst=${src##*/}
49
     test -n "$dst" || dst=${src##*/}
51
     echo "$(_get_root "$grp")/$dst"
50
     echo "$(_get_root "$grp")/$dst"
52
 }
51
 }
55
     #
54
     #
56
     # Find out target root for group $1
55
     # Find out target root for group $1
57
     #
56
     #
58
-    local grp="$1"
59
-    local root=$(ini 1value "roots:$grp")
60
-    local destdir=$(ini 1value ENV:DESTDIR)
57
+    local grp=$1        # deploy group
58
+    local root          # root for this group
59
+    local destdir       # value of DESTDIR
60
+    root=$(ini 1value "roots:$grp")
61
+    destdir=$(ini 1value ENV:DESTDIR)
61
     destdir=${destdir%/}
62
     destdir=${destdir%/}
62
     case $destdir:$root in
63
     case $destdir:$root in
63
         *:)     die "missing in config.ini: roots:$grp" ;;
64
         *:)     die "missing in config.ini: roots:$grp" ;;
84
     #
85
     #
85
     # Install product
86
     # Install product
86
     #
87
     #
87
-    local dst group mode src
88
+    local group     # each deploy group
89
+    local mode      # mode (group-specific)
90
+    local src       # each source path
91
+    local dst       # each (final absolute) destination path
88
     ini lskeys "files" \
92
     ini lskeys "files" \
89
       | sort \
93
       | sort \
90
       | uniq \
94
       | uniq \
91
-      | while read group;
92
-        do
95
+      | while read -r group; do
93
             mode=$(ini 1value "modes:$group")
96
             mode=$(ini 1value "modes:$group")
94
             ini values "files:$group" \
97
             ini values "files:$group" \
95
-              | while read src dst;
96
-                do
98
+              | while read -r src dst; do
97
                     dst=$(_get_dst "$group" "$src" "$dst")
99
                     dst=$(_get_dst "$group" "$src" "$dst")
98
                     _deploy_item "$src" "$dst" "$mode"
100
                     _deploy_item "$src" "$dst" "$mode"
99
                 done
101
                 done
106
     #
108
     #
107
     # Uninstall product
109
     # Uninstall product
108
     #
110
     #
109
-    local dst group src
111
+    local group     # each deploy group
112
+    local src       # each source path
113
+    local dst       # each (final absolute) destination path
110
     ini lskeys "files" \
114
     ini lskeys "files" \
111
       | sort \
115
       | sort \
112
       | uniq \
116
       | uniq \
113
-      | while read group;
114
-        do
117
+      | while read -r group; do
115
             ini values "files:$group" \
118
             ini values "files:$group" \
116
-              | while read src dst;
117
-                do
119
+              | while read -r src dst; do
118
                     dst=$(_get_dst "$group" "$src" "$dst")
120
                     dst=$(_get_dst "$group" "$src" "$dst")
119
                     _maybe rm -vrf "$dst"
121
                     _maybe rm -vrf "$dst"
120
                 done
122
                 done

+ 18
- 13
utils/mkit/include/facts.sh View File

6
     #
6
     #
7
     # Get git bool (ie. exit status counts) $1
7
     # Get git bool (ie. exit status counts) $1
8
     #
8
     #
9
-    local bool_name="$1"
9
+    local bool_name=$1      # name of boolean to get
10
     git_present || warn "can't give bool outside git repo: $bool_name"
10
     git_present || warn "can't give bool outside git repo: $bool_name"
11
     case "$bool_name" in
11
     case "$bool_name" in
12
         dirty_files)
12
         dirty_files)
29
     #
29
     #
30
     # Get git fact $1
30
     # Get git fact $1
31
     #
31
     #
32
-    local fact_name="$1"
32
+    local fact_name=$1      # name of fact to get
33
     git_present || warn "can't give fact outside git repo: $fact_name"
33
     git_present || warn "can't give fact outside git repo: $fact_name"
34
     case "$fact_name" in
34
     case "$fact_name" in
35
         latest_tag)
35
         latest_tag)
88
     # work if you got outside the git repo in other way than dist
88
     # work if you got outside the git repo in other way than dist
89
     # target, but that's actually expected.)
89
     # target, but that's actually expected.)
90
     #
90
     #
91
-    if git_present;
92
-    then    # we are in git repo
93
-        local last_hash=$(git rev-parse HEAD)
91
+    local last_hash     # last commit hash
92
+    if git_present; then    # we are in git repo
93
+        last_hash=$(git rev-parse HEAD)
94
         echo -n "$last_hash"
94
         echo -n "$last_hash"
95
         git_bool dirty && echo -n ".dirty"
95
         git_bool dirty && echo -n ".dirty"
96
     else    # we are outside (eg. distributor's build dir')
96
     else    # we are outside (eg. distributor's build dir')
146
     # FIXME:  Using project:prerl for release IDs may not be compatible with
146
     # FIXME:  Using project:prerl for release IDs may not be compatible with
147
     #         release strategy implemented in release.sh
147
     #         release strategy implemented in release.sh
148
     #
148
     #
149
-    local version=$(ini 1value project:version)
150
-    local prerl=$(ini 1value project:prerl)
151
-    grep ":" <<<"$prerl" && warn "colon in project:prerl may corrupt version data: $prerl"
149
+    local version       # version string (final result)
150
+    local prerl         # pre-release keyword (from mkit.ini, eg. 'alpha')
151
+    local latest_tag    # latest git tag
152
+    local commit        # commit indicator (CURRENT_BRANCH.gHASH)
153
+    local dirty         # 0 if dirty, 1 if clean
154
+    local suffix        # version suffix
155
+    version=$(ini 1value project:version)
156
+    prerl=$(ini 1value project:prerl)
157
+    grep ":" <<<"$prerl" \
158
+     && warn "colon in project:prerl may corrupt version data: $prerl"
152
     if git_present;
159
     if git_present;
153
     then    # we are in git repo... so we can get smart
160
     then    # we are in git repo... so we can get smart
154
-        local latest_tag=$(git_fact latest_tag)
161
+        latest_tag=$(git_fact latest_tag)
155
         if ! git describe --tags --exact-match HEAD >&/dev/null;
162
         if ! git describe --tags --exact-match HEAD >&/dev/null;
156
         then    # we are at a later commit than the last tag
163
         then    # we are at a later commit than the last tag
157
-            local commit="$(git_fact current_branch).g$(git_fact latest_sha)"
164
+            commit="$(git_fact current_branch).g$(git_fact latest_sha)"
158
         fi
165
         fi
159
-        local dirty=""
160
-        local suffix=""
161
         git_bool dirty; dirty=$?
166
         git_bool dirty; dirty=$?
162
         test -n "$latest_tag" && version=${latest_tag:1}
167
         test -n "$latest_tag" && version=${latest_tag:1}
163
         case "$dirty:$commit" in
168
         case "$dirty:$commit" in
165
             0:)  suffix="+dirty"         ;;
170
             0:)  suffix="+dirty"         ;;
166
             1:*) suffix="+$commit"       ;;
171
             1:*) suffix="+$commit"       ;;
167
             0:*) suffix="+$commit.dirty" ;;
172
             0:*) suffix="+$commit.dirty" ;;
168
-            *)   suffix=MKIT_BUG;
173
+            *)   suffix=MKIT_BUG
169
                  warn "MKIT_BUG: bad dirt/commit detection" ;;
174
                  warn "MKIT_BUG: bad dirt/commit detection" ;;
170
         esac
175
         esac
171
         test -n "$prerl" && suffix="-$prerl$suffix"
176
         test -n "$prerl" && suffix="-$prerl$suffix"

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

4
     #
4
     #
5
     # A no-op for text stream
5
     # A no-op for text stream
6
     #
6
     #
7
-    while read line;
8
-    do
7
+    local line      # each line
8
+    while read -r line; do
9
         printf -- "%s\n" "$line"
9
         printf -- "%s\n" "$line"
10
     done
10
     done
11
 }
11
 }
14
     #
14
     #
15
     # Expand reference value (prefix only)
15
     # Expand reference value (prefix only)
16
     #
16
     #
17
-    local line suffix ref value
18
-    while read line;                        # [foo:bar]/path
19
-    do
17
+    local line      # each input line
18
+    local suffix    # tail of the line
19
+    local ref       # reference
20
+    local value     # value if reference
21
+    while read -r line; do                  # [foo:bar]/path
20
         suffix="${line#\[*\]}"              # /path
22
         suffix="${line#\[*\]}"              # /path
21
         ref="${line%$suffix}"               # [foo:bar]
23
         ref="${line%$suffix}"               # [foo:bar]
22
         ref="${ref%\]}"                     # [foo:bar
24
         ref="${ref%\]}"                     # [foo:bar
30
     #
32
     #
31
     # Read key from a section
33
     # Read key from a section
32
     #
34
     #
33
-    local wnt=$1
35
+    local wnt=$1    # wanted key
34
     grep '.' \
36
     grep '.' \
35
       | grep -v '\s*#' \
37
       | grep -v '\s*#' \
36
       | sed -e 's/ *= */=/; s/ +$//; s/^//;' \
38
       | sed -e 's/ *= */=/; s/ +$//; s/^//;' \
48
     #     [files:share]
50
     #     [files:share]
49
     #         my/lib.sh   = proj/my/lib.sh
51
     #         my/lib.sh   = proj/my/lib.sh
50
     #
52
     #
51
-    local wnt="$1"
52
-    local wntkey="${wnt##*:}"
53
-    local wntsec="${wnt%:$wntkey}"
54
-    if test "$wntsec" = 'ENV';
55
-    then
56
-        local override="${!wntkey}"
57
-        if test -n "$override";
58
-        then
59
-            echo "$override"
60
-            return
61
-        fi
53
+    local wnt=$1                    # wanted path
54
+    local wntkey=${wnt##*:}         # ^^ key part
55
+    local wntsec=${wnt%:$wntkey}    # ^^ section part
56
+    local override                  # ENV override (only ENV section)
57
+    if test "$wntsec" = 'ENV'; then
58
+        override=${!wntkey}
59
+        test -n "$override" \
60
+         && echo "$override" \
61
+         && return
62
     fi
62
     fi
63
     _ini_grepsec "$wntsec" | _ini_grepkey "$wntkey"
63
     _ini_grepsec "$wntsec" | _ini_grepkey "$wntkey"
64
 }
64
 }
67
     #
67
     #
68
     # Read one INI section
68
     # Read one INI section
69
     #
69
     #
70
-    local wnt="$1"
71
-    local ok=false
70
+    local wnt=$1        # wanted section name
71
+    local ok=false      # are we in the section?
72
+    local line          # each input line
72
     grep '.' \
73
     grep '.' \
73
       | grep -v '\s*#' \
74
       | grep -v '\s*#' \
74
-      | while read line;
75
-        do
75
+      | while read -r line; do
76
             case "$line" in
76
             case "$line" in
77
                 \[$wnt\]) ok=true;  continue ;;
77
                 \[$wnt\]) ok=true;  continue ;;
78
                 \[*\])    ok=false; continue ;;
78
                 \[*\])    ok=false; continue ;;
87
     #
87
     #
88
     # List keys from a section
88
     # List keys from a section
89
     #
89
     #
90
-    local sct="$1"
90
+    local sct=$1    # section of interest
91
     _ini_grepsec "$sct" | cut -d= -f1 | sort | uniq
91
     _ini_grepsec "$sct" | cut -d= -f1 | sort | uniq
92
 }
92
 }
93
 
93
 
95
     #
95
     #
96
     # Decide whether or not to expand
96
     # Decide whether or not to expand
97
     #
97
     #
98
-    if test "$MKIT_INI_EXPAND" -gt 0;
99
-    then
98
+    if test "$MKIT_INI_EXPAND" -gt 0; then
100
         MKIT_INI_EXPAND=$(( --MKIT_INI_EXPAND )) _ini_expand
99
         MKIT_INI_EXPAND=$(( --MKIT_INI_EXPAND )) _ini_expand
101
     else
100
     else
102
         _ini_cat
101
         _ini_cat
107
     #
106
     #
108
     # do ini operation
107
     # do ini operation
109
     #
108
     #
110
-    local op=$1
111
-    local arg=$2
112
-    local fn
113
-    local limit=_ini_cat
109
+    local op=$1             # operator
110
+    local arg=$2            # argument
111
+    local fn                # internal function implementing $op
112
+    local limit=_ini_cat    # limiting internal function
114
     case $op in
113
     case $op in
115
         lskeys) fn=_ini_lskeys   ;;
114
         lskeys) fn=_ini_lskeys   ;;
116
         sec)    fn=_ini_grepsec  ;;
115
         sec)    fn=_ini_grepsec  ;;
125
     #
124
     #
126
     # Change project.version in mkit.ini at path $2 to version $1
125
     # Change project.version in mkit.ini at path $2 to version $1
127
     #
126
     #
128
-    local version="$1"
129
-    local inifile="$2"
130
-    local tmp=$(mktemp -t mkit.update_version.XXXXXXXX)
127
+    local version=$1    # new version
128
+    local inifile=$2    # mkit.ini path
129
+    local tmp           # mkit.ini cache
130
+    tmp=$(mktemp -t mkit.update_version.XXXXXXXX)
131
     <"$inifile" perl -e '
131
     <"$inifile" perl -e '
132
         my $hit = 0;
132
         my $hit = 0;
133
         my $done = 0;
133
         my $done = 0;

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

38
     # Print debug message
38
     # Print debug message
39
     #
39
     #
40
     $MKIT_DEBUG || return 0
40
     $MKIT_DEBUG || return 0
41
-    local __mkit_debug_var_name__
42
-    for __mkit_debug_var_name__ in "$@";
43
-    do
41
+    local __mkit_debug_var_name__       # variable name to debug
42
+    for __mkit_debug_var_name__ in "$@"; do
44
         {
43
         {
45
             echo -n "MKIT_DEBUG: ${FUNCNAME[1]}():"
44
             echo -n "MKIT_DEBUG: ${FUNCNAME[1]}():"
46
             echo -n " $__mkit_debug_var_name__"
45
             echo -n " $__mkit_debug_var_name__"
65
     # If our x is 0, check first two fragments, otherwise check just
64
     # If our x is 0, check first two fragments, otherwise check just
66
     # the x.  Fragments must equal.
65
     # the x.  Fragments must equal.
67
     #
66
     #
68
-    local their_ver our_x our_y their_x their_y
69
-    their_ver="$1"
67
+    local their_ver=$1      # their version
68
+    local our_x             # our X
69
+    local our_y             # our Y
70
+    local their_x           # their X
71
+    local their_y           # their Y
70
     their_x=${their_ver%%.*}
72
     their_x=${their_ver%%.*}
71
     their_y=${their_ver##$their_x.}
73
     their_y=${their_ver##$their_x.}
72
     their_y=${their_y%%.*}
74
     their_y=${their_y%%.*}
89
     # Look for "#mkit version=0.0.0" or similar in first or last
91
     # Look for "#mkit version=0.0.0" or similar in first or last
90
     # 3 lines of the file; then check if the version is supported.
92
     # 3 lines of the file; then check if the version is supported.
91
     #
93
     #
92
-    local ver_line
93
-    local their_ver
94
+    local ver_line      # line declaring version
95
+    local their_ver     # the declared version
94
     ver_line=$(
96
     ver_line=$(
95
         {
97
         {
96
             head -3 "$MKIT_INI"
98
             head -3 "$MKIT_INI"
122
     #
124
     #
123
     # Call correct function based on $1
125
     # Call correct function based on $1
124
     #
126
     #
125
-    if _valid_targets | grep -qwx "^$1";
126
-    then
127
+    if _valid_targets | grep -qwx "^$1"; then
127
         "$1"
128
         "$1"
128
     else
129
     else
129
         {
130
         {

+ 51
- 21
utils/mkit/include/release.sh View File

7
     #
7
     #
8
     # Bump version on stdin by level $1 (x, y or z)
8
     # Bump version on stdin by level $1 (x, y or z)
9
     #
9
     #
10
-    local rlevel=$1
11
-    local old
10
+    local rlevel=$1     # release level
11
+    local old           # old version
12
+    local oldx          # ... X
13
+    local oldz          # ... Z
14
+    local oldy          # ... Y
15
+    local tmpy          # Y parsing cache
16
+    local new           # bumped version
12
     read -r old
17
     read -r old
13
-    local oldx=${old%.*.*}
14
-    local oldz=${old#*.*.}
15
-    local tmpy=${old%.*}
16
-    local oldy=${tmpy#*.}
17
-    local new=""
18
+    oldx=${old%.*.*}
19
+    oldz=${old#*.*.}
20
+    tmpy=${old%.*}
21
+    oldy=${tmpy#*.}
18
     case $rlevel in
22
     case $rlevel in
19
         x) new="$((oldx+MKIT_BUMPSIZE)).0.0"            ;;
23
         x) new="$((oldx+MKIT_BUMPSIZE)).0.0"            ;;
20
         y) new="$oldx.$((oldy+MKIT_BUMPSIZE)).0"        ;;
24
         y) new="$oldx.$((oldy+MKIT_BUMPSIZE)).0"        ;;
28
     #
32
     #
29
     # Die if blocking condition $1 is detected
33
     # Die if blocking condition $1 is detected
30
     #
34
     #
31
-    local condition="$1"
32
-    local x
35
+    local condition=$1      # condition name
36
+    local oracle            # expected value
33
     case "$condition" in
37
     case "$condition" in
34
         git_present)
38
         git_present)
35
             git rev-parse HEAD >&/dev/null\
39
             git rev-parse HEAD >&/dev/null\
36
              || die "cannot do this outside git repo"
40
              || die "cannot do this outside git repo"
37
             ;;
41
             ;;
38
         at_relsrc)
42
         at_relsrc)
39
-            local relsrc=$(ini 1value project:relsrc)
43
+            oracle=$(ini 1value project:relsrc)
40
             git_fact current_branch \
44
             git_fact current_branch \
41
-              | grep -qFx "$relsrc" \
42
-             || die "you are not on release source branch: $relsrc"
45
+              | grep -qFx "$oracle" \
46
+             || die "you are not on release source branch: $oracle"
43
             ;;
47
             ;;
44
         not_dirty)
48
         not_dirty)
45
             git diff --shortstat 2>/dev/null \
49
             git diff --shortstat 2>/dev/null \
46
               | grep -q . \
50
               | grep -q . \
47
-             && die "tree is dirty: $dirt"
51
+             && die "tree is dirty!"
48
             ;;
52
             ;;
49
         tags_ok)
53
         tags_ok)
50
             git_fact latest_tag \
54
             git_fact latest_tag \
62
              && die "WIP commit since $(git_fact latest_tag)"
66
              && die "WIP commit since $(git_fact latest_tag)"
63
             ;;
67
             ;;
64
         ini_version)
68
         ini_version)
65
-            local oracle=$(git_fact latest_version | _bump_version "$rlevel")
69
+            oracle=$(git_fact latest_version | _bump_version "$rlevel")
66
             ini 1value project:version  \
70
             ini 1value project:version  \
67
               | grep -qFx "$oracle" \
71
               | grep -qFx "$oracle" \
68
              || die "new version not in mkit.ini: $oracle"
72
              || die "new version not in mkit.ini: $oracle"
83
     # FIXME: Using project:prerl as build.sh:semver() does may not be
87
     # FIXME: Using project:prerl as build.sh:semver() does may not be
84
     #        compatible with this release strategy
88
     #        compatible with this release strategy
85
     #
89
     #
86
-    local rlevel=$1
87
-    local newtag
88
-    local reldst
90
+    local rlevel=$1     # release level (x, y or z)
91
+    local newtag        # new tag
92
+    local reldst        # release destination branch (if any)
89
 
93
 
90
     _relck git_present
94
     _relck git_present
91
     _relck at_relsrc
95
     _relck at_relsrc
103
 
107
 
104
     reldst=$(ini 1value project:reldst)
108
     reldst=$(ini 1value project:reldst)
105
     debug_var reldst
109
     debug_var reldst
106
-    if test -n "$reldst";
107
-    then
110
+    if test -n "$reldst"; then
108
         git branch -f "$reldst" "$newtag"
111
         git branch -f "$reldst" "$newtag"
109
     fi
112
     fi
110
 }
113
 }
127
 }
130
 }
128
 
131
 
129
 _vbump() {
132
 _vbump() {
130
-    local rlevel="$1"
131
-    local nextver   # after the bump
133
+    #
134
+    # Do version bump at level $1
135
+    #
136
+    # Perform checks, compute new version, update mkit.ini and initiate
137
+    # 'Bump version' commit with changelog template.
138
+    #
139
+    local rlevel=$1     # bump level (x, y or z)
140
+    local nextver       # version after the bump
132
     _relck git_present
141
     _relck git_present
133
     _relck at_relsrc
142
     _relck at_relsrc
134
     _relck not_dirty
143
     _relck not_dirty
143
 }
152
 }
144
 
153
 
145
 _vbump_gitmsg() {
154
 _vbump_gitmsg() {
155
+    #
156
+    # Compose git message template for 'Bump version' commit
157
+    #
146
     echo "Bump version"
158
     echo "Bump version"
147
     echo ""
159
     echo ""
148
     echo "Overview of changes:"
160
     echo "Overview of changes:"
156
 }
168
 }
157
 
169
 
158
 release_x() {
170
 release_x() {
171
+    #
172
+    # Perform release on X level
173
+    #
159
     _release x
174
     _release x
160
 }
175
 }
161
 
176
 
162
 release_y() {
177
 release_y() {
178
+    #
179
+    # Perform release on Y level
180
+    #
163
     _release y
181
     _release y
164
 }
182
 }
165
 
183
 
166
 release_z() {
184
 release_z() {
185
+    #
186
+    # Perform release on Z level
187
+    #
167
     _release z
188
     _release z
168
 }
189
 }
169
 
190
 
170
 vbump_x() {
191
 vbump_x() {
192
+    #
193
+    # Perform version bump on X level
194
+    #
171
     _vbump x
195
     _vbump x
172
 }
196
 }
173
 
197
 
174
 vbump_y() {
198
 vbump_y() {
199
+    #
200
+    # Perform version bump on Y level
201
+    #
175
     _vbump y
202
     _vbump y
176
 }
203
 }
177
 
204
 
178
 vbump_z() {
205
 vbump_z() {
206
+    #
207
+    # Perform version bump on Z level
208
+    #
179
     _vbump z
209
     _vbump z
180
 }
210
 }

+ 6
- 2
utils/mkit/make View File

1
 #!/bin/bash
1
 #!/bin/bash
2
+#shellcheck disable=SC2034,SC1090
2
 # mkit - simple install helper
3
 # mkit - simple install helper
3
 # See LICENSE file for copyright and license details.
4
 # See LICENSE file for copyright and license details.
4
 
5
 
5
 die() {
6
 die() {
6
-    echo "$@" && exit 9
7
+    #
8
+    # Poor man's die() (mkit.sh has better)
9
+    #
10
+    echo "$@" >&2 && exit 9
7
 }
11
 }
8
 
12
 
9
 
13
 
66
 #
70
 #
67
 # This MKit version
71
 # This MKit version
68
 #
72
 #
69
-MKIT_VERSION=0.0.18
73
+MKIT_VERSION=0.0.20
70
 
74
 
71
 
75
 
72
 . "$MKIT_DIR/include/mkit.sh" || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"
76
 . "$MKIT_DIR/include/mkit.sh" || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"

+ 6
- 0
utils/mkit/mkit.mk View File

26
 install: all
26
 install: all
27
 	@$(MKIT_DIR)/make install
27
 	@$(MKIT_DIR)/make install
28
 
28
 
29
+release:
30
+	@$(MKIT_DIR)/make release_z
31
+
29
 release_x:
32
 release_x:
30
 	@$(MKIT_DIR)/make release_x
33
 	@$(MKIT_DIR)/make release_x
31
 
34
 
38
 uninstall:
41
 uninstall:
39
 	@$(MKIT_DIR)/make uninstall
42
 	@$(MKIT_DIR)/make uninstall
40
 
43
 
44
+vbump:
45
+	@$(MKIT_DIR)/make vbump_z
46
+
41
 vbump_x:
47
 vbump_x:
42
 	@$(MKIT_DIR)/make vbump_x
48
 	@$(MKIT_DIR)/make vbump_x
43
 
49