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