Browse Source

Update MKit to v0.0.28

Alois Mahdal 7 years ago
parent
commit
9d6918791e

+ 58
- 71
utils/mkit/include/build.sh View File

6
 mkit_import facts
6
 mkit_import facts
7
 
7
 
8
 
8
 
9
-_build1() {
9
+__build1() {
10
     #
10
     #
11
     # Process one skeleton $1 of type $3 (or guessed) to path $2
11
     # Process one skeleton $1 of type $3 (or guessed) to path $2
12
     #
12
     #
14
     local dstpath=$2    # destination meaty animal path
14
     local dstpath=$2    # destination meaty animal path
15
     local ftype=$3      # file/builder type
15
     local ftype=$3      # file/builder type
16
     test -n "$dstpath"  || dstpath=${srcpath%.skel}
16
     test -n "$dstpath"  || dstpath=${srcpath%.skel}
17
-    test -n "$ftype"    || ftype=$(_guess_ftype "$dstpath")
17
+    test -n "$ftype"    || ftype=$(__guess_ftype "$dstpath")
18
     debug_var srcpath dstpath ftype
18
     debug_var srcpath dstpath ftype
19
-    <"$srcpath" _build1_ftype "$ftype" >"$dstpath"
19
+    <"$srcpath" __build1_ftype "$ftype" >"$dstpath"
20
     rec_built "$dstpath"
20
     rec_built "$dstpath"
21
 }
21
 }
22
 
22
 
23
-_build1_ftype() {
23
+__build1_ftype() {
24
     #
24
     #
25
     # Build a file of type $1; fom stdin to stdout
25
     # Build a file of type $1; fom stdin to stdout
26
     #
26
     #
27
     local ftype=$1      # file/builder type
27
     local ftype=$1      # file/builder type
28
     case $ftype in
28
     case $ftype in
29
-        MKIT_COMMON)    _expand_tokens "tokens" ;;
30
-        markdown)       _expand_includes | _expand_tokens "tokens" ;;
31
-        rpmstuff)       _expand_tokens "tokens" "rpmstuff:tokens" ;;
32
-        debstuff)       _expand_tokens "tokens" "debstuff:tokens" ;;
29
+        MKIT_COMMON)    __expand_tokens "tokens" ;;
30
+        rpmstuff)       __expand_tokens "tokens" "rpmstuff:tokens" ;;
31
+        debstuff)       __expand_tokens "tokens" "debstuff:tokens" ;;
33
         *)              die "unknown file type: $ftype" ;;
32
         *)              die "unknown file type: $ftype" ;;
34
     esac
33
     esac
35
 }
34
 }
36
 
35
 
37
-_expand_includes() {
38
-    #
39
-    # Expand include directives
40
-    #
41
-    # Expand e.g. `<!-- include4: foo.sh -->` to include code of foo.sh
42
-    #
43
-    perl -we '
44
-        use strict;
45
-        my $text;
46
-        while (<>) {
47
-            chomp;
48
-            if (m/<!-- include4: (\S+) -->/) {
49
-                open my $fh, $1 or warn "cannot find: $1";
50
-                my $text = do { local($/); <$fh> };
51
-                close $fh;
52
-                $text =~ s/^(.)/    $1/gm;
53
-                chomp $text;
54
-                print "$text\n";
55
-            } else {
56
-                print "$_\n";
57
-            }
58
-        }
59
-    '
60
-}
61
-
62
-_expand_tokens() {
36
+__expand_tokens() {
63
     #
37
     #
64
     # Read stdin, expanding tokens from sections $@
38
     # Read stdin, expanding tokens from sections $@
65
     #
39
     #
73
             debug_var section
47
             debug_var section
74
             ini lskeys "$section" \
48
             ini lskeys "$section" \
75
               | while read -r varname; do
49
               | while read -r varname; do
76
-                    varvalue="$(ini 1value "$section:$varname" | _qfs )"
50
+                    varvalue="$(ini 1value "$section:$varname" | __qfs )"
77
                     echo "s|$varname|$varvalue|g;"
51
                     echo "s|$varname|$varvalue|g;"
78
                     debug_var varname varvalue
52
                     debug_var varname varvalue
79
                 done
53
                 done
80
         done
54
         done
81
-        echo "s|__MKIT_PROJ_NAME__|$(ini 1value project:name | _qfs)|g;"
82
-        echo "s|__MKIT_PROJ_CODENAME__|$(ini 1value project:codename | _qfs)|g;"
83
-        echo "s|__MKIT_PROJ_LICENSE__|$(ini 1value project:license | _qfs)|g;"
84
-        echo "s|__MKIT_PROJ_PKGNAME__|$(ini 1value project:pkgname | _qfs)|g;"
85
-        echo "s|__MKIT_PROJ_TAGLINE__|$(ini 1value project:tagline | _qfs)|g;"
86
-        echo "s|__MKIT_PROJ_MAINTAINER__|$(ini 1value project:maintainer | _qfs)|g;"
87
-        echo "s|__MKIT_PROJ_VCS_BROWSER__|$(ini 1value project:vcs_browser | _qfs)|g;"
88
-        echo "s|__MKIT_PROJ_GIT_LASTHASH__|$(git_lasthash | _qfs)|g;"
89
-        echo "s|__MKIT_PROJ_VERSION__|$(semver | _qfs)|g;"
55
+        echo "s|__MKIT_PROJ_NAME__|$(ini 1value project:name | __qfs)|g;"
56
+        echo "s|__MKIT_PROJ_CODENAME__|$(ini 1value project:codename | __qfs)|g;"
57
+        echo "s|__MKIT_PROJ_LICENSE__|$(ini 1value project:license | __qfs)|g;"
58
+        echo "s|__MKIT_PROJ_PKGNAME__|$(ini 1value project:pkgname | __qfs)|g;"
59
+        echo "s|__MKIT_PROJ_TAGLINE__|$(ini 1value project:tagline | __qfs)|g;"
60
+        echo "s|__MKIT_PROJ_MAINTAINER__|$(ini 1value project:maintainer | __qfs)|g;"
61
+        echo "s|__MKIT_PROJ_VCS_BROWSER__|$(ini 1value project:vcs_browser | __qfs)|g;"
62
+        echo "s|__MKIT_PROJ_GIT_LASTHASH__|$(git_lasthash | __qfs)|g;"
63
+        echo "s|__MKIT_PROJ_VERSION__|$(semver | __qfs)|g;"
90
         echo "s|__MKIT_SELF_VERSION__|$MKIT_VERSION|g;"
64
         echo "s|__MKIT_SELF_VERSION__|$MKIT_VERSION|g;"
91
     } >> "$script"
65
     } >> "$script"
92
-    sed -f "$script" || die "_expand_tokens failed"
66
+    sed -f "$script" || die "__expand_tokens failed"
93
     rm "$script"
67
     rm "$script"
94
 }
68
 }
95
 
69
 
96
-_guess_ftype() {
70
+__guess_ftype() {
97
     #
71
     #
98
     # Guess file type from destination path $1
72
     # Guess file type from destination path $1
99
     #
73
     #
100
     local dstpath=$1    # destination path
74
     local dstpath=$1    # destination path
101
     case $dstpath in
75
     case $dstpath in
102
-        *.md) echo markdown    ;;
103
         *)    echo MKIT_COMMON ;;
76
         *)    echo MKIT_COMMON ;;
104
     esac
77
     esac
105
 }
78
 }
106
 
79
 
107
-_qfs() {
80
+__qfs() {
108
     #
81
     #
109
     # Quote for our sed scipt's RHS
82
     # Quote for our sed scipt's RHS
110
     #
83
     #
114
     '
87
     '
115
 }
88
 }
116
 
89
 
90
+_mkit_data() {
91
+    #
92
+    # Build sampler showing all token values
93
+    #
94
+    local token
95
+    local section
96
+    local sections
97
+    sections=()
98
+    ini lskeys tokens | grep -q . && sections=(tokens)
99
+    sections+=( $(ini lssect | grep ':tokens$') )
100
+    {
101
+        echo "(builtin):"
102
+        echo "  x_MKIT_PROJ_NAME__ => '__MKIT_PROJ_NAME__'"
103
+        echo "  x_MKIT_PROJ_CODENAME__ => '__MKIT_PROJ_CODENAME__'"
104
+        echo "  x_MKIT_PROJ_LICENSE__ => '__MKIT_PROJ_LICENSE__'"
105
+        echo "  x_MKIT_PROJ_PKGNAME__ => '__MKIT_PROJ_PKGNAME__'"
106
+        echo "  x_MKIT_PROJ_TAGLINE__ => '__MKIT_PROJ_TAGLINE__'"
107
+        echo "  x_MKIT_PROJ_MAINTAINER__ => '__MKIT_PROJ_MAINTAINER__'"
108
+        echo "  x_MKIT_PROJ_VCS_BROWSER__ => '__MKIT_PROJ_VCS_BROWSER__'"
109
+        echo "  x_MKIT_PROJ_GIT_LASTHASH__ => '__MKIT_PROJ_GIT_LASTHASH__'"
110
+        echo "  x_MKIT_PROJ_VERSION__ => '__MKIT_PROJ_VERSION__'"
111
+        echo "  x_MKIT_SELF_VERSION__ => '__MKIT_SELF_VERSION__'"
112
+        for section in "${sections[@]}"; do
113
+            echo "$section:"
114
+            for token in $(ini lskeys "$section"); do
115
+                echo "  x${token:1} => '$token'"
116
+            done
117
+        done
118
+    } \
119
+      | __expand_tokens "MKIT_BUILTIN" "${sections[@]}" \
120
+      | sed '/^  x/ s|x|_|'
121
+}
122
+
117
 build() {
123
 build() {
118
     #
124
     #
119
     # Add meat to all skeletons
125
     # Add meat to all skeletons
122
     semver >/dev/null
128
     semver >/dev/null
123
     find . -type f -name '*.skel' \
129
     find . -type f -name '*.skel' \
124
      | while read -r srcpath; do
130
      | while read -r srcpath; do
125
-           _build1 "$srcpath"
131
+           __build1 "$srcpath"
126
        done
132
        done
127
 }
133
 }
128
 
134
 
129
-build_manpages() {
130
-    #
131
-    # Build manpages using ronn
132
-    #
133
-    local manfile   # each manual file listed in '[files:man]'
134
-    local mdfile    # each source markdown file
135
-    if command -v ronn >/dev/null; then
136
-        ini lskeys "files:man" \
137
-          | while read -r manfile; do
138
-                mdfile="$manfile.md"
139
-                ronn -r "$mdfile"
140
-                rec_built "$manfile"
141
-            done
142
-    else
143
-        echo "ronn is not installed"
144
-        return 1
145
-    fi
146
-}
147
-
148
 clean() {
135
 clean() {
149
     #
136
     #
150
     # Clean up tree after building
137
     # Clean up tree after building
185
       | while read -r dfsrc; do
172
       | while read -r dfsrc; do
186
             dftgt="debian/${dfsrc#$debian_skel}"
173
             dftgt="debian/${dfsrc#$debian_skel}"
187
             mkdir -p "$(dirname "$dftgt")"
174
             mkdir -p "$(dirname "$dftgt")"
188
-            _build1 "$dfsrc" "$dftgt" debstuff
175
+            __build1 "$dfsrc" "$dftgt" debstuff
189
         done
176
         done
190
     rec_built debian
177
     rec_built debian
191
 }
178
 }
194
     #
181
     #
195
     # Create distributable tarball
182
     # Create distributable tarball
196
     #
183
     #
197
-    #FIXME: lacking Makefile skills, we do this step twice fot
184
+    #FIXME: lacking Makefile skills, we do this step twice for
198
     #       rpmstuff, hence -f hack for gzip
185
     #       rpmstuff, hence -f hack for gzip
199
     #
186
     #
200
     local version           # tarball version
187
     local version           # tarball version
223
     specsrc="$(ini 1value "dist:rpmstuff")"
210
     specsrc="$(ini 1value "dist:rpmstuff")"
224
     test -n "$specsrc" || die "dist:rpmstuff not specified"
211
     test -n "$specsrc" || die "dist:rpmstuff not specified"
225
     test -f "$specsrc" || die "specfile template not found: $specsrc"
212
     test -f "$specsrc" || die "specfile template not found: $specsrc"
226
-    _build1 "$specsrc" "$specname" rpmstuff
213
+    __build1 "$specsrc" "$specname" rpmstuff
227
 }
214
 }

+ 13
- 12
utils/mkit/include/deploy.sh View File

4
 
4
 
5
 mkit_import ini
5
 mkit_import ini
6
 
6
 
7
-_deploy_item() {
7
+__deploy_item() {
8
     #
8
     #
9
     # Deploy item and make it look like wanted
9
     # Deploy item and make it look like wanted
10
     #
10
     #
11
-    # usage: _deploy_item src dst [mode]
11
+    # usage: __deploy_item src dst [mode]
12
     #
12
     #
13
     # Both src and dst must be names of actual items[1],
13
     # Both src and dst must be names of actual items[1],
14
     # whereas dst must not exist.  On update, dst is
14
     # whereas dst must not exist.  On update, dst is
37
                 [[ $item =~ .skel$ ]] \
37
                 [[ $item =~ .skel$ ]] \
38
                  && grep -q "${item%.skel}" "$MKIT_LOCAL/built.lst" \
38
                  && grep -q "${item%.skel}" "$MKIT_LOCAL/built.lst" \
39
                  && continue
39
                  && continue
40
-                _deploy_item "$item" "$dst${item#$src}" "$mode"
40
+                __deploy_item "$item" "$dst${item#$src}" "$mode"
41
             done
41
             done
42
     else
42
     else
43
-        _maybe install -DTvm "$mode" "$src" "$dst"
43
+        test "$mode" == "SRC" && mode=$(stat -c "%a" "$src")
44
+        __maybe install -DTvm "$mode" "$src" "$dst"
44
     fi
45
     fi
45
 }
46
 }
46
 
47
 
47
-_get_dst() {
48
+__get_dst() {
48
     #
49
     #
49
     # Find out target path for src file $2 of group $1
50
     # Find out target path for src file $2 of group $1
50
     #
51
     #
52
     local src=$2        # each source
53
     local src=$2        # each source
53
     local dst=$3        # alternative destination name
54
     local dst=$3        # alternative destination name
54
     test -n "$dst" || dst=${src##*/}
55
     test -n "$dst" || dst=${src##*/}
55
-    echo "$(_get_root "$grp")/$dst"
56
+    echo "$(__get_root "$grp")/$dst"
56
 }
57
 }
57
 
58
 
58
-_get_root() {
59
+__get_root() {
59
     #
60
     #
60
     # Find out target root for group $1
61
     # Find out target root for group $1
61
     #
62
     #
72
     esac
73
     esac
73
 }
74
 }
74
 
75
 
75
-_maybe() {
76
+__maybe() {
76
     #
77
     #
77
     # Call the deploy command $1 $@ unless in dry mode
78
     # Call the deploy command $1 $@ unless in dry mode
78
     #
79
     #
101
             mode=$(ini 1value "modes:$group")
102
             mode=$(ini 1value "modes:$group")
102
             ini values "files:$group" \
103
             ini values "files:$group" \
103
               | while read -r src dst; do
104
               | while read -r src dst; do
104
-                    dst=$(_get_dst "$group" "$src" "$dst")
105
-                    _deploy_item "$src" "$dst" "$mode"
105
+                    dst=$(__get_dst "$group" "$src" "$dst")
106
+                    __deploy_item "$src" "$dst" "$mode"
106
                 done
107
                 done
107
         done
108
         done
108
     test -f "$MKIT_LOCAL/autoclean" && clean
109
     test -f "$MKIT_LOCAL/autoclean" && clean
122
       | while read -r group; do
123
       | while read -r group; do
123
             ini values "files:$group" \
124
             ini values "files:$group" \
124
               | while read -r src dst; do
125
               | while read -r src dst; do
125
-                    dst=$(_get_dst "$group" "$src" "$dst")
126
-                    _maybe rm -vrf "$dst"
126
+                    dst=$(__get_dst "$group" "$src" "$dst")
127
+                    __maybe rm -vrf "$dst"
127
                 done
128
                 done
128
         done
129
         done
129
 }
130
 }

+ 27
- 18
utils/mkit/include/ini.sh View File

2
 # MKit - simple install helper
2
 # MKit - simple install helper
3
 # See LICENSE file for copyright and license details.
3
 # See LICENSE file for copyright and license details.
4
 
4
 
5
-_ini_cat() {
5
+__ini_cat() {
6
     #
6
     #
7
     # A no-op for text stream
7
     # A no-op for text stream
8
     #
8
     #
12
     done
12
     done
13
 }
13
 }
14
 
14
 
15
-_ini_expand() {
15
+__ini_expand() {
16
     #
16
     #
17
     # Expand reference value (prefix only)
17
     # Expand reference value (prefix only)
18
     #
18
     #
30
     done
30
     done
31
 }
31
 }
32
 
32
 
33
-_ini_grepkey() {
33
+__ini_grepkey() {
34
     #
34
     #
35
     # Read key from a section
35
     # Read key from a section
36
     #
36
     #
40
       | sed -e 's/ *= */=/; s/ +$//; s/^//;' \
40
       | sed -e 's/ *= */=/; s/ +$//; s/^//;' \
41
       | grep -e "^$wnt=" \
41
       | grep -e "^$wnt=" \
42
       | cut -d= -f2- \
42
       | cut -d= -f2- \
43
-      | _ini_maybe_expand
43
+      | __ini_maybe_expand
44
 }
44
 }
45
 
45
 
46
-_ini_greppath() {
46
+__ini_greppath() {
47
     #
47
     #
48
     # Read key from the right section
48
     # Read key from the right section
49
     #
49
     #
62
          && echo "$override" \
62
          && echo "$override" \
63
          && return
63
          && return
64
     fi
64
     fi
65
-    _ini_grepsec "$wntsec" | _ini_grepkey "$wntkey"
65
+    __ini_grepsec "$wntsec" | __ini_grepkey "$wntkey"
66
 }
66
 }
67
 
67
 
68
-_ini_grepsec() {
68
+__ini_grepsec() {
69
     #
69
     #
70
     # Read one INI section
70
     # Read one INI section
71
     #
71
     #
85
       | sed -e 's/ *= */=/; s/ +$//; s/^//;'
85
       | sed -e 's/ *= */=/; s/ +$//; s/^//;'
86
 }
86
 }
87
 
87
 
88
-_ini_lskeys() {
88
+__ini_lskeys() {
89
     #
89
     #
90
     # List keys from a section
90
     # List keys from a section
91
     #
91
     #
92
     local sct=$1    # section of interest
92
     local sct=$1    # section of interest
93
-    _ini_grepsec "$sct" | cut -d= -f1 | awk '!x[$0]++'
93
+    __ini_grepsec "$sct" | cut -d= -f1 | awk '!x[$0]++'
94
 }
94
 }
95
 
95
 
96
-_ini_maybe_expand() {
96
+__ini_lssect() {
97
+    #
98
+    # List all section names
99
+    #
100
+    local arg=$1    # unused argument
101
+    grep -x '\[.*\]' | sed 's/^.//; s/.$//'
102
+}
103
+
104
+__ini_maybe_expand() {
97
     #
105
     #
98
     # Decide whether or not to expand
106
     # Decide whether or not to expand
99
     #
107
     #
100
     if test "$MKIT_INI_EXPAND" -gt 0; then
108
     if test "$MKIT_INI_EXPAND" -gt 0; then
101
-        MKIT_INI_EXPAND=$(( --MKIT_INI_EXPAND )) _ini_expand
109
+        MKIT_INI_EXPAND=$(( --MKIT_INI_EXPAND )) __ini_expand
102
     else
110
     else
103
-        _ini_cat
111
+        __ini_cat
104
     fi
112
     fi
105
 }
113
 }
106
 
114
 
111
     local op=$1             # operator
119
     local op=$1             # operator
112
     local arg=$2            # argument
120
     local arg=$2            # argument
113
     local fn                # internal function implementing $op
121
     local fn                # internal function implementing $op
114
-    local limit=_ini_cat    # limiting internal function
122
+    local limit=__ini_cat    # limiting internal function
115
     case $op in
123
     case $op in
116
-        lskeys) fn=_ini_lskeys   ;;
117
-        sec)    fn=_ini_grepsec  ;;
118
-        values) fn=_ini_greppath ;;
119
-        1value) fn=_ini_greppath; limit="tail -1" ;;
124
+        lskeys) fn=__ini_lskeys   ;;
125
+        lssect) fn=__ini_lssect   ;;
126
+        sec)    fn=__ini_grepsec  ;;
127
+        values) fn=__ini_greppath ;;
128
+        1value) fn=__ini_greppath; limit="tail -1" ;;
120
         *)      die "incorrect use of \`ini()\`"
129
         *)      die "incorrect use of \`ini()\`"
121
     esac
130
     esac
122
     <"$MKIT_INI" $fn "$arg" | $limit
131
     <"$MKIT_INI" $fn "$arg" | $limit
124
 
133
 
125
 update_version() {
134
 update_version() {
126
     #
135
     #
127
-    # Change project.version in mkit.ini at path $2 to version $1
136
+    # Change project:version in mkit.ini at path $2 to value $1
128
     #
137
     #
129
     local version=$1    # new version
138
     local version=$1    # new version
130
     local inifile=$2    # mkit.ini path
139
     local inifile=$2    # mkit.ini path

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

30
 mkit_import release
30
 mkit_import release
31
 mkit_import ini
31
 mkit_import ini
32
 
32
 
33
-_valid_targets() {
33
+__valid_targets() {
34
     #
34
     #
35
     # List valid routes
35
     # List valid routes
36
     #
36
     #
37
+    echo _mkit_data
37
     echo build
38
     echo build
38
-    echo build_manpages
39
     echo clean
39
     echo clean
40
     echo debstuff
40
     echo debstuff
41
     echo dist
41
     echo dist
76
     done
76
     done
77
 }
77
 }
78
 
78
 
79
-_compver() {
79
+__compver() {
80
     #
80
     #
81
     # True if version $1 matches our version
81
     # True if version $1 matches our version
82
     #
82
     #
103
     return 0
103
     return 0
104
 }
104
 }
105
 
105
 
106
-_chkiniversion() {
106
+__chkiniversion() {
107
     #
107
     #
108
     # Check if ini version is supported
108
     # Check if ini version is supported
109
     #
109
     #
121
     test -n "$ver_line" \
121
     test -n "$ver_line" \
122
      || die "version mark ('#mkit version=x.y.z') not found in: $MKIT_INI"
122
      || die "version mark ('#mkit version=x.y.z') not found in: $MKIT_INI"
123
     their_ver="$(tr -d '[:blank:]v' <<<"${ver_line##*=}")"
123
     their_ver="$(tr -d '[:blank:]v' <<<"${ver_line##*=}")"
124
-    _compver "$their_ver" \
124
+    __compver "$their_ver" \
125
      || die "bad mkit.ini version: $their_ver does not match $MKIT_VERSION"
125
      || die "bad mkit.ini version: $their_ver does not match $MKIT_VERSION"
126
 }
126
 }
127
 
127
 
160
     #shellcheck disable=SC2034
160
     #shellcheck disable=SC2034
161
     MKIT_PROJ_PKGNAME=$(ini 1value "project:pkgname")
161
     MKIT_PROJ_PKGNAME=$(ini 1value "project:pkgname")
162
     test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
162
     test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
163
-    _chkiniversion
163
+    __chkiniversion
164
 }
164
 }
165
 
165
 
166
 rec_built() {
166
 rec_built() {
176
     #
176
     #
177
     # Call correct function based on $1
177
     # Call correct function based on $1
178
     #
178
     #
179
-    if _valid_targets | grep -qwx "^$1"; then
179
+    if __valid_targets | grep -qwx "^$1"; then
180
         "$1"
180
         "$1"
181
     else
181
     else
182
         {
182
         {
183
             echo "usage: $(basename "$0") TARGET"
183
             echo "usage: $(basename "$0") TARGET"
184
             echo
184
             echo
185
             echo "valid targets:"
185
             echo "valid targets:"
186
-            _valid_targets | sed 's/^/    /'
186
+            __valid_targets | sed 's/^/    /'
187
         } >&2
187
         } >&2
188
     fi
188
     fi
189
 }
189
 }

+ 33
- 29
utils/mkit/include/release.sh View File

5
 mkit_import ini
5
 mkit_import ini
6
 mkit_import facts
6
 mkit_import facts
7
 
7
 
8
-_bump_version() {
8
+__bump_version() {
9
     #
9
     #
10
     # Bump version on stdin by level $1 (x, y or z)
10
     # Bump version on stdin by level $1 (x, y or z)
11
     #
11
     #
30
     echo "$new"
30
     echo "$new"
31
 }
31
 }
32
 
32
 
33
-_relck() {
33
+__relck() {
34
     #
34
     #
35
     # Die if blocking condition $1 is detected
35
     # Die if blocking condition $1 is detected
36
     #
36
     #
68
              && die "WIP commit since $(git_fact latest_tag)"
68
              && die "WIP commit since $(git_fact latest_tag)"
69
             ;;
69
             ;;
70
         ini_version)
70
         ini_version)
71
-            oracle=$(git_fact latest_version | _bump_version "$rlevel")
71
+            oracle=$(git_fact latest_version | __bump_version "$rlevel")
72
             ini 1value project:version  \
72
             ini 1value project:version  \
73
               | grep -qFx "$oracle" \
73
               | grep -qFx "$oracle" \
74
              || die "new version not in mkit.ini: $oracle"
74
              || die "new version not in mkit.ini: $oracle"
79
     esac
79
     esac
80
 }
80
 }
81
 
81
 
82
-_release() {
82
+__release() {
83
     #
83
     #
84
     # Prepare release
84
     # Prepare release
85
     #
85
     #
94
     local relsrc        # release source branch (if any)
94
     local relsrc        # release source branch (if any)
95
     local reldst        # release destination branch (if any)
95
     local reldst        # release destination branch (if any)
96
 
96
 
97
-    _relck git_present
98
-    _relck at_relsrc
99
-    _relck not_dirty
100
-    _relck tags_ok
101
-    _relck vbump_hot
102
-    _relck no_wip
103
-    _relck ini_version
97
+    __relck git_present
98
+    __relck at_relsrc
99
+    __relck not_dirty
100
+    __relck tags_ok
101
+    __relck vbump_hot
102
+    __relck no_wip
103
+    __relck ini_version
104
 
104
 
105
-    newtag=$(git_fact latest_version | _bump_version "$rlevel" | git_ver2tag )
105
+    newtag=$(git_fact latest_version | __bump_version "$rlevel" | git_ver2tag )
106
     set -e
106
     set -e
107
     debug_var newtag
107
     debug_var newtag
108
     $MKIT_DRY && return
108
     $MKIT_DRY && return
109
-    git tag -m "$(_release_msg)" "$newtag"
109
+    git tag -m "$(__release_msg)" "$newtag"
110
 
110
 
111
     relsrc=$(ini 1value project:relsrc)
111
     relsrc=$(ini 1value project:relsrc)
112
     reldst=$(ini 1value project:reldst)
112
     reldst=$(ini 1value project:reldst)
116
     fi
116
     fi
117
 }
117
 }
118
 
118
 
119
-_release_msg() {
119
+__release_msg() {
120
     #
120
     #
121
     # Generate message for annotated tag
121
     # Generate message for annotated tag
122
     #
122
     #
133
       | tail -n +3
133
       | tail -n +3
134
 }
134
 }
135
 
135
 
136
-_vbump() {
136
+__vbump() {
137
     #
137
     #
138
     # Do version bump at level $1
138
     # Do version bump at level $1
139
     #
139
     #
142
     #
142
     #
143
     local rlevel=$1     # bump level (x, y or z)
143
     local rlevel=$1     # bump level (x, y or z)
144
     local nextver       # version after the bump
144
     local nextver       # version after the bump
145
-    _relck git_present
146
-    _relck at_relsrc
147
-    _relck not_dirty
148
-    nextver=$(ini 1value project:version | _bump_version "$rlevel")
145
+    local cache         # cache for the message
146
+    __relck git_present
147
+    __relck at_relsrc
148
+    __relck not_dirty
149
+    nextver=$(ini 1value project:version | __bump_version "$rlevel")
149
     debug_var nextver
150
     debug_var nextver
150
     $MKIT_DRY && return
151
     $MKIT_DRY && return
151
     update_version "$nextver" mkit.ini \
152
     update_version "$nextver" mkit.ini \
152
       || die "failed to update version in mkit.ini"
153
       || die "failed to update version in mkit.ini"
153
     git add mkit.ini \
154
     git add mkit.ini \
154
       || die "failed to add mkit.ini to the index"
155
       || die "failed to add mkit.ini to the index"
155
-    git commit -e -m "$(_vbump_gitmsg)"
156
+    cache=$(mktemp -t "mkit._vbump_gitmsg.XXXXXXXX")
157
+    _vbump_gitmsg > "$cache"
158
+    git commit -e -F "$cache"   # note: reading from stdin will break vim
159
+    rm "$cache"
156
 }
160
 }
157
 
161
 
158
 _vbump_gitmsg() {
162
 _vbump_gitmsg() {
165
     echo ""
169
     echo ""
166
     git_fact reldiff \
170
     git_fact reldiff \
167
       | sed '
171
       | sed '
168
-            s/^[a-f0-9]\{7\} / *  &/; t PATHS
172
+            s/^[a-f0-9]\{7\} /\n *  &/; t PATHS
169
             s/^/        /
173
             s/^/        /
170
             :PATHS
174
             :PATHS
171
         '
175
         '
175
     #
179
     #
176
     # Perform release on Z level
180
     # Perform release on Z level
177
     #
181
     #
178
-    _release z
182
+    __release z
179
 }
183
 }
180
 
184
 
181
 release_x() {
185
 release_x() {
182
     #
186
     #
183
     # Perform release on X level
187
     # Perform release on X level
184
     #
188
     #
185
-    _release x
189
+    __release x
186
 }
190
 }
187
 
191
 
188
 release_y() {
192
 release_y() {
189
     #
193
     #
190
     # Perform release on Y level
194
     # Perform release on Y level
191
     #
195
     #
192
-    _release y
196
+    __release y
193
 }
197
 }
194
 
198
 
195
 release_z() {
199
 release_z() {
196
     #
200
     #
197
     # Perform release on Z level
201
     # Perform release on Z level
198
     #
202
     #
199
-    _release z
203
+    __release z
200
 }
204
 }
201
 
205
 
202
 vbump() {
206
 vbump() {
203
     #
207
     #
204
     # Perform version bump on Z level
208
     # Perform version bump on Z level
205
     #
209
     #
206
-    _vbump z
210
+    __vbump z
207
 }
211
 }
208
 
212
 
209
 vbump_x() {
213
 vbump_x() {
210
     #
214
     #
211
     # Perform version bump on X level
215
     # Perform version bump on X level
212
     #
216
     #
213
-    _vbump x
217
+    __vbump x
214
 }
218
 }
215
 
219
 
216
 vbump_y() {
220
 vbump_y() {
217
     #
221
     #
218
     # Perform version bump on Y level
222
     # Perform version bump on Y level
219
     #
223
     #
220
-    _vbump y
224
+    __vbump y
221
 }
225
 }
222
 
226
 
223
 vbump_z() {
227
 vbump_z() {
224
     #
228
     #
225
     # Perform version bump on Z level
229
     # Perform version bump on Z level
226
     #
230
     #
227
-    _vbump z
231
+    __vbump z
228
 }
232
 }

+ 1
- 1
utils/mkit/include/vars.sh View File

58
 #
58
 #
59
 # This MKit version
59
 # This MKit version
60
 #
60
 #
61
-MKIT_VERSION=0.0.25
61
+MKIT_VERSION=0.0.28

+ 19
- 19
utils/mkit/mkit.mk View File

5
 
5
 
6
 all: build
6
 all: build
7
 
7
 
8
-build:
9
-	@$(MKIT_DIR)/make build
8
+_mkit_data:
9
+	@"$(MKIT_DIR)"/make _mkit_data
10
 
10
 
11
-manpages: build
12
-	@$(MKIT_DIR)/make build_manpages
11
+build:
12
+	@"$(MKIT_DIR)"/make build
13
 
13
 
14
 clean:
14
 clean:
15
-	@$(MKIT_DIR)/make clean
15
+	@"$(MKIT_DIR)"/make clean
16
 
16
 
17
 debstuff: dist
17
 debstuff: dist
18
-	@$(MKIT_DIR)/make debstuff
18
+	@"$(MKIT_DIR)"/make debstuff
19
 
19
 
20
 dist: clean
20
 dist: clean
21
-	@$(MKIT_DIR)/make dist
21
+	@"$(MKIT_DIR)"/make dist
22
 
22
 
23
 rpmstuff: dist
23
 rpmstuff: dist
24
-	@$(MKIT_DIR)/make rpmstuff
24
+	@"$(MKIT_DIR)"/make rpmstuff
25
 
25
 
26
 install: all
26
 install: all
27
-	@$(MKIT_DIR)/make install
27
+	@"$(MKIT_DIR)"/make install
28
 
28
 
29
 release:
29
 release:
30
-	@$(MKIT_DIR)/make release
30
+	@"$(MKIT_DIR)"/make release
31
 
31
 
32
 release_x:
32
 release_x:
33
-	@$(MKIT_DIR)/make release_x
33
+	@"$(MKIT_DIR)"/make release_x
34
 
34
 
35
 release_y:
35
 release_y:
36
-	@$(MKIT_DIR)/make release_y
36
+	@"$(MKIT_DIR)"/make release_y
37
 
37
 
38
 release_z:
38
 release_z:
39
-	@$(MKIT_DIR)/make release_z
39
+	@"$(MKIT_DIR)"/make release_z
40
 
40
 
41
 uninstall:
41
 uninstall:
42
-	@$(MKIT_DIR)/make uninstall
42
+	@"$(MKIT_DIR)"/make uninstall
43
 
43
 
44
 vbump:
44
 vbump:
45
-	@$(MKIT_DIR)/make vbump
45
+	@"$(MKIT_DIR)"/make vbump
46
 
46
 
47
 vbump_x:
47
 vbump_x:
48
-	@$(MKIT_DIR)/make vbump_x
48
+	@"$(MKIT_DIR)"/make vbump_x
49
 
49
 
50
 vbump_y:
50
 vbump_y:
51
-	@$(MKIT_DIR)/make vbump_y
51
+	@"$(MKIT_DIR)"/make vbump_y
52
 
52
 
53
 vbump_z:
53
 vbump_z:
54
-	@$(MKIT_DIR)/make vbump_z
54
+	@"$(MKIT_DIR)"/make vbump_z
55
 
55
 
56
-.PHONY: all clean dist rpmstuff install uninstall release release_x release_y release_z vbump vbump_x vbump_y vbump_z
56
+.PHONY: all _mkit_data clean dist rpmstuff install uninstall release release_x release_y release_z vbump vbump_x vbump_y vbump_z

+ 75
- 49
utils/mkit/stub View File

58
             echo "$any_name"
58
             echo "$any_name"
59
             tr -c '=\n' '=' <<<"$any_name"
59
             tr -c '=\n' '=' <<<"$any_name"
60
             echo ''
60
             echo ''
61
-            echo ''
62
             if test -n "$Tagline"; then
61
             if test -n "$Tagline"; then
63
                 echo "$Tagline"
62
                 echo "$Tagline"
64
             else
63
             else
68
 
67
 
69
         */mkit.ini|mkit.ini)
68
         */mkit.ini|mkit.ini)
70
             echo "[project]"
69
             echo "[project]"
71
-            echo "    version     = $Version"
72
-            test -n "$Codename"     && echo "    codename    = $Codename"
73
-            test -n "$NiceName"     && echo "    name        = $NiceName"
74
-            test -n "$Tagline"      && echo "    tagline     = $Tagline"
75
-            test -n "$PackageName"  && echo "    pkgname     = $PackageName"
76
-            test -n "$Maintainer"   && echo "    maintainer  = $Maintainer"
77
-            test -n "$VcsBrowser"   && echo "    vcs_browser = $VcsBrowser"
78
-            test -n "$RelSrc"       && echo "    relsrc      = $RelSrc"
79
-            test -n "$RelDst"       && echo "    reldst      = $RelDst"
70
+            {
71
+                echo "version = $Version"
72
+                test -n "$Codename"     && echo "codename    = $Codename"
73
+                test -n "$NiceName"     && echo "name        = $NiceName"
74
+                test -n "$Tagline"      && echo "tagline     = $Tagline"
75
+                test -n "$PackageName"  && echo "pkgname     = $PackageName"
76
+                test -n "$Maintainer"   && echo "maintainer  = $Maintainer"
77
+                test -n "$VcsBrowser"   && echo "vcs_browser = $VcsBrowser"
78
+                test -n "$RelSrc"       && echo "relsrc      = $RelSrc"
79
+                test -n "$RelDst"       && echo "reldst      = $RelDst"
80
+            } | reformat_section
80
             if updating; then
81
             if updating; then
81
                 remake_section dist
82
                 remake_section dist
82
                 remake_section ENV
83
                 remake_section ENV
87
             else
88
             else
88
                 echo ""
89
                 echo ""
89
                 echo "[dist]"
90
                 echo "[dist]"
90
-                $MkLicense  && echo "    tarball = LICENSE.md"
91
-                $MkMakefile && echo "    tarball = Makefile"
92
-                $MkReadme   && echo "    tarball = README.md"
93
-                echo "    tarball = mkit.ini"
94
-                $MkPackaging && echo "    tarball = packaging"
95
-                echo "    tarball = src"
96
-                echo "    tarball = tests"
97
-                echo "    tarball = utils"
98
-                $MkPackaging && echo "    rpmstuff = packaging/template.spec"
99
-                $MkPackaging && echo "    debstuff = packaging/debian"
91
+                {
92
+                    $MkLicense  && echo "tarball = LICENSE.md"
93
+                    $MkMakefile && echo "tarball = Makefile"
94
+                    $MkReadme   && echo "tarball = README.md"
95
+                    echo "tarball = mkit.ini"
96
+                    $MkPackaging && echo "tarball = packaging"
97
+                    echo "tarball = src"
98
+                    echo "tarball = tests"
99
+                    echo "tarball = utils"
100
+                    $MkPackaging && echo "rpmstuff = packaging/template.spec"
101
+                    $MkPackaging && echo "debstuff = packaging/debian"
102
+                } | reformat_section
100
                 echo ""
103
                 echo ""
101
                 echo "[ENV]"
104
                 echo "[ENV]"
102
-                echo "    PREFIX = /usr/local"
105
+                {
106
+                    echo "    PREFIX = /usr/local"
107
+                } | reformat_section
103
                 echo ""
108
                 echo ""
104
                 echo "[roots]"
109
                 echo "[roots]"
105
-                echo "    bin     = [ENV:PREFIX]/bin"
106
-                echo "    doc     = [ENV:PREFIX]/share/doc/$PackageName"
110
+                {
111
+                    echo "bin = [ENV:PREFIX]/bin"
112
+                    echo "doc = [ENV:PREFIX]/share/doc/$PackageName"
113
+                } | reformat_section
107
                 echo ""
114
                 echo ""
108
                 echo "[tokens]"
115
                 echo "[tokens]"
109
-                echo "    __${PackageName^^}_FOO__ = Barr.."
116
+                {
117
+                    echo "__${PackageName^^}_FOO__ = Barr.."
118
+                } | reformat_section
110
                 echo ""
119
                 echo ""
111
                 echo "[modes]"
120
                 echo "[modes]"
112
-                echo "    bin     = 755"
113
-                echo "    doc     = 644"
121
+                {
122
+                    echo "bin = 755"
123
+                    echo "doc = 644"
124
+                } | reformat_section
114
                 echo ""
125
                 echo ""
115
                 echo "[files]"
126
                 echo "[files]"
116
-                echo "    bin      = src/$PackageName"
117
-                $MkLicense && echo "    doc      = LICENSE.md"
118
-                $MkReadme  && echo "    doc      = README.md"
127
+                {
128
+                    echo "bin = src/$PackageName"
129
+                    $MkLicense && echo "doc = LICENSE.md"
130
+                    $MkReadme  && echo "doc = README.md"
131
+                } | reformat_section
119
             fi
132
             fi
120
             echo ""
133
             echo ""
121
             echo "#mkit version=$MKIT_VERSION"
134
             echo "#mkit version=$MKIT_VERSION"
122
             ;;
135
             ;;
123
 
136
 
124
         packaging/template.spec)
137
         packaging/template.spec)
125
-            echo 'Name:		__MKIT_PROJ_PKGNAME__'
126
-            echo 'Version:	__MKIT_PROJ_VERSION__'
127
-            echo 'Release:	1%{?dist}'
128
-            echo 'Summary:	__MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__'
129
-            echo ''
130
-            $MkLicense && echo "License:	$License"
131
-            echo 'Source0:	%{name}-%{version}.tar.gz'
138
+            echo 'Name:       __MKIT_PROJ_PKGNAME__'
139
+            echo 'Version:    __MKIT_PROJ_VERSION__'
140
+            echo 'Release:    1%{?dist}'
141
+            echo 'Summary:    __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__'
142
+            test -n "$VcsBrowser" && echo 'URL:        __MKIT_PROJ_VCS_BROWSER__'
143
+            $MkLicense && echo "License:    $License"
132
             echo ''
144
             echo ''
133
-            echo 'BuildArch:	noarch'
134
-            echo 'BuildRequires:	coreutils git'
135
-            echo 'Requires:	MKIT_STUB_REQUIRES'
145
+            echo 'Source0:    %{name}-%{version}.tar.gz'
146
+            echo 'BuildArch:  noarch'
136
             echo ''
147
             echo ''
148
+            echo 'Requires: MKIT_STUB_REQUIRES'
137
             echo '%description'
149
             echo '%description'
138
             echo 'MKIT_STUB_DESCRIPTION'
150
             echo 'MKIT_STUB_DESCRIPTION'
139
             echo ''
151
             echo ''
198
             echo 'override_dh_auto_install:'
210
             echo 'override_dh_auto_install:'
199
             echo ''
211
             echo ''
200
             echo '	make install PREFIX=/usr DESTDIR=debian/tmp'
212
             echo '	make install PREFIX=/usr DESTDIR=debian/tmp'
201
-            echo ''
202
-            echo 'override_dh_usrlocal:'
203
-            echo ''
204
-            echo '	@true'
205
             ;;
213
             ;;
206
 
214
 
207
         packaging/debian/source/format)
215
         packaging/debian/source/format)
208
             echo '3.0 (quilt)'
216
             echo '3.0 (quilt)'
209
             ;;
217
             ;;
210
 
218
 
211
-        packaging/debian/*.install)
219
+        packaging/debian/install)
212
             echo MKIT_STUB_FILELIST
220
             echo MKIT_STUB_FILELIST
213
             ;;
221
             ;;
214
 
222
 
318
             echo "     *  \`MKIT_STUB_FILELIST\` - List of full paths to"
326
             echo "     *  \`MKIT_STUB_FILELIST\` - List of full paths to"
319
             echo "        your files after installation."
327
             echo "        your files after installation."
320
             echo ""
328
             echo ""
321
-            echo "        Note that in case of debian/package.install files,"
322
-            echo "        PREFIX based paths (eg. /usr/bin) in this file should"
323
-            echo "        should be as if PREFIX was /usr."
329
+            echo "        Note that in case of debian/install files, PREFIX"
330
+            echo "        based paths (eg. /usr/bin) in this file should be as"
331
+            echo "        if PREFIX was /usr."
324
             echo ""
332
             echo ""
325
             echo "        In case of Fedora-based distro, you should make use"
333
             echo "        In case of Fedora-based distro, you should make use"
326
             echo "        of RPM macros:"
334
             echo "        of RPM macros:"
551
     deploy packaging/debian/control
559
     deploy packaging/debian/control
552
     deploy packaging/debian/changelog
560
     deploy packaging/debian/changelog
553
     deploy packaging/debian/compat
561
     deploy packaging/debian/compat
562
+    deploy packaging/debian/install
554
     deploy packaging/debian/rules
563
     deploy packaging/debian/rules
555
     deploy packaging/debian/source/format
564
     deploy packaging/debian/source/format
556
-    deploy packaging/debian/"$PackageName".install
557
 }
565
 }
558
 
566
 
559
 init_from_existing() {
567
 init_from_existing() {
615
                     echo "$key = $value"
623
                     echo "$key = $value"
616
                 done
624
                 done
617
         done \
625
         done \
618
-      | column -to' ' \
626
+      | reformat_section
627
+}
628
+
629
+reformat_section() {
630
+    #
631
+    # Re-format "k = v" on stdin as "nice" ini section
632
+    #
633
+    local key
634
+    local eq
635
+    local value
636
+    while read -r key eq value; do
637
+        test "$eq" == "=" || {
638
+            warn "ignoring malformed ini line: $key $eq $value"
639
+            continue
640
+        }
641
+        echo "$key = $value"
642
+    done \
643
+      | sed 's/ *= */=/; s/^ *//; s/ *$//' \
644
+      | column -t -s= -o' = ' \
619
       | sed 's/^/    /'
645
       | sed 's/^/    /'
620
 }
646
 }
621
 
647