Sfoglia il codice sorgente

Update own dogfood

Alois Mahdal 7 anni fa
parent
commit
dfe09d2b2b

+ 4
- 2
utils/mkit/include/build.sh Vedi File

@@ -1,7 +1,9 @@
1 1
 #!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
2 4
 
3
-. "$MKIT_DIR/include/ini.sh"   || die "cannot import ini.sh"
4
-. "$MKIT_DIR/include/facts.sh" || die "cannot import facts.sh"
5
+mkit_import ini
6
+mkit_import facts
5 7
 
6 8
 
7 9
 _build1() {

+ 9
- 6
utils/mkit/include/deploy.sh Vedi File

@@ -1,4 +1,6 @@
1 1
 #!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
2 4
 
3 5
 _deploy_item() {
4 6
     #
@@ -26,13 +28,14 @@ _deploy_item() {
26 28
     local src=$1                            # source path
27 29
     local dst=$2                            # destination path
28 30
     local mode=${3:-$MKIT_DEFAULT_MODE}     # mode
29
-    local chmod_item                        # each file to chmod in directory
31
+    local item                              # each in directory
30 32
     if test -d "$src"; then
31
-        _maybe mkdir -vp "$(dirname "$dst")"
32
-        _maybe cp -Tvr "$src" "$dst"
33
-        find "$dst" -type f \
34
-          | while read -r chmod_item; do
35
-                _maybe chmod "$mode" "$chmod_item"
33
+        find "$src" -type f \
34
+          | while read -r item; do
35
+                [[ $item =~ .skel$ ]] \
36
+                 && grep -q "${item%.skel}" "$MKIT_LOCAL/built.lst" \
37
+                 && continue
38
+                _deploy_item "$item" "$dst${item#$src}" "$mode"
36 39
             done
37 40
     else
38 41
         _maybe install -DTvm "$mode" "$src" "$dst"

+ 3
- 1
utils/mkit/include/facts.sh Vedi File

@@ -1,6 +1,8 @@
1 1
 #!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
2 4
 
3
-. "$MKIT_DIR/include/ini.sh" || die "cannot import ini.sh"
5
+mkit_import ini
4 6
 
5 7
 git_bool() {
6 8
     #

+ 2
- 0
utils/mkit/include/ini.sh Vedi File

@@ -1,4 +1,6 @@
1 1
 #!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
2 4
 
3 5
 _ini_cat() {
4 6
     #

+ 29
- 12
utils/mkit/include/mkit.sh Vedi File

@@ -1,9 +1,34 @@
1 1
 #!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
2 4
 
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"
5
+die() {
6
+    #
7
+    # Exit with message and non-zero exit status
8
+    #
9
+    echo "fatal: $*" >&2
10
+    exit 4
11
+}
12
+
13
+mkit_import() {
14
+    #
15
+    # Import mkit module $1.sh
16
+    #
17
+    # Check for module, source it and die with reasonable message if needed.
18
+    #
19
+    local modname=$1
20
+    local modpath
21
+    modpath="$MKIT_DIR/include/$modname.sh"
22
+    test -f "$modpath" || die "no such module: $modpath"
23
+    bash -n "$modpath" || die "bad syntax: $modpath"
24
+    #shellcheck disable=SC1090
25
+    . "$modpath" || die "failed to import: $modname"
26
+}
27
+
28
+mkit_import build
29
+mkit_import deploy
30
+mkit_import release
31
+mkit_import ini
7 32
 
8 33
 _valid_targets() {
9 34
     #
@@ -49,14 +74,6 @@ debug_var() {
49 74
     done
50 75
 }
51 76
 
52
-die() {
53
-    #
54
-    # Exit with message and non-zero exit status
55
-    #
56
-    echo "fatal: $*" >&2
57
-    exit 4
58
-}
59
-
60 77
 _compver() {
61 78
     #
62 79
     # True if version $1 matches our version

+ 4
- 2
utils/mkit/include/release.sh Vedi File

@@ -1,7 +1,9 @@
1 1
 #!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
2 4
 
3
-. "$MKIT_DIR/include/ini.sh"   || die "cannot import ini.sh"
4
-. "$MKIT_DIR/include/facts.sh" || die "cannot import facts.sh"
5
+mkit_import ini
6
+mkit_import facts
5 7
 
6 8
 _bump_version() {
7 9
     #

+ 60
- 0
utils/mkit/include/vars.sh Vedi File

@@ -0,0 +1,60 @@
1
+#!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
5
+
6
+#
7
+# Bump size (for vbump_? and release_?)
8
+#
9
+MKIT_BUMPSIZE=${MKIT_BUMPSIZE:-1}
10
+
11
+#
12
+# Debug mode (true|false)
13
+#
14
+MKIT_DEBUG=${MKIT_DEBUG:-false}
15
+
16
+#
17
+# Default deploy mode for files
18
+#
19
+MKIT_DEFAULT_MODE="644"
20
+
21
+#
22
+# Dry mode (true|false)
23
+#
24
+# Set to true to not install anything. Implies MKIT_DEBUG.
25
+#
26
+MKIT_DRY=${MKIT_DRY:-false}
27
+
28
+#
29
+# Path to mkit.ini
30
+#
31
+MKIT_INI=${MKIT_INI:-mkit.ini}
32
+
33
+#
34
+# Limit ini expansion depth
35
+#
36
+# To avoid endless loops, this value is subtracted each
37
+# time ini() expands a reference; when zero is reached,
38
+# no more expansions happen.
39
+#
40
+MKIT_INI_EXPAND=2
41
+
42
+#
43
+# Path to MKit local config and temp
44
+#
45
+# Typically hidden in project root, here MKit can
46
+# save its temporary lists.
47
+#
48
+MKIT_LOCAL=${MKIT_LOCAL:-.mkit}
49
+
50
+#
51
+# Package name
52
+#
53
+# Used as base for tarball and in some default tokens.
54
+#
55
+MKIT_PROJ_PKGNAME=""
56
+
57
+#
58
+# This MKit version
59
+#
60
+MKIT_VERSION=0.0.20+devel.g7c137e5

+ 10
- 62
utils/mkit/make Vedi File

@@ -1,79 +1,27 @@
1 1
 #!/bin/bash
2
-#shellcheck disable=SC2034,SC1090
2
+#shellcheck disable=SC2034
3 3
 # mkit - simple install helper
4 4
 # See LICENSE file for copyright and license details.
5 5
 
6
-die() {
6
+init_core() {
7 7
     #
8
-    # Poor man's die() (mkit.sh has better)
8
+    # Load core module (or die)
9 9
     #
10
-    echo "$@" >&2 && exit 9
10
+    #shellcheck disable=SC1090
11
+    . "$MKIT_DIR/include/mkit.sh" \
12
+     && . "$MKIT_DIR/include/vars.sh" \
13
+     && return 0
14
+    echo "failed to load core; check if MKIT_DIR is set properly: $MKIT_DIR" >&2
15
+    exit 9
11 16
 }
12 17
 
13
-
14
-#
15
-# Bump size (for vbump_? and release_?)
16
-#
17
-MKIT_BUMPSIZE=${MKIT_BUMPSIZE:-1}
18
-
19
-#
20
-# Debug mode (true|false)
21
-#
22
-MKIT_DEBUG=${MKIT_DEBUG:-false}
23
-
24
-#
25
-# Default deploy mode for files
26
-#
27
-MKIT_DEFAULT_MODE="644"
28
-
29 18
 #
30 19
 # Path to MKit dir (where 'include' is)
31 20
 #
32 21
 MKIT_DIR=${MKIT_DIR:-$(dirname "$0")}
33 22
 
34
-#
35
-# Dry mode (true|false)
36
-#
37
-# Set to true to not install anything. Implies MKIT_DEBUG.
38
-#
39
-MKIT_DRY=${MKIT_DRY:-false}
40
-
41
-#
42
-# Path to mkit.ini
43
-#
44
-MKIT_INI=${MKIT_INI:-mkit.ini}
45
-
46
-#
47
-# Limit ini expansion depth
48
-#
49
-# To avoid endless loops, this value is subtracted each
50
-# time ini() expands a reference; when zero is reached,
51
-# no more expansions happen.
52
-#
53
-MKIT_INI_EXPAND=2
54
-
55
-#
56
-# Path to MKit local config and temp
57
-#
58
-# Typically hidden in project root, here MKit can
59
-# save its temporary lists.
60
-#
61
-MKIT_LOCAL=${MKIT_LOCAL:-.mkit}
62
-
63
-#
64
-# Package name
65
-#
66
-# Used as base for tarball and in some default tokens.
67
-#
68
-MKIT_PROJ_PKGNAME=""
69
-
70
-#
71
-# This MKit version
72
-#
73
-MKIT_VERSION=0.0.19+devel.ge8a2332
74
-
75 23
 
76
-. "$MKIT_DIR/include/mkit.sh" || die "failed to init; check if MKIT_DIR is set properly: $MKIT_DIR"
24
+init_core
77 25
 
78 26
 case "$1" in
79 27
     --version-semver) echo "$MKIT_VERSION"; exit 0 ;;

+ 591
- 0
utils/mkit/newstub Vedi File

@@ -0,0 +1,591 @@
1
+#!/bin/bash
2
+# mkit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
5
+init_core() {
6
+    #
7
+    # Load core modules (or die)
8
+    #
9
+    #shellcheck disable=SC1090
10
+    . "$MKIT_DIR/include/mkit.sh" \
11
+     && . "$MKIT_DIR/include/vars.sh" \
12
+     && return 0
13
+    echo "failed to load core; check if MKIT_DIR is set properly: $MKIT_DIR" >&2
14
+    exit 9
15
+}
16
+
17
+#
18
+# Path to MKit dir (where 'include' is)
19
+#
20
+MKIT_DIR=${MKIT_DIR:-$(dirname "$0")}
21
+
22
+init_core
23
+
24
+declare -A MKIT_INIT_LICENSES
25
+MKIT_INIT_LICENSES[GPLv1]="http://www.gnu.org/licenses/old-licenses/gpl-1.0.md"
26
+MKIT_INIT_LICENSES[GPLv2]="http://www.gnu.org/licenses/old-licenses/gpl-2.0.md"
27
+MKIT_INIT_LICENSES[GPLv3]="http://www.gnu.org/licenses/gpl-3.0.md"
28
+MKIT_INIT_LICENSES[LGPLv2]="http://www.gnu.org/licenses/old-licenses/lgpl-2.1.md"
29
+MKIT_INIT_LICENSES[LGPLv3]="http://www.gnu.org/licenses/lgpl-3.0.md"
30
+MKIT_INIT_LICENSES[AGPLv3]="http://www.gnu.org/licenses/agpl-3.0.md"
31
+MKIT_INIT_LICENSES[FDLv1.3]="http://www.gnu.org/licenses/fdl-1.3.md"
32
+MKIT_INIT_LICENSES[FDLv1.2]="http://www.gnu.org/licenses/old-licenses/fdl-1.2.md"
33
+MKIT_INIT_LICENSES[FDLv1.1]="http://www.gnu.org/licenses/old-licenses/fdl-1.1.md"
34
+
35
+
36
+deploy() {
37
+    local file=$1       # which known file?
38
+    local any_name=${NiceName:-$PackageName}
39
+    mkdir -p "$(dirname "$file")"
40
+    case $file in
41
+
42
+        Makefile)
43
+            echo -n "# $any_name"
44
+            test -n "$Tagline" && echo -n " - $Tagline"
45
+            echo
46
+            echo '# See LICENSE.md file for copyright and license details.'
47
+            echo ''
48
+            echo 'MKIT_DIR=utils/mkit'
49
+            #shellcheck disable=SC2016
50
+            echo 'include $(MKIT_DIR)/mkit.mk'
51
+            ;;
52
+
53
+        README.md)
54
+            echo "$any_name"
55
+            tr -c '=\n' '=' <<<"$any_name"
56
+            echo ''
57
+            echo ''
58
+            if test -n "$Tagline"; then
59
+                echo "$Tagline"
60
+            else
61
+                echo "(Nothing to say about this project.)"
62
+            fi
63
+            ;;
64
+
65
+        mkit.ini)
66
+            echo "#mkit version=$MKIT_VERSION"
67
+            echo ""
68
+            echo "[project]"
69
+            echo "    version     = 0.0.0"
70
+            test -n "$Codename"     && echo "    codename    = $Codename"
71
+            test -n "$NiceName"     && echo "    name        = $NiceName"
72
+            test -n "$Tagline"      && echo "    tagline     = $Tagline"
73
+            test -n "$PackageName"  && echo "    pkgname     = $PackageName"
74
+            test -n "$Maintainer"   && echo "    maintainer  = $Maintainer"
75
+            test -n "$VcsBrowser"   && echo "    vcs_browser = $VcsBrowser"
76
+            test -n "$RelSrc"       && echo "    relsrc      = $RelSrc"
77
+            test -n "$RelDst"       && echo "    reldst      = $RelDst"
78
+            echo ""
79
+            echo "[dist]"
80
+            echo "    tarball = LICENSE.md"
81
+            $MkMakefile && echo "    tarball = Makefile"
82
+            $MkReadme   && echo "    tarball = README.md"
83
+            echo "    tarball = mkit.ini"
84
+            $MkPackaging && echo "    tarball = packaging"
85
+            echo "    tarball = src"
86
+            echo "    tarball = tests"
87
+            echo "    tarball = utils"
88
+            $MkPackaging && echo "    rpmstuff = packaging/template.spec"
89
+            $MkPackaging && echo "    debstuff = packaging/debian"
90
+            echo ""
91
+            echo "[ENV]"
92
+            echo "    PREFIX = /usr/local"
93
+            echo ""
94
+            echo "[roots]"
95
+            echo "    bin     = [ENV:PREFIX]/bin"
96
+            echo "    doc     = [ENV:PREFIX]/share/doc/$PackageName"
97
+            echo ""
98
+            echo "[tokens]"
99
+            echo "    __BIN_DIR__ = [roots:bin]"
100
+            echo ""
101
+            echo "[modes]"
102
+            echo "    bin     = 755"
103
+            echo "    doc     = 644"
104
+            echo ""
105
+            echo "[files]"
106
+            echo "    bin      = src/$PackageName"
107
+            $MkReadme && echo "    doc      = LICENSE.md"
108
+            test -n "$License" && echo "    doc      = README.md"
109
+            ;;
110
+
111
+        packaging/template.spec)
112
+            echo 'Name:		__MKIT_PROJ_PKGNAME__'
113
+            echo 'Version:	__MKIT_PROJ_VERSION__'
114
+            echo 'Release:	1%{?dist}'
115
+            echo 'Summary:	__MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__'
116
+            echo ''
117
+            echo "License:	$License"
118
+            echo 'Source0:	%{name}-%{version}.tar.gz'
119
+            echo ''
120
+            echo 'BuildArch:	noarch'
121
+            echo 'BuildRequires:	coreutils git'
122
+            echo 'Requires:	MKIT_NEWSTUB_REQUIRES'
123
+            echo ''
124
+            echo '%description'
125
+            echo 'MKIT_NEWSTUB_DESCRIPTION'
126
+            echo ''
127
+            echo '%prep'
128
+            echo '%setup -q'
129
+            echo ''
130
+            echo '%build'
131
+            echo 'make %{?_smp_mflags}'
132
+            echo ''
133
+            echo '%install'
134
+            echo '%make_install'
135
+            echo ''
136
+            echo '%files'
137
+            echo 'MKIT_NEWSTUB_FILELIST'
138
+            echo ''
139
+            echo '%changelog'
140
+            echo ''
141
+            echo '# specfile built with MKit __MKIT_SELF_VERSION__'
142
+            ;;
143
+
144
+        packaging/debian/copyright)
145
+            echo ""
146
+            ;;
147
+
148
+        packaging/debian/control)
149
+            echo 'Source: __MKIT_PROJ_PKGNAME__'
150
+            echo 'Maintainer: __MKIT_PROJ_MAINTAINER__'
151
+            test -n "$VcsBrowser" && echo 'Vcs-Browser: __MKIT_PROJ_VCS_BROWSER__'
152
+            echo 'Section: misc'
153
+            echo 'Priority: extra'
154
+            echo 'Standards-Version: 3.9.2'
155
+            echo 'Build-Depends: debhelper (>= 9)'
156
+            echo ''
157
+            echo 'Package: __MKIT_PROJ_PKGNAME__'
158
+            echo 'Architecture: all'
159
+            echo 'Depends: MKIT_NEWSTUB_REQUIRES'
160
+            echo 'Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__'
161
+            echo ' MKIT_NEWSTUB_DESCRIPTION'
162
+            echo ''
163
+            echo '# control file built with MKit __MKIT_SELF_VERSION__'
164
+            ;;
165
+
166
+        packaging/debian/changelog)
167
+            echo '__MKIT_PROJ_PKGNAME__ (__MKIT_PROJ_VERSION__-1) UNRELEASED; urgency=medium'
168
+            echo ''
169
+            echo '  * Initial release. (Closes: #XXXXXX)'
170
+            echo ''
171
+            echo " -- __MKIT_PROJ_MAINTAINER__  $(date -R)"
172
+            ;;
173
+
174
+        packaging/debian/compat)
175
+            echo 9
176
+            ;;
177
+
178
+        packaging/debian/rules)
179
+            echo '#!/usr/bin/make -f'
180
+            echo ''
181
+            echo '%:'
182
+            echo ''
183
+            echo '	dh $@'
184
+            echo ''
185
+            echo 'override_dh_auto_install:'
186
+            echo ''
187
+            echo '	make install DESTDIR=debian/tmp'
188
+            echo ''
189
+            echo 'override_dh_usrlocal:'
190
+            echo ''
191
+            echo '	@true'
192
+            ;;
193
+
194
+        packaging/debian/source/format)
195
+            echo '3.0 (quilt)'
196
+            ;;
197
+
198
+        packaging/debian/*.install)
199
+            echo MKIT_NEWSTUB_FILELIST
200
+            ;;
201
+
202
+        src/*.skel)
203
+            echo 'echo "my version is: __MKIT_PROJ_VERSION__"'
204
+            echo 'echo "And that'"'"'s all, folks!"'
205
+            ;;
206
+
207
+        LICENSE.md)
208
+            local url   # license URL
209
+            url="${MKIT_INIT_LICENSES[$License]}"
210
+            curl -sf "$url" \
211
+             || die "failed to download license: $url"
212
+            ;;
213
+
214
+        .mkit/autoclean)
215
+            ;;
216
+
217
+        MKIT_NEWSTUB_README.md)
218
+            echo "FINISHING MKIT CONFIGURATION"
219
+            echo "============================"
220
+            echo ""
221
+            echo "Congratulations, your new project has been configured!"
222
+            echo ""
223
+            echo "However, the *newstub* script is not able to figure out"
224
+            echo "everything, so few things still need to be done manually."
225
+            echo "This document will guide you throught the rest of the"
226
+            echo "process."
227
+
228
+            echo ""
229
+            echo ""
230
+            echo "Structure"
231
+            echo "---------"
232
+            echo ""
233
+            echo "First, let's go through the directory structure:"
234
+            echo ""
235
+            echo " *  *src* directory - here is your main place to store"
236
+            echo "    source files.  This includes also documents like user"
237
+            echo "    manuals---IOW, anything intended to end up on user's"
238
+            echo "    machine should be uder 'src'."
239
+            echo ""
240
+            echo "    Note that during build time, files named ending with"
241
+            echo "    '.skel' are subject to token expansion, see mkit.ini"
242
+            echo "    section below for details."
243
+            echo ""
244
+            echo " *  *notes* directory - here you shall store notes"
245
+            echo "    intended for people contributing to your project,"
246
+            echo "    for instance, guidelines, coding style documents,"
247
+            echo "    TODOs, ideas, plans..."
248
+            echo ""
249
+            echo " *  *utils* directory - here you shall store utilities"
250
+            echo "    and scripts that will help you with project maintenance,"
251
+            echo "    and that, unlike software like compilers or versioning"
252
+            echo "    systems, can (and should) be embedded inside the"
253
+            echo "    repository."
254
+            echo ""
255
+            echo "    MKit itself is one nice example. :)"
256
+
257
+            if $MkPackaging; then
258
+            echo ""
259
+            echo " *  *packaging* directory contains templates that enable"
260
+            echo "    MKit create raw stuffs used to create DEB or RPM"
261
+            echo "    packages.  Similar to '.skel' files in 'src', all files"
262
+            echo "    here are automatically considered for token expansion,"
263
+            echo "    no matter how they are named (see mkit.ini section"
264
+            echo "    below)."
265
+            echo ""
266
+            echo "    NOTE: these templates, as well as any packages created by"
267
+            echo "    them are intended only for experimental, private use and"
268
+            echo "    testing."
269
+            echo ""
270
+            echo "    Should you have ambition to create 'real' packages for"
271
+            echo "    OS distribution such as Debian or Fedora (what a great"
272
+            echo "    idea!), be prepared that you will need to follow their"
273
+            echo "    guidelines.  This will most probably mean huge changes"
274
+            echo "    to these packages or even changes to your workflow."
275
+
276
+            echo ""
277
+            echo ""
278
+            echo "Placeholders"
279
+            echo "------------"
280
+            echo ""
281
+            echo "At places where *newstub* script did not have way to get all"
282
+            echo "information automatically, it has inserted placeholders."
283
+            echo "You will need to go through all of these placeholders and"
284
+            echo "replace them with proper data."
285
+            echo ""
286
+            echo "Please follow instructions:"
287
+            echo ""
288
+            echo " 1. Look for placeholders starting with \`MKIT_NEWSTUB_\`"
289
+            echo "    prefix by calling this command:"
290
+            echo ""
291
+            echo "        grep -lw MKIT_NEWSTUB_ -r"
292
+            echo ""
293
+            echo " 2. Go through each file and locate the placeholder.  (You"
294
+            echo "    will also see placeholders like \`__MKIT_*__\`, you can"
295
+            echo "    ignore those."
296
+            echo ""
297
+            echo " 3. Replace placeholder with appropriate information:"
298
+            echo ""
299
+            echo "     *  \`MKIT_NEWSTUB_REQUIRES\` - Requirements of your"
300
+            echo "        project."
301
+            echo ""
302
+            echo "     *  \`MKIT_NEWSTUB_DESCRIPTION\` - Description of your"
303
+            echo "        project (few sentences to paragraphs)."
304
+            echo ""
305
+            echo "     *  \`MKIT_NEWSTUB_FILELIST\` - List of full paths to"
306
+            echo "        your files after installation."
307
+            echo ""
308
+            echo "    Refer to these documents for further details:"
309
+            echo ""
310
+            echo "        http://rpm-guide.readthedocs.io/"
311
+            echo "        https://www.debian.org/doc/manuals/maint-guide/"
312
+            fi
313
+
314
+            echo ""
315
+            echo ""
316
+            echo "mkit.ini"
317
+            echo "--------"
318
+            echo ""
319
+            echo "Most sections still need to be reviewed. In order to do"
320
+            echo "that, you will need to understand how MKit works:"
321
+            echo ""
322
+            echo " 1. First, you need to define *roles* your files will play"
323
+            echo "    when they are installed on user's file systems.  These"
324
+            echo "    roles then imply where and how the files should be"
325
+            echo "    deployed."
326
+            echo ""
327
+            echo "    Typical example of a role is e.g. 'bin' for commands"
328
+            echo "    (normally under '/usr/bin' or '/usr/local/bin'), 'doc'"
329
+            echo "    for documents or 'lib' for libraries."
330
+
331
+            echo ""
332
+            echo " 2. Next, in \`[roots]\` section, you have to set target"
333
+            echo "    root directory for each role.  However, in order to"
334
+            echo "    enable people to implement local conventions, it is"
335
+            echo "    considered a good manner to also respect PREFIX"
336
+            echo "    environment variable.  For this reason, most paths"
337
+            echo "    need to start with \`[ENV:PREFIX]\`."
338
+            echo ""
339
+
340
+            echo " 3. \`[files]\` section is where you assign actual files"
341
+            echo "    from your repository to their final paths.  The format"
342
+            echo "    is \`ROLE = REPOPATH [RENAMED]\`, where ROLE is file's"
343
+            echo "    role, REPOPATH is relative path to the file."
344
+            echo ""
345
+            echo "    Final path is then composed by taking path assigned to"
346
+            echo "    ROLE and appending file's name.  However, if you need"
347
+            echo "    the deployed file to have different name than in the"
348
+            echo "    codebase, you can specify the other name as RENAMED."
349
+            echo ""
350
+            echo "    Note that you don't need to address every single file"
351
+            echo "    individually, if in your repo you have a directory with"
352
+            echo "    100 files of the same role, you can add just path to the"
353
+            echo "    directory itself."
354
+
355
+            echo ""
356
+            echo " 4. If some roles require special permissions on your files,"
357
+            echo "    \`[modes]\` section is your friend.  Permissions here"
358
+            echo "    should be in UNIX octal format."
359
+
360
+            echo ""
361
+            echo " 5. Next, \`[tokens]\` section allows you to define own"
362
+            echo "    placeholders that will be replaced when your scripts are"
363
+            echo "    built.  Each file in 'src' directory that is named with"
364
+            echo "    '.skel' suffix, and each file from 'packaging' directory"
365
+            echo "    (no matter its name), can contain one or more of tokens"
366
+            echo "    defined here, plus range of tokens automatically defined"
367
+            echo "    by MKit.  During build, these tokens are replaced with"
368
+            echo "    their actual values."
369
+
370
+            echo ""
371
+            echo " 6. Less interesting, but important section is \`[dist]\`,"
372
+            echo "    which lists files in your codebase that will be added"
373
+            echo "    to distribution tarball (part of \"stuffs\" mentioned"
374
+            echo "    above).  Listing directory here will include all its"
375
+            echo "    contents, and normally it's OK to be very inclusive, so"
376
+            echo "    most of the time this section should be OK."
377
+
378
+            echo ""
379
+            echo " 7. Even less interesting is section \`[ENV]\`.  It is"
380
+            echo "    special in that it provides *default* value for an"
381
+            echo "    environment variable.  You almost never need to touch"
382
+            echo "    this."
383
+            echo ""
384
+
385
+            echo " 8. Finally, the most interesting section!  \`[project]\`,"
386
+            echo "    provides most general information for your project such"
387
+            echo "    as name and version."
388
+            echo ""
389
+            echo "    Note that the \`version\` key is another \"special"
390
+            echo "    snowflake\" -- it is now set to 0.0.0, and you **should"
391
+            echo "    not need** to change  it manually.  When you feel you"
392
+            echo "    a are ready to release next version of your evolving"
393
+            echo "    project, simply call \`make vbump\` and MKit will take"
394
+            echo "    care of everything!"
395
+
396
+            if $MkMakefile; then
397
+            echo ""
398
+            echo ""
399
+            echo "Makefile"
400
+            echo "--------"
401
+            echo ""
402
+            echo "*newstub* script also created a Makefile for you, but all"
403
+            echo "it really does is include MKit's own mkit.mk, which in turn"
404
+            echo "only maps \`make\` targets to actual mkit script calls."
405
+            echo "Unless your project already uses GNU Make, you should not"
406
+            echo "need to change this file."
407
+            fi
408
+
409
+            if $MkReadme; then
410
+            echo ""
411
+            echo ""
412
+            echo "README.md"
413
+            echo "---------"
414
+            echo ""
415
+            echo "Each serious project needs a serious README.  Which is why"
416
+            echo "*newstub* has created a 'stub' of one for you."
417
+            fi
418
+
419
+            echo ""
420
+            echo ""
421
+            echo "The final touch"
422
+            echo "---------------"
423
+            echo ""
424
+            echo "Once you have reviewed everything, just delete this file!"
425
+            ;;
426
+
427
+    esac >"$file"
428
+}
429
+
430
+known_licenses() {
431
+    local key
432
+    local first=true
433
+    for key in "${!MKIT_INIT_LICENSES[@]}"; do
434
+        $first && echo "$key"  && continue
435
+        echo ", $key"
436
+    done
437
+}
438
+
439
+usage() {
440
+    {
441
+        echo "Usage:"
442
+        echo "   newstub [options] NAME"
443
+        echo "   newstub -L"
444
+        echo ""
445
+        echo "Options:"
446
+        echo ""
447
+        echo "    -c CODENAME   your project codename"
448
+        echo "    -t TAGLINE    your project tagline"
449
+        echo "    -b RELSRC     pre-release branch"
450
+        echo "    -B RELDST     post-release branch"
451
+        echo "    -n NICENAME   your project's 'nice' name"
452
+        echo "    -l LICENSE    your options's license (see -L)"
453
+        echo "    -m MAINT      project maintainer's name and e-mail"
454
+        echo "    -v URL        URL to public code browser"
455
+        echo "    -a            enable autoclean ('make clean' after"
456
+        echo "                  each 'make install')"
457
+        echo "    -g            make git commits before and adter"
458
+        echo "                  (implies -y)"
459
+        echo "    -y            don't ask, just do it"
460
+        echo "    -R            skip creating README.md"
461
+        echo "    -M            skip creating Makefile"
462
+        echo "    -P            skip creating packaging templates"
463
+        echo "    -L            list know licenses and exit"
464
+        echo ""
465
+        echo "NAME should be packaging-friendly name, ie. consist"
466
+        echo "only of small letters, numbers, underscore and dash."
467
+        echo "For your 'real' name, use NICENAME, which can be any"
468
+        echo "string."
469
+    } >&2
470
+    exit 2
471
+}
472
+
473
+confirm() {
474
+    local response      # user's response to our warning
475
+    $Force && return 0
476
+    {
477
+        echo "Warning: This operation can be destructive for your"
478
+        echo "current codebase.  At least following files will be"
479
+        echo "created or overwritten:"
480
+        echo ""
481
+        $MkPackaging        && echo " *  'packaging' directory (pass -P to avoid)"
482
+        $MkMakefile         && echo " *  'Makefile' (pass -M to avoid)"
483
+        $MkReadme           && echo " *  'README.md' (pass -R to avoid)"
484
+        test -n "$License"  && echo " *  'LICENSE.md' (omit -l to avoid)"
485
+        echo " *  'mkit.ini'"
486
+        echo ""
487
+        read -p "Type 'yes' to proceed: " -r response
488
+    } >&2
489
+    test "$response" == "yes" && return 0
490
+    warn "Aborting."
491
+    return 1
492
+}
493
+
494
+mkcommit_backup() {
495
+    git ls-files --others \
496
+      | grep -qv -e '^utils/mkit$' -e '^utils/mkit/' \
497
+     || { warn "nothing to back up"; return 0; }
498
+    git add .                           || return
499
+    git rm -r --cached utils/mkit       || return
500
+    git commit -m "WIP [mkit/newstub] backup"   || return
501
+}
502
+
503
+mkcommit_mkit_code() {
504
+    git ls-files --others \
505
+      | grep -q -e '^utils/mkit$' -e '^utils/mkit/' \
506
+     || return 0
507
+    git add utils/mkit                                         || return
508
+    git commit -m "WIP [mkit/newstub] Add MKit version v$MKIT_VERSION" || return
509
+}
510
+
511
+mkcommit_mkit_conf() {
512
+    git add .                                                  || return
513
+    git commit -m "WIP [mkit/newstub] Add MKit configuration stub" || return
514
+}
515
+
516
+deploy_packaging() {
517
+    rm -rf packaging
518
+    deploy packaging/template.spec
519
+    deploy packaging/debian/copyright
520
+    deploy packaging/debian/control
521
+    deploy packaging/debian/changelog
522
+    deploy packaging/debian/compat
523
+    deploy packaging/debian/rules
524
+    deploy packaging/debian/source/format
525
+    deploy packaging/debian/"$PackageName".install
526
+    deploy packaging/template.spec
527
+}
528
+
529
+main() {
530
+    local NiceName          # human-readable project name
531
+    local PackageName       # machine-safe project (package) name
532
+    local RelSrc            # pre-release branch
533
+    local RelDst            # post-release branch
534
+    local Codename          # release codename
535
+    local Tagline           # project tagline
536
+    local Maintainer        # project maintainer (Name + e-mail)
537
+    local VcsBrowser        # VCS browser (eg. GitHub URL)
538
+    local AutoClean=false   # touch .mkit/autoclean?
539
+    local MkCommits=false   # create pre/post git commits?
540
+    local Force=false       # go without asking?
541
+    local MkReadme=true     # create README.md?
542
+    local MkMakefile=true   # create Makefile?
543
+    local MkPackaging=true  # create packaging templates?
544
+    while true; do case $1 in
545
+        -n) NiceName=$2;        shift 2 || usage ;;
546
+        -b) RelSrc=$2;          shift 2 || usage ;;
547
+        -B) RelDst=$2;          shift 2 || usage ;;
548
+        -c) Codename=$2;        shift 2 || usage ;;
549
+        -t) Tagline=$2;         shift 2 || usage ;;
550
+        -l) License=$2;         shift 2 || usage ;;
551
+        -m) Maintainer=$2;      shift 2 || usage ;;
552
+        -v) VcsBrowser=$2;      shift 2 || usage ;;
553
+        -M) MkMakefile=false;   shift ;;
554
+        -R) MkReadme=false;     shift ;;
555
+        -a) AutoClean=true;     shift ;;
556
+        -y) Force=true;         shift ;;
557
+        -g) MkCommits=true;     shift ;;
558
+        -P) MkPackaging=false;  shift ;;
559
+        -L) known_licenses | tr , '\n'; exit 0 ;;
560
+        -*) usage ;;
561
+        *)  break ;;
562
+    esac done
563
+    PackageName="$1"
564
+    test -n "$PackageName" || usage
565
+    if test -n "$License"; then
566
+        known_licenses | grep -qxF "$License" \
567
+         || die "unknown license (use -L to get list): $License"
568
+    fi
569
+    if $MkCommits; then
570
+        mkcommit_backup || die "failed creating backup commit"
571
+        Force=true
572
+    fi
573
+    confirm            || return 1
574
+    deploy mkit.ini
575
+    deploy src/"$PackageName".skel
576
+    $MkMakefile        && deploy Makefile
577
+    $MkReadme          && deploy README.md
578
+    test -n "$License" && deploy LICENSE.md
579
+    $AutoClean         && deploy .mkit/autoclean
580
+    $MkPackaging       && deploy_packaging
581
+    if $MkCommits; then
582
+        mkcommit_mkit_code || die "failed creating post-commit"
583
+        mkcommit_mkit_conf || die "failed creating post-commit"
584
+    fi
585
+    deploy MKIT_NEWSTUB_README.md
586
+    warn "Configuration stub built, follow instructions in"
587
+    warn "MKIT_NEWSTUB_README.md to finish configuration."
588
+    return 0
589
+}
590
+
591
+main "$@"