Browse Source

Initial commit

Alois Mahdal 6 years ago
commit
fbda5c726e
58 changed files with 5935 additions and 0 deletions
  1. 503
    0
      LICENSE.md
  2. 5
    0
      Makefile
  3. 4
    0
      README.md
  4. 75
    0
      mkit.ini
  5. 138
    0
      notes/SUITE.md
  6. 6
    0
      notes/TODO.md
  7. 5
    0
      packaging/debian/changelog
  8. 1
    0
      packaging/debian/compat
  9. 47
    0
      packaging/debian/control
  10. 1
    0
      packaging/debian/copyright
  11. 3
    0
      packaging/debian/jattool-report.install
  12. 20
    0
      packaging/debian/jattool-tdk.install
  13. 10
    0
      packaging/debian/jattool.install
  14. 9
    0
      packaging/debian/rules
  15. 1
    0
      packaging/debian/source/format
  16. 104
    0
      packaging/template.spec
  17. 34
    0
      src/app.skel
  18. 38
    0
      src/complete.bash.skel
  19. 0
    0
      src/help.skel
  20. 4
    0
      src/ini.d/main/jattool.ini
  21. 43
    0
      src/jinja2/html.j2
  22. 94
    0
      src/libexec/jattool-export.skel
  23. 69
    0
      src/libexec/jattool-qrun
  24. 95
    0
      src/libexec/jattool-runtest
  25. 44
    0
      src/libexec/jattool-sessid
  26. 104
    0
      src/libexec/jattool-sfind
  27. 58
    0
      src/libexec/jattool-tfind
  28. 258
    0
      src/python/jat.py
  29. 5
    0
      src/tdk/Makefile
  30. 24
    0
      src/tdk/mkit.ini.skel
  31. 5
    0
      src/tdk/packaging/debian/changelog
  32. 1
    0
      src/tdk/packaging/debian/compat
  33. 19
    0
      src/tdk/packaging/debian/control
  34. 1
    0
      src/tdk/packaging/debian/copyright
  35. 0
    0
      src/tdk/packaging/debian/install
  36. 9
    0
      src/tdk/packaging/debian/rules
  37. 1
    0
      src/tdk/packaging/debian/source/format
  38. 36
    0
      src/tdk/packaging/template.spec
  39. 290
    0
      src/tdk/utils/mkit/include/build.sh
  40. 130
    0
      src/tdk/utils/mkit/include/deploy.sh
  41. 175
    0
      src/tdk/utils/mkit/include/facts.sh
  42. 177
    0
      src/tdk/utils/mkit/include/ini.sh
  43. 162
    0
      src/tdk/utils/mkit/include/mkit.sh
  44. 232
    0
      src/tdk/utils/mkit/include/release.sh
  45. 61
    0
      src/tdk/utils/mkit/include/vars.sh
  46. 34
    0
      src/tdk/utils/mkit/make
  47. 56
    0
      src/tdk/utils/mkit/mkit.mk
  48. 715
    0
      src/tdk/utils/mkit/stub
  49. 286
    0
      utils/mkit/include/build.sh
  50. 130
    0
      utils/mkit/include/deploy.sh
  51. 175
    0
      utils/mkit/include/facts.sh
  52. 178
    0
      utils/mkit/include/ini.sh
  53. 162
    0
      utils/mkit/include/mkit.sh
  54. 232
    0
      utils/mkit/include/release.sh
  55. 61
    0
      utils/mkit/include/vars.sh
  56. 34
    0
      utils/mkit/make
  57. 56
    0
      utils/mkit/mkit.mk
  58. 715
    0
      utils/mkit/stub

+ 503
- 0
LICENSE.md View File

@@ -0,0 +1,503 @@
1
+### GNU LESSER GENERAL PUBLIC LICENSE
2
+
3
+Version 2.1, February 1999
4
+
5
+    Copyright (C) 1991, 1999 Free Software Foundation, Inc.
6
+    51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
7
+    
8
+    Everyone is permitted to copy and distribute verbatim copies
9
+    of this license document, but changing it is not allowed.
10
+
11
+    [This is the first released version of the Lesser GPL.  It also counts
12
+     as the successor of the GNU Library Public License, version 2, hence
13
+     the version number 2.1.]
14
+
15
+### Preamble
16
+
17
+The licenses for most software are designed to take away your freedom
18
+to share and change it. By contrast, the GNU General Public Licenses
19
+are intended to guarantee your freedom to share and change free
20
+software--to make sure the software is free for all its users.
21
+
22
+This license, the Lesser General Public License, applies to some
23
+specially designated software packages--typically libraries--of the
24
+Free Software Foundation and other authors who decide to use it. You
25
+can use it too, but we suggest you first think carefully about whether
26
+this license or the ordinary General Public License is the better
27
+strategy to use in any particular case, based on the explanations
28
+below.
29
+
30
+When we speak of free software, we are referring to freedom of use,
31
+not price. Our General Public Licenses are designed to make sure that
32
+you have the freedom to distribute copies of free software (and charge
33
+for this service if you wish); that you receive source code or can get
34
+it if you want it; that you can change the software and use pieces of
35
+it in new free programs; and that you are informed that you can do
36
+these things.
37
+
38
+To protect your rights, we need to make restrictions that forbid
39
+distributors to deny you these rights or to ask you to surrender these
40
+rights. These restrictions translate to certain responsibilities for
41
+you if you distribute copies of the library or if you modify it.
42
+
43
+For example, if you distribute copies of the library, whether gratis
44
+or for a fee, you must give the recipients all the rights that we gave
45
+you. You must make sure that they, too, receive or can get the source
46
+code. If you link other code with the library, you must provide
47
+complete object files to the recipients, so that they can relink them
48
+with the library after making changes to the library and recompiling
49
+it. And you must show them these terms so they know their rights.
50
+
51
+We protect your rights with a two-step method: (1) we copyright the
52
+library, and (2) we offer you this license, which gives you legal
53
+permission to copy, distribute and/or modify the library.
54
+
55
+To protect each distributor, we want to make it very clear that there
56
+is no warranty for the free library. Also, if the library is modified
57
+by someone else and passed on, the recipients should know that what
58
+they have is not the original version, so that the original author's
59
+reputation will not be affected by problems that might be introduced
60
+by others.
61
+
62
+Finally, software patents pose a constant threat to the existence of
63
+any free program. We wish to make sure that a company cannot
64
+effectively restrict the users of a free program by obtaining a
65
+restrictive license from a patent holder. Therefore, we insist that
66
+any patent license obtained for a version of the library must be
67
+consistent with the full freedom of use specified in this license.
68
+
69
+Most GNU software, including some libraries, is covered by the
70
+ordinary GNU General Public License. This license, the GNU Lesser
71
+General Public License, applies to certain designated libraries, and
72
+is quite different from the ordinary General Public License. We use
73
+this license for certain libraries in order to permit linking those
74
+libraries into non-free programs.
75
+
76
+When a program is linked with a library, whether statically or using a
77
+shared library, the combination of the two is legally speaking a
78
+combined work, a derivative of the original library. The ordinary
79
+General Public License therefore permits such linking only if the
80
+entire combination fits its criteria of freedom. The Lesser General
81
+Public License permits more lax criteria for linking other code with
82
+the library.
83
+
84
+We call this license the "Lesser" General Public License because it
85
+does Less to protect the user's freedom than the ordinary General
86
+Public License. It also provides other free software developers Less
87
+of an advantage over competing non-free programs. These disadvantages
88
+are the reason we use the ordinary General Public License for many
89
+libraries. However, the Lesser license provides advantages in certain
90
+special circumstances.
91
+
92
+For example, on rare occasions, there may be a special need to
93
+encourage the widest possible use of a certain library, so that it
94
+becomes a de-facto standard. To achieve this, non-free programs must
95
+be allowed to use the library. A more frequent case is that a free
96
+library does the same job as widely used non-free libraries. In this
97
+case, there is little to gain by limiting the free library to free
98
+software only, so we use the Lesser General Public License.
99
+
100
+In other cases, permission to use a particular library in non-free
101
+programs enables a greater number of people to use a large body of
102
+free software. For example, permission to use the GNU C Library in
103
+non-free programs enables many more people to use the whole GNU
104
+operating system, as well as its variant, the GNU/Linux operating
105
+system.
106
+
107
+Although the Lesser General Public License is Less protective of the
108
+users' freedom, it does ensure that the user of a program that is
109
+linked with the Library has the freedom and the wherewithal to run
110
+that program using a modified version of the Library.
111
+
112
+The precise terms and conditions for copying, distribution and
113
+modification follow. Pay close attention to the difference between a
114
+"work based on the library" and a "work that uses the library". The
115
+former contains code derived from the library, whereas the latter must
116
+be combined with the library in order to run.
117
+
118
+### TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
119
+
120
+**0.** This License Agreement applies to any software library or other
121
+program which contains a notice placed by the copyright holder or
122
+other authorized party saying it may be distributed under the terms of
123
+this Lesser General Public License (also called "this License"). Each
124
+licensee is addressed as "you".
125
+
126
+A "library" means a collection of software functions and/or data
127
+prepared so as to be conveniently linked with application programs
128
+(which use some of those functions and data) to form executables.
129
+
130
+The "Library", below, refers to any such software library or work
131
+which has been distributed under these terms. A "work based on the
132
+Library" means either the Library or any derivative work under
133
+copyright law: that is to say, a work containing the Library or a
134
+portion of it, either verbatim or with modifications and/or translated
135
+straightforwardly into another language. (Hereinafter, translation is
136
+included without limitation in the term "modification".)
137
+
138
+"Source code" for a work means the preferred form of the work for
139
+making modifications to it. For a library, complete source code means
140
+all the source code for all modules it contains, plus any associated
141
+interface definition files, plus the scripts used to control
142
+compilation and installation of the library.
143
+
144
+Activities other than copying, distribution and modification are not
145
+covered by this License; they are outside its scope. The act of
146
+running a program using the Library is not restricted, and output from
147
+such a program is covered only if its contents constitute a work based
148
+on the Library (independent of the use of the Library in a tool for
149
+writing it). Whether that is true depends on what the Library does and
150
+what the program that uses the Library does.
151
+
152
+**1.** You may copy and distribute verbatim copies of the Library's
153
+complete source code as you receive it, in any medium, provided that
154
+you conspicuously and appropriately publish on each copy an
155
+appropriate copyright notice and disclaimer of warranty; keep intact
156
+all the notices that refer to this License and to the absence of any
157
+warranty; and distribute a copy of this License along with the
158
+Library.
159
+
160
+You may charge a fee for the physical act of transferring a copy, and
161
+you may at your option offer warranty protection in exchange for a
162
+fee.
163
+
164
+**2.** You may modify your copy or copies of the Library or any
165
+portion of it, thus forming a work based on the Library, and copy and
166
+distribute such modifications or work under the terms of Section 1
167
+above, provided that you also meet all of these conditions:
168
+
169
+-   **a)** The modified work must itself be a software library.
170
+-   **b)** You must cause the files modified to carry prominent
171
+    notices stating that you changed the files and the date of
172
+    any change.
173
+-   **c)** You must cause the whole of the work to be licensed at no
174
+    charge to all third parties under the terms of this License.
175
+-   **d)** If a facility in the modified Library refers to a function
176
+    or a table of data to be supplied by an application program that
177
+    uses the facility, other than as an argument passed when the
178
+    facility is invoked, then you must make a good faith effort to
179
+    ensure that, in the event an application does not supply such
180
+    function or table, the facility still operates, and performs
181
+    whatever part of its purpose remains meaningful.
182
+
183
+    (For example, a function in a library to compute square roots has
184
+    a purpose that is entirely well-defined independent of
185
+    the application. Therefore, Subsection 2d requires that any
186
+    application-supplied function or table used by this function must
187
+    be optional: if the application does not supply it, the square
188
+    root function must still compute square roots.)
189
+
190
+These requirements apply to the modified work as a whole. If
191
+identifiable sections of that work are not derived from the Library,
192
+and can be reasonably considered independent and separate works in
193
+themselves, then this License, and its terms, do not apply to those
194
+sections when you distribute them as separate works. But when you
195
+distribute the same sections as part of a whole which is a work based
196
+on the Library, the distribution of the whole must be on the terms of
197
+this License, whose permissions for other licensees extend to the
198
+entire whole, and thus to each and every part regardless of who wrote
199
+it.
200
+
201
+Thus, it is not the intent of this section to claim rights or contest
202
+your rights to work written entirely by you; rather, the intent is to
203
+exercise the right to control the distribution of derivative or
204
+collective works based on the Library.
205
+
206
+In addition, mere aggregation of another work not based on the Library
207
+with the Library (or with a work based on the Library) on a volume of
208
+a storage or distribution medium does not bring the other work under
209
+the scope of this License.
210
+
211
+**3.** You may opt to apply the terms of the ordinary GNU General
212
+Public License instead of this License to a given copy of the Library.
213
+To do this, you must alter all the notices that refer to this License,
214
+so that they refer to the ordinary GNU General Public License, version
215
+2, instead of to this License. (If a newer version than version 2 of
216
+the ordinary GNU General Public License has appeared, then you can
217
+specify that version instead if you wish.) Do not make any other
218
+change in these notices.
219
+
220
+Once this change is made in a given copy, it is irreversible for that
221
+copy, so the ordinary GNU General Public License applies to all
222
+subsequent copies and derivative works made from that copy.
223
+
224
+This option is useful when you wish to copy part of the code of the
225
+Library into a program that is not a library.
226
+
227
+**4.** You may copy and distribute the Library (or a portion or
228
+derivative of it, under Section 2) in object code or executable form
229
+under the terms of Sections 1 and 2 above provided that you accompany
230
+it with the complete corresponding machine-readable source code, which
231
+must be distributed under the terms of Sections 1 and 2 above on a
232
+medium customarily used for software interchange.
233
+
234
+If distribution of object code is made by offering access to copy from
235
+a designated place, then offering equivalent access to copy the source
236
+code from the same place satisfies the requirement to distribute the
237
+source code, even though third parties are not compelled to copy the
238
+source along with the object code.
239
+
240
+**5.** A program that contains no derivative of any portion of the
241
+Library, but is designed to work with the Library by being compiled or
242
+linked with it, is called a "work that uses the Library". Such a work,
243
+in isolation, is not a derivative work of the Library, and therefore
244
+falls outside the scope of this License.
245
+
246
+However, linking a "work that uses the Library" with the Library
247
+creates an executable that is a derivative of the Library (because it
248
+contains portions of the Library), rather than a "work that uses the
249
+library". The executable is therefore covered by this License. Section
250
+6 states terms for distribution of such executables.
251
+
252
+When a "work that uses the Library" uses material from a header file
253
+that is part of the Library, the object code for the work may be a
254
+derivative work of the Library even though the source code is not.
255
+Whether this is true is especially significant if the work can be
256
+linked without the Library, or if the work is itself a library. The
257
+threshold for this to be true is not precisely defined by law.
258
+
259
+If such an object file uses only numerical parameters, data structure
260
+layouts and accessors, and small macros and small inline functions
261
+(ten lines or less in length), then the use of the object file is
262
+unrestricted, regardless of whether it is legally a derivative work.
263
+(Executables containing this object code plus portions of the Library
264
+will still fall under Section 6.)
265
+
266
+Otherwise, if the work is a derivative of the Library, you may
267
+distribute the object code for the work under the terms of Section 6.
268
+Any executables containing that work also fall under Section 6,
269
+whether or not they are linked directly with the Library itself.
270
+
271
+**6.** As an exception to the Sections above, you may also combine or
272
+link a "work that uses the Library" with the Library to produce a work
273
+containing portions of the Library, and distribute that work under
274
+terms of your choice, provided that the terms permit modification of
275
+the work for the customer's own use and reverse engineering for
276
+debugging such modifications.
277
+
278
+You must give prominent notice with each copy of the work that the
279
+Library is used in it and that the Library and its use are covered by
280
+this License. You must supply a copy of this License. If the work
281
+during execution displays copyright notices, you must include the
282
+copyright notice for the Library among them, as well as a reference
283
+directing the user to the copy of this License. Also, you must do one
284
+of these things:
285
+
286
+-   **a)** Accompany the work with the complete corresponding
287
+    machine-readable source code for the Library including whatever
288
+    changes were used in the work (which must be distributed under
289
+    Sections 1 and 2 above); and, if the work is an executable linked
290
+    with the Library, with the complete machine-readable "work that
291
+    uses the Library", as object code and/or source code, so that the
292
+    user can modify the Library and then relink to produce a modified
293
+    executable containing the modified Library. (It is understood that
294
+    the user who changes the contents of definitions files in the
295
+    Library will not necessarily be able to recompile the application
296
+    to use the modified definitions.)
297
+-   **b)** Use a suitable shared library mechanism for linking with
298
+    the Library. A suitable mechanism is one that (1) uses at run time
299
+    a copy of the library already present on the user's computer
300
+    system, rather than copying library functions into the executable,
301
+    and (2) will operate properly with a modified version of the
302
+    library, if the user installs one, as long as the modified version
303
+    is interface-compatible with the version that the work was
304
+    made with.
305
+-   **c)** Accompany the work with a written offer, valid for at least
306
+    three years, to give the same user the materials specified in
307
+    Subsection 6a, above, for a charge no more than the cost of
308
+    performing this distribution.
309
+-   **d)** If distribution of the work is made by offering access to
310
+    copy from a designated place, offer equivalent access to copy the
311
+    above specified materials from the same place.
312
+-   **e)** Verify that the user has already received a copy of these
313
+    materials or that you have already sent this user a copy.
314
+
315
+For an executable, the required form of the "work that uses the
316
+Library" must include any data and utility programs needed for
317
+reproducing the executable from it. However, as a special exception,
318
+the materials to be distributed need not include anything that is
319
+normally distributed (in either source or binary form) with the major
320
+components (compiler, kernel, and so on) of the operating system on
321
+which the executable runs, unless that component itself accompanies
322
+the executable.
323
+
324
+It may happen that this requirement contradicts the license
325
+restrictions of other proprietary libraries that do not normally
326
+accompany the operating system. Such a contradiction means you cannot
327
+use both them and the Library together in an executable that you
328
+distribute.
329
+
330
+**7.** You may place library facilities that are a work based on the
331
+Library side-by-side in a single library together with other library
332
+facilities not covered by this License, and distribute such a combined
333
+library, provided that the separate distribution of the work based on
334
+the Library and of the other library facilities is otherwise
335
+permitted, and provided that you do these two things:
336
+
337
+-   **a)** Accompany the combined library with a copy of the same work
338
+    based on the Library, uncombined with any other
339
+    library facilities. This must be distributed under the terms of
340
+    the Sections above.
341
+-   **b)** Give prominent notice with the combined library of the fact
342
+    that part of it is a work based on the Library, and explaining
343
+    where to find the accompanying uncombined form of the same work.
344
+
345
+**8.** You may not copy, modify, sublicense, link with, or distribute
346
+the Library except as expressly provided under this License. Any
347
+attempt otherwise to copy, modify, sublicense, link with, or
348
+distribute the Library is void, and will automatically terminate your
349
+rights under this License. However, parties who have received copies,
350
+or rights, from you under this License will not have their licenses
351
+terminated so long as such parties remain in full compliance.
352
+
353
+**9.** You are not required to accept this License, since you have not
354
+signed it. However, nothing else grants you permission to modify or
355
+distribute the Library or its derivative works. These actions are
356
+prohibited by law if you do not accept this License. Therefore, by
357
+modifying or distributing the Library (or any work based on the
358
+Library), you indicate your acceptance of this License to do so, and
359
+all its terms and conditions for copying, distributing or modifying
360
+the Library or works based on it.
361
+
362
+**10.** Each time you redistribute the Library (or any work based on
363
+the Library), the recipient automatically receives a license from the
364
+original licensor to copy, distribute, link with or modify the Library
365
+subject to these terms and conditions. You may not impose any further
366
+restrictions on the recipients' exercise of the rights granted herein.
367
+You are not responsible for enforcing compliance by third parties with
368
+this License.
369
+
370
+**11.** If, as a consequence of a court judgment or allegation of
371
+patent infringement or for any other reason (not limited to patent
372
+issues), conditions are imposed on you (whether by court order,
373
+agreement or otherwise) that contradict the conditions of this
374
+License, they do not excuse you from the conditions of this License.
375
+If you cannot distribute so as to satisfy simultaneously your
376
+obligations under this License and any other pertinent obligations,
377
+then as a consequence you may not distribute the Library at all. For
378
+example, if a patent license would not permit royalty-free
379
+redistribution of the Library by all those who receive copies directly
380
+or indirectly through you, then the only way you could satisfy both it
381
+and this License would be to refrain entirely from distribution of the
382
+Library.
383
+
384
+If any portion of this section is held invalid or unenforceable under
385
+any particular circumstance, the balance of the section is intended to
386
+apply, and the section as a whole is intended to apply in other
387
+circumstances.
388
+
389
+It is not the purpose of this section to induce you to infringe any
390
+patents or other property right claims or to contest validity of any
391
+such claims; this section has the sole purpose of protecting the
392
+integrity of the free software distribution system which is
393
+implemented by public license practices. Many people have made
394
+generous contributions to the wide range of software distributed
395
+through that system in reliance on consistent application of that
396
+system; it is up to the author/donor to decide if he or she is willing
397
+to distribute software through any other system and a licensee cannot
398
+impose that choice.
399
+
400
+This section is intended to make thoroughly clear what is believed to
401
+be a consequence of the rest of this License.
402
+
403
+**12.** If the distribution and/or use of the Library is restricted in
404
+certain countries either by patents or by copyrighted interfaces, the
405
+original copyright holder who places the Library under this License
406
+may add an explicit geographical distribution limitation excluding
407
+those countries, so that distribution is permitted only in or among
408
+countries not thus excluded. In such case, this License incorporates
409
+the limitation as if written in the body of this License.
410
+
411
+**13.** The Free Software Foundation may publish revised and/or new
412
+versions of the Lesser General Public License from time to time. Such
413
+new versions will be similar in spirit to the present version, but may
414
+differ in detail to address new problems or concerns.
415
+
416
+Each version is given a distinguishing version number. If the Library
417
+specifies a version number of this License which applies to it and
418
+"any later version", you have the option of following the terms and
419
+conditions either of that version or of any later version published by
420
+the Free Software Foundation. If the Library does not specify a
421
+license version number, you may choose any version ever published by
422
+the Free Software Foundation.
423
+
424
+**14.** If you wish to incorporate parts of the Library into other
425
+free programs whose distribution conditions are incompatible with
426
+these, write to the author to ask for permission. For software which
427
+is copyrighted by the Free Software Foundation, write to the Free
428
+Software Foundation; we sometimes make exceptions for this. Our
429
+decision will be guided by the two goals of preserving the free status
430
+of all derivatives of our free software and of promoting the sharing
431
+and reuse of software generally.
432
+
433
+**NO WARRANTY**
434
+
435
+**15.** BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO
436
+WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
437
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
438
+OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY
439
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
440
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
441
+PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
442
+LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME
443
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
444
+
445
+**16.** IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
446
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
447
+AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU
448
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
449
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
450
+LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
451
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
452
+FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF
453
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
454
+DAMAGES.
455
+
456
+### END OF TERMS AND CONDITIONS
457
+
458
+### How to Apply These Terms to Your New Libraries
459
+
460
+If you develop a new library, and you want it to be of the greatest
461
+possible use to the public, we recommend making it free software that
462
+everyone can redistribute and change. You can do so by permitting
463
+redistribution under these terms (or, alternatively, under the terms
464
+of the ordinary General Public License).
465
+
466
+To apply these terms, attach the following notices to the library. It
467
+is safest to attach them to the start of each source file to most
468
+effectively convey the exclusion of warranty; and each file should
469
+have at least the "copyright" line and a pointer to where the full
470
+notice is found.
471
+
472
+    one line to give the library's name and an idea of what it does.
473
+    Copyright (C) year  name of author
474
+
475
+    This library is free software; you can redistribute it and/or
476
+    modify it under the terms of the GNU Lesser General Public
477
+    License as published by the Free Software Foundation; either
478
+    version 2.1 of the License, or (at your option) any later version.
479
+
480
+    This library is distributed in the hope that it will be useful,
481
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
482
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
483
+    Lesser General Public License for more details.
484
+
485
+    You should have received a copy of the GNU Lesser General Public
486
+    License along with this library; if not, write to the Free Software
487
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
488
+
489
+Also add information on how to contact you by electronic and paper
490
+mail.
491
+
492
+You should also get your employer (if you work as a programmer) or
493
+your school, if any, to sign a "copyright disclaimer" for the library,
494
+if necessary. Here is a sample; alter the names:
495
+
496
+    Yoyodyne, Inc., hereby disclaims all copyright interest in
497
+    the library `Frob' (a library for tweaking knobs) written
498
+    by James Random Hacker.
499
+
500
+    signature of Ty Coon, 1 April 1990
501
+    Ty Coon, President of Vice
502
+
503
+That's all there is to it!

+ 5
- 0
Makefile View File

@@ -0,0 +1,5 @@
1
+# asrt - Shell-level testing framework
2
+# See LICENSE.md file for copyright and license details.
3
+
4
+MKIT_DIR=utils/mkit
5
+include $(MKIT_DIR)/mkit.mk

+ 4
- 0
README.md View File

@@ -0,0 +1,4 @@
1
+JATTOOL
2
+=======
3
+
4
+Shell-level testing framework

+ 75
- 0
mkit.ini View File

@@ -0,0 +1,75 @@
1
+[project]
2
+    version     = 0.0.0
3
+    name        = jattool
4
+    tagline     = Tool and related code for JAT testing framework
5
+    pkgname     = jattool
6
+    maintainer  = Alois Mahdal <netvor+jattool@vornet.cz>
7
+    vcs_browser = https://github.com/AloisMahdal/jattool
8
+    relsrc      = master
9
+    reldst      = last
10
+
11
+[dist]
12
+    tarball  = LICENSE.md
13
+    tarball  = Makefile
14
+    tarball  = README.md
15
+    tarball  = mkit.ini
16
+    tarball  = packaging
17
+    tarball  = src
18
+    tarball  = utils
19
+    rpmstuff = packaging/template.spec
20
+    debstuff = packaging/debian
21
+
22
+[ENV]
23
+    PREFIX          = /usr/local
24
+    XDG_DATA_HOME   = $HOME/.local/share
25
+    XDG_CACHE_HOME  = $HOME/.cache
26
+    XDG_CONFIG_HOME = $HOME/.config
27
+
28
+[roots]
29
+    bin     = [ENV:PREFIX]/bin
30
+    libexec = [ENV:PREFIX]/libexec/jattool
31
+    share   = [ENV:PREFIX]/share/jattool
32
+    doc     = [ENV:PREFIX]/share/doc/jattool
33
+    etc     = /etc/jattool
34
+    etc_bc  = /etc/bash_completion.d
35
+    sfincb  = [ENV:PREFIX]/share/shellfu/include-bash
36
+    tdkskel = [ENV:PREFIX]/share/jattool/tdk/skel
37
+    tdkutil = [ENV:PREFIX]/share/jattool/tdk/utils
38
+
39
+[macros]
40
+    __SATURNIN_DATA_HOME__    = [ENV:XDG_DATA_HOME]/jattool
41
+    __SATURNIN_CACHE_HOME__   = [ENV:XDG_CACHE_HOME]/jattool
42
+    __SATURNIN_CONFIG_HOME__  = [ENV:XDG_CONFIG_HOME]/jattool
43
+    __SATURNIN_CONFIG_LOCAL__ = [roots:etc]
44
+    __SATURNIN_LIBEXEC__      = [roots:libexec]
45
+    __SATURNIN_SHARE__        = [roots:share]
46
+    __JATTOOL_TEMPLATES__     = [roots:share]/jinja2
47
+    __JATTOOL_PYTHONPATH__    = [roots:share]/python
48
+    __JATTOOL_TDK_SKEL__      = [roots:tdkskel]
49
+
50
+[modes]
51
+    bin     = 755
52
+    libexec = 755
53
+    tdkutil = SRC
54
+
55
+[files]
56
+    bin     = src/app                        jattool
57
+    doc     = README.md
58
+    etc_bc  = src/complete.bash              jattool.bash
59
+    libexec = src/libexec/jattool-export
60
+    libexec = src/libexec/jattool-qrun
61
+    libexec = src/libexec/jattool-runtest
62
+    libexec = src/libexec/jattool-sessid
63
+    libexec = src/libexec/jattool-sfind
64
+    libexec = src/libexec/jattool-tfind
65
+    sfincb  = src/shellfu/jattool.sh
66
+    share   = src/help
67
+    share   = src/ini.d
68
+    share   = src/jinja2
69
+    share   = src/python
70
+    tdkskel = src/tdk/Makefile
71
+    tdkskel = src/tdk/packaging
72
+    tdkskel = src/tdk/mkit.ini
73
+    tdkutil = src/tdk/utils/mkit
74
+
75
+#mkit version=0.0.31

+ 138
- 0
notes/SUITE.md View File

@@ -0,0 +1,138 @@
1
+JATS - JAT-based test suite
2
+===========================
3
+
4
+Version
5
+-------
6
+
7
+v0.0 -- proof-of-concept phase
8
+
9
+**Disclaimer:** Version number of this specification starts with zero, which
10
+signifies *proof-of-concept phase*; many aspects including the basic ones
11
+**WILL CHANGE**.
12
+
13
+
14
+Suite
15
+-----
16
+
17
+JATS test suite consists of one or more JAT-based tests.  Each test is
18
+a directory, containing:
19
+
20
+    test
21
+    meta.yml
22
+
23
+*test* is main body of the test.  *meta.yml* is a YAML file containing
24
+test meta-data such as human-readable description, dependencies and
25
+coverage information.
26
+
27
+
28
+### Root directory ###
29
+
30
+Root directory of a test suite is designated by placement of file *format*
31
+in sub-directory *.jats*.  This file MUST contain version number in `X.Y`
32
+format, where X is major format version and `Y` is minor format version.
33
+
34
+A tool declaring support for JATS test suite MUST recognize one or more
35
+compatible format versions and refuse to work with suite if no supported
36
+versions match suite version.
37
+
38
+
39
+### Suite meta-data ###
40
+
41
+Test suite meta-data is stored under *.jats* directory under respective
42
+filename:
43
+
44
+
45
+ *  *domain* - Domain under which test suite exists.  A public JATS test suite
46
+    SHOULD refer to a valid domain name owned by test suite owner.
47
+
48
+    Default value is `jats.example.org`.
49
+
50
+ *  *ns* - Namespace under which rules for test organization are defined.
51
+    MUST consist of valid Path as defined in [RFC 3986][rfc3986path].
52
+
53
+    Usually this contains hierarchical elements such as work group name and
54
+    project name.
55
+
56
+    Default value is `anonns`.
57
+
58
+ *  *sut_pname* -  Plain name (or "package name") of System Under Test. MUST
59
+    consist of lowercase ASCII letters and dashes.  MUST NOT start with dash.
60
+
61
+    Default value is `anonsut`.
62
+
63
+ *  *sut_url* - Valid HTTP(s) URL leading to more information about System Under
64
+    Test.   Default value is `https://example.org/anonsut`,
65
+
66
+ *  *url* - Valid HTTP(s) URL leading to more information about Test Suite
67
+    itself.  Default value is composed in following way:
68
+
69
+        https://<DOMAIN>/<NS>
70
+
71
+    where `<DOMAIN>` and `<NS>` are contents of files *domain* and *ns* as above,
72
+    respectively.
73
+
74
+  [rfc3986path]: https://tools.ietf.org/html/rfc3986#section-3.3
75
+
76
+
77
+
78
+Test
79
+----
80
+
81
+By default, the format of the test is a source-able Bash code using
82
+*shellfu-bash-jat* library.  A trivial example of *test* code could
83
+be:
84
+
85
+    jat__pstartt "example test phase"
86
+        jat__cmd -h "true is still true" \
87
+            true
88
+        jat__cmp -h "five is still greater than three" \
89
+            5 gt 3
90
+        jat__cmp -h "foo still contains oo" \
91
+            foo re oo
92
+    jat__pend
93
+
94
+
95
+Meta-data and test properties
96
+-----------------------------
97
+
98
+Properties of a test are inferred from directory structure and complemented
99
+by test meta-data.  Following test properties are defined:
100
+
101
+
102
+### Test id ###
103
+
104
+Test id is determined from available data and has format of:
105
+
106
+    jats://<DOMAIN>/<NS>/<SUT_PNAME>/<PATH>
107
+
108
+where:
109
+
110
+ *  `jats://` is a constant pseudo-protocol string,
111
+
112
+ *  `<DOMAIN>`, `<NS>`, and `<SUT_PNAME>` are contents of respective
113
+    files from *.jats* meta-data directory,
114
+
115
+ *  and `<PATH>` is path of test directory relative to suite root directory.
116
+
117
+For example, following tree:
118
+
119
+    foosuite
120
+      +-- .jats
121
+      |       +-- domain        # contaning "my.example.org"
122
+      |       +-- ns            # contaning "myns"
123
+      |       +-- sut_pname     # contaning "mysut"
124
+      |       +-- version
125
+      +-- foo
126
+      |     +-- test
127
+      +-- bar
128
+           +-- baz-simple
129
+           |     +-- test
130
+           +-- baz-advanced
131
+                 +-- test
132
+
133
+contains following tests:
134
+
135
+    jats://my.example.org/myns/mysut/foo
136
+    jats://my.example.org/myns/mysut/bar/baz-simple
137
+    jats://my.example.org/myns/mysut/bar/baz-advanced
138
+

+ 6
- 0
notes/TODO.md View File

@@ -0,0 +1,6 @@
1
+TODO
2
+====
3
+
4
+ *  add .j2 for HTML/text/whatever (separate module?)
5
+
6
+ *  fortify against running from within test

+ 5
- 0
packaging/debian/changelog View File

@@ -0,0 +1,5 @@
1
+__MKIT_PROJ_PKGNAME__ (__MKIT_PROJ_VERSION__-1) UNRELEASED; urgency=medium
2
+
3
+  * Initial release. (Closes: #XXXXXX)
4
+
5
+ -- __MKIT_PROJ_MAINTAINER__  Mon, 02 Apr 2018 01:33:51 +0200

+ 1
- 0
packaging/debian/compat View File

@@ -0,0 +1 @@
1
+9

+ 47
- 0
packaging/debian/control View File

@@ -0,0 +1,47 @@
1
+Source: __MKIT_PROJ_PKGNAME__
2
+Maintainer: __MKIT_PROJ_MAINTAINER__
3
+Vcs-Browser: __MKIT_PROJ_VCS_BROWSER__
4
+Section: misc
5
+Priority: extra
6
+Standards-Version: 3.9.2
7
+Build-Depends:
8
+ debhelper (>= 9),
9
+
10
+Package: __MKIT_PROJ_PKGNAME__
11
+Architecture: all
12
+Depends:
13
+ shellfu (>= 0.10.7),
14
+ shellfu (<< 0.11),
15
+ shellfu-bash-jat (>= 0.0.0),
16
+ shellfu-bash-jat (<< 0.0.1),
17
+ shellfu-bash-pretty,
18
+ shellfu-bash-saturnin (>= 0.4.12),
19
+ shellfu-bash-saturnin (<< 5.0),
20
+Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__
21
+ JAT is a testing framework for Shell-based test suites.
22
+ .
23
+ This sub-package contains main binaries for session control and log
24
+ parsing.
25
+
26
+Package: __MKIT_PROJ_PKGNAME__-report
27
+Architecture: all
28
+Depends:
29
+ jattool (>= 0.0.0),
30
+ jattool (<< 0.0.1),
31
+ python-jinja2,
32
+Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__
33
+ JAT is a testing framework for Shell-based test suites.
34
+ .
35
+ This sub-package contains tools for result parsing and post-processing.
36
+
37
+Package: __MKIT_PROJ_PKGNAME__-tdk
38
+Architecture: all
39
+Depends:
40
+ git,
41
+Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__
42
+ JAT is a testing framework for Shell-based test suites.
43
+ .
44
+ This sub-package contains files and tools to help with test
45
+ development.
46
+
47
+# control file built with MKit __MKIT_SELF_VERSION__

+ 1
- 0
packaging/debian/copyright View File

@@ -0,0 +1 @@
1
+

+ 3
- 0
packaging/debian/jattool-report.install View File

@@ -0,0 +1,3 @@
1
+/usr/libexec/jattool/jattool-export
2
+/usr/share/jattool/jinja2/html.j2
3
+/usr/share/jattool/python/jat.py

+ 20
- 0
packaging/debian/jattool-tdk.install View File

@@ -0,0 +1,20 @@
1
+/usr/share/jattool/tdk/skel/Makefile
2
+/usr/share/jattool/tdk/skel/mkit.ini
3
+/usr/share/jattool/tdk/skel/packaging/debian/changelog
4
+/usr/share/jattool/tdk/skel/packaging/debian/compat
5
+/usr/share/jattool/tdk/skel/packaging/debian/control
6
+/usr/share/jattool/tdk/skel/packaging/debian/copyright
7
+/usr/share/jattool/tdk/skel/packaging/debian/install
8
+/usr/share/jattool/tdk/skel/packaging/debian/rules
9
+/usr/share/jattool/tdk/skel/packaging/debian/source/format
10
+/usr/share/jattool/tdk/skel/packaging/template.spec
11
+/usr/share/jattool/tdk/utils/mkit/include/build.sh
12
+/usr/share/jattool/tdk/utils/mkit/include/deploy.sh
13
+/usr/share/jattool/tdk/utils/mkit/include/facts.sh
14
+/usr/share/jattool/tdk/utils/mkit/include/ini.sh
15
+/usr/share/jattool/tdk/utils/mkit/include/mkit.sh
16
+/usr/share/jattool/tdk/utils/mkit/include/release.sh
17
+/usr/share/jattool/tdk/utils/mkit/include/vars.sh
18
+/usr/share/jattool/tdk/utils/mkit/make
19
+/usr/share/jattool/tdk/utils/mkit/mkit.mk
20
+/usr/share/jattool/tdk/utils/mkit/stub

+ 10
- 0
packaging/debian/jattool.install View File

@@ -0,0 +1,10 @@
1
+/etc/bash_completion.d/jattool.bash
2
+/usr/bin/jattool
3
+/usr/libexec/jattool/jattool-qrun
4
+/usr/libexec/jattool/jattool-runtest
5
+/usr/libexec/jattool/jattool-sessid
6
+/usr/libexec/jattool/jattool-sfind
7
+/usr/libexec/jattool/jattool-tfind
8
+/usr/share/jattool/help
9
+/usr/share/jattool/ini.d/main/jattool.ini
10
+/usr/share/doc/jattool/README.md

+ 9
- 0
packaging/debian/rules View File

@@ -0,0 +1,9 @@
1
+#!/usr/bin/make -f
2
+
3
+%:
4
+
5
+	dh $@
6
+
7
+override_dh_auto_install:
8
+
9
+	make install PREFIX=/usr DESTDIR=debian/tmp

+ 1
- 0
packaging/debian/source/format View File

@@ -0,0 +1 @@
1
+3.0 (quilt)

+ 104
- 0
packaging/template.spec View File

@@ -0,0 +1,104 @@
1
+%global sfincb %{_datadir}/shellfu/include-bash
2
+%global shellfu_req shellfu >= 0.10.8, shellfu < 0.11
3
+%global saturnin_req shellfu-bash-saturnin >= 0.4.12, shellfu-bash-saturnin < 0.5
4
+
5
+Name:       __MKIT_PROJ_PKGNAME__
6
+Version:    __MKIT_PROJ_VERSION__
7
+Release:    1%{?dist}
8
+Summary:    __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__
9
+URL:        __MKIT_PROJ_VCS_BROWSER__
10
+License:    LGPLv2
11
+Source0:    %{name}-%{version}.tar.gz
12
+BuildArch:  noarch
13
+
14
+Requires: %shellfu_req
15
+Requires: %saturnin_req
16
+Requires: shellfu-bash
17
+Requires: shellfu-bash-jat >= 0.0.0
18
+Requires: shellfu-bash-jat < 0.0.1
19
+Requires: shellfu-bash-pretty
20
+%description
21
+JAT is a testing framework for Shell-based test suites.
22
+
23
+This sub-package contains main binaries for test suite and session
24
+control.
25
+
26
+%package report
27
+Requires: python2-jinja2
28
+Requires: jattool == %{version}
29
+Summary: JAT result post-processing
30
+%description report
31
+JAT is a testing framework for Shell-based test suites.
32
+
33
+This sub-package contains tools for result parsing and post-processing.
34
+
35
+%package tdk
36
+Requires: git
37
+Summary: JAT test development kit
38
+%description tdk
39
+JAT is a testing framework for Shell-based test suites.
40
+
41
+This sub-package contains files and tools to help with test
42
+development.
43
+
44
+%prep
45
+%setup -q
46
+
47
+%build
48
+make %{?_smp_mflags} PREFIX=/usr
49
+
50
+%install
51
+%make_install PREFIX=/usr
52
+
53
+%files
54
+%config %{_sysconfdir}/bash_completion.d/%{name}.bash
55
+%dir %{_datadir}/%{name}
56
+%dir %{_datadir}/%{name}/ini.d
57
+%dir %{_datadir}/%{name}/ini.d/main
58
+%dir %{_libexecdir}/%{name}
59
+%doc %{_docdir}/%{name}/README.md
60
+%{_bindir}/%{name}
61
+%{_datadir}/%{name}/help
62
+%{_datadir}/%{name}/ini.d/main/jattool.ini
63
+%{_libexecdir}/%{name}/%{name}-qrun
64
+%{_libexecdir}/%{name}/%{name}-runtest
65
+%{_libexecdir}/%{name}/%{name}-sessid
66
+%{_libexecdir}/%{name}/%{name}-sfind
67
+%{_libexecdir}/%{name}/%{name}-tfind
68
+
69
+%files report
70
+%{_datadir}/jattool/jinja2/html.j2
71
+%{_datadir}/jattool/python/jat.py*
72
+%{_libexecdir}/%{name}/%{name}-export
73
+
74
+%files tdk
75
+%dir %{_datadir}/%{name}/tdk/skel
76
+%dir %{_datadir}/%{name}/tdk/skel/packaging
77
+%dir %{_datadir}/%{name}/tdk/skel/packaging/debian
78
+%dir %{_datadir}/%{name}/tdk/skel/packaging/debian/source
79
+%dir %{_datadir}/%{name}/tdk/utils/mkit
80
+%dir %{_datadir}/%{name}/tdk/utils/mkit/include
81
+%{_datadir}/%{name}/tdk/skel/Makefile
82
+%{_datadir}/%{name}/tdk/skel/mkit.ini
83
+%{_datadir}/%{name}/tdk/skel/packaging/debian/changelog
84
+%{_datadir}/%{name}/tdk/skel/packaging/debian/compat
85
+%{_datadir}/%{name}/tdk/skel/packaging/debian/control
86
+%{_datadir}/%{name}/tdk/skel/packaging/debian/copyright
87
+%{_datadir}/%{name}/tdk/skel/packaging/debian/install
88
+%{_datadir}/%{name}/tdk/skel/packaging/debian/rules
89
+%{_datadir}/%{name}/tdk/skel/packaging/debian/source/format
90
+%{_datadir}/%{name}/tdk/skel/packaging/template.spec
91
+%{_datadir}/%{name}/tdk/utils/mkit/include/build.sh
92
+%{_datadir}/%{name}/tdk/utils/mkit/include/deploy.sh
93
+%{_datadir}/%{name}/tdk/utils/mkit/include/facts.sh
94
+%{_datadir}/%{name}/tdk/utils/mkit/include/ini.sh
95
+%{_datadir}/%{name}/tdk/utils/mkit/include/mkit.sh
96
+%{_datadir}/%{name}/tdk/utils/mkit/include/release.sh
97
+%{_datadir}/%{name}/tdk/utils/mkit/include/vars.sh
98
+%{_datadir}/%{name}/tdk/utils/mkit/make
99
+%{_datadir}/%{name}/tdk/utils/mkit/mkit.mk
100
+%{_datadir}/%{name}/tdk/utils/mkit/stub
101
+
102
+%changelog
103
+
104
+# specfile built with MKit __MKIT_SELF_VERSION__

+ 34
- 0
src/app.skel View File

@@ -0,0 +1,34 @@
1
+#!/bin/bash
2
+#shellcheck disable=SC1090,SC2034
3
+
4
+. "$(sfpath)" || exit 3
5
+
6
+{
7
+    SATURNIN_APP_CODENAME="__MKIT_PROJ_CODENAME__"
8
+    SATURNIN_APP_TAGLINE="__MKIT_PROJ_TAGLINE__"
9
+    SATURNIN_APP_VERSION="__MKIT_PROJ_VERSION__"
10
+    SATURNIN_APP_GIT_HASH="__MKIT_PROJ_GIT_LASTHASH__"
11
+    SATURNIN_CACHE_HOME=${SATURNIN_CACHE_HOME:-"__SATURNIN_CACHE_HOME__"}
12
+    SATURNIN_CONFIG_HOME=${SATURNIN_CONFIG_HOME:-"__SATURNIN_CONFIG_HOME__"}
13
+    SATURNIN_DATA_HOME=${SATURNIN_DATA_HOME:-"__SATURNIN_DATA_HOME__"}
14
+    SATURNIN_META_HELP=${SATURNIN_META_HELP:-"+__SATURNIN_SHARE__/help"}
15
+    SATURNIN_LIBEXEC=${SATURNIN_LIBEXEC:-"__SATURNIN_LIBEXEC__"}
16
+    SATURNIN_LIBEXEC_PREFIX="__MKIT_PROJ_PKGNAME__-"
17
+    PRETTY_USAGE="subcommand"
18
+    PRETTY_DEBUG_EXCLUDE="$PRETTY_DEBUG_EXCLUDE,inigrep,saturnin"
19
+}
20
+
21
+shellfu import saturnin
22
+
23
+test -n "$SATURNIN_CONF_PATH" || SATURNIN_CONF_PATH="$(
24
+    saturnin__conf_mkpath \
25
+        "__SATURNIN_CONFIG_HOME__/ini.d" \
26
+        "__SATURNIN_CONFIG_HOME__" \
27
+        "__SATURNIN_CONFIG_LOCAL__" \
28
+        "__SATURNIN_SHARE__/ini.d"
29
+)"
30
+
31
+export SATURNIN_CONF_PATH SHELLFU_PATH PRETTY_USAGE PRETTY_DEBUG_EXCLUDE \
32
+       SATURNIN_CACHE_HOME SATURNIN_CONFIG_HOME SATURNIN_DATA_HOME
33
+
34
+saturnin__main "$@"

+ 38
- 0
src/complete.bash.skel View File

@@ -0,0 +1,38 @@
1
+#!/bin/bash
2
+
3
+__SATURNIN_COMPLETE_CMDNAME=__MKIT_PROJ_PKGNAME__
4
+
5
+#shellcheck disable=SC2016
6
+__SATURNIN_COMPLETE_CODETMPL='
7
+__%s() {
8
+    local cur opts sopts
9
+    COMPREPLY=()
10
+    cur="${COMP_WORDS[COMP_CWORD]}"
11
+    sopts="-D -V -d -h -v"
12
+    opts="--full-debug --help --verbose --debug --version --version-semver"
13
+    case "$cur" in
14
+        -*)
15
+            COMPREPLY=(
16
+                $(compgen -W "$sopts $opts" -- "${cur}")
17
+            )
18
+            ;;
19
+        --*)
20
+            COMPREPLY=(
21
+                $(compgen -W "$opts" -- "${cur}")
22
+            )
23
+            ;;
24
+        *)
25
+            COMPREPLY=(
26
+                $(compgen -W "$(%s --saturnin-get-subcommands)" "${cur}")
27
+            )
28
+    esac
29
+}'
30
+
31
+eval "$(
32
+    #shellcheck disable=SC2059
33
+    printf "$__SATURNIN_COMPLETE_CODETMPL" \
34
+        $__SATURNIN_COMPLETE_CMDNAME \
35
+        $__SATURNIN_COMPLETE_CMDNAME
36
+)"
37
+
38
+complete -F "__$__SATURNIN_COMPLETE_CMDNAME" "$__SATURNIN_COMPLETE_CMDNAME"

+ 0
- 0
src/help.skel View File


+ 4
- 0
src/ini.d/main/jattool.ini View File

@@ -0,0 +1,4 @@
1
+
2
+[jattool]
3
+
4
+    sdir = /var/tmp/jat

+ 43
- 0
src/jinja2/html.j2 View File

@@ -0,0 +1,43 @@
1
+<!doctype html>
2
+<html>
3
+    <head>
4
+        <title>JAT report {{ session.sessid }}</title>
5
+
6
+        <style type="text/css">
7
+            body { color: gray; background-color: black }
8
+            .lint { background-color: orange }
9
+            .phase { font-weight: bold }
10
+            .p_setup { color: blue }
11
+            .p_test { color: yellow }
12
+            .p_diag { color: lightblue }
13
+            .p_cleanup { color: blue }
14
+            .e_PASS { color: green }
15
+            .e_FAIL { color: red }
16
+        </style>
17
+
18
+    </head>
19
+    <body>
20
+
21
+        <div class="lints">
22
+            {% for lint in session.lints %}
23
+                <div class="lint">{{ lint.msg }} <code>{{ lint._data }}</code></div>
24
+            {% endfor %}
25
+        </div>
26
+
27
+        <div class="events">
28
+            {% for P in session.phases %}
29
+                <div class="phase p_{{P.type}}">
30
+                    <span class="type">{{P.type}}</span> |
31
+                    <span class="name">{{P.name}}</span>
32
+                </div>
33
+                {% for E in P.all_events %}
34
+                    <div class="event e_{{E.etype}}">
35
+                        {{E.etype}} | {{ E.hint }} | {{ E.data }}
36
+                    </div>
37
+                {% endfor %}
38
+            {% endfor %}
39
+        </div>
40
+
41
+    </body>
42
+</html>
43
+

+ 94
- 0
src/libexec/jattool-export.skel View File

@@ -0,0 +1,94 @@
1
+#!/bin/bash
2
+#shellcheck disable=SC1090
3
+
4
+. "$(sfpath)" || exit 3
5
+
6
+shellfu import pretty
7
+shellfu import jat
8
+
9
+usage() {
10
+    mkusage "$@" "[options] YLOG" \
11
+        -- \
12
+            "Export logfile YLOG to a concise report.  Format and target"    \
13
+            "paths can be specified using -d, -n and -f.  Note that one log" \
14
+            "may contain multiple sessions; each will be saved to separate"  \
15
+            "file."                                                          \
16
+        -o                                                                   \
17
+            "-d EDIR    Save exported files to EDIR (make it if it does not" \
18
+            "           exist).  Default is current directory."              \
19
+            "-f EFMT    Export in format EFMT.  Default is 'html'."          \
20
+            "           exist).  Default is current directory."              \
21
+            "-n NAME    Set template for exported files to NAME.  NAME must" \
22
+            "           contain '%s', which will be replaced with session"   \
23
+            "           id.  Default name is jat_report%s.html"
24
+}
25
+
26
+render_with_jinja() {
27
+    #
28
+    # Render template $1 with Jinja2
29
+    #
30
+    debug -v ExpDir ExpName ExpFmt YLog TFile
31
+    {
32
+        echo 'import sys'
33
+        echo 'from jinja2 import Template'
34
+        echo 'import jat'
35
+        echo ''
36
+        echo "epath = '$ExpDir/$ExpName.$ExpFmt'"
37
+        echo "ypath = '$YLog'"
38
+        echo "tpath = '$TFile'"
39
+        echo ''
40
+        echo 'sessions = jat.load(ypath)'
41
+        echo ''
42
+        echo 'with open(tpath) as tf:'
43
+        echo '    t = Template(tf.read())'
44
+        echo ''
45
+        echo 'for session in sessions:'
46
+        echo '    with open(epath % session.sessid, "w") as ef:'
47
+        echo '        ef.write(t.render('
48
+        echo '            session=session'
49
+        echo '        ))'
50
+    } | PYTHONPATH="__JATTOOL_PYTHONPATH__" python2
51
+}
52
+
53
+cmd_export() {
54
+    #
55
+    # Export to HTML
56
+    #
57
+    local TFile
58
+    mkdir -p "$ExpDir" || {
59
+        warn "cannot create export directory: $ExpDir"
60
+        return 3
61
+    }
62
+    case $ExpName in
63
+        *%s*)   : ;;
64
+        *)      warn "NAME does not contain %s, adding suffix -%s"
65
+                ExpName+=-%s ;;
66
+    esac
67
+    TFile="__JATTOOL_TEMPLATES__/$ExpFmt.j2"
68
+    test -f "$TFile" || {
69
+        warn "unsupported format: $ExpFmt"
70
+        return 3
71
+    }
72
+    render_with_jinja
73
+}
74
+
75
+main() {
76
+    local YLog
77
+    local ExpName=jat_report-%s
78
+    local ExpDir=.
79
+    local ExpFmt=html
80
+    while true; do case $1 in
81
+        -d) ExpDir=$2; shift 2 || usage -w "missing EDIR" ;;
82
+        -f) ExpFmt=$2; shift 2 || usage -w "missing EFMT" ;;
83
+        -n) ExpName=$2; shift 2 || usage -w "missing NAME" ;;
84
+        -*) usage ;;
85
+        *)  break ;;
86
+    esac done
87
+    YLog=$1; shift
88
+    test -n "$YLog"  || usage -w "no YLOG specified"
89
+    test -f "$YLog"  || usage -w "no such file: $YLog"
90
+    debug -v Ylog ExpName ExpDir ExpFmt
91
+    cmd_export
92
+}
93
+
94
+main "$@"

+ 69
- 0
src/libexec/jattool-qrun View File

@@ -0,0 +1,69 @@
1
+#!/bin/bash
2
+#shellcheck disable=SC1090
3
+
4
+. "$(sfpath)" || exit 3
5
+
6
+shellfu import pretty
7
+shellfu import saturnin
8
+shellfu import jat
9
+
10
+usage() {
11
+    mkusage "$@" "[options] BODY" \
12
+        -- \
13
+            "Initialize session and quick-run JAT test."                     \
14
+            ""                                                               \
15
+        -o                                                                   \
16
+            "-n NS      Set BEID namespace to NS"                            \
17
+            "-d SDIR    Set JAR session directory to SDIR.  This is where"   \
18
+            "           state data is kept.  Default: /var/tmp/jat."         \
19
+            "-y YLOG    Write YAML log also to file YLOG.  Default is to"    \
20
+            "           write only to default file under session dir."       \
21
+        --                                                                   \
22
+            "Test body should consist of asserts and/or phases documented"   \
23
+            "in jat.sh Shellfu module; use \`sfdoc jat\` to access its"      \
24
+            "documentation."
25
+}
26
+
27
+qrun() {
28
+    #
29
+    # Wrap in boilerplate and run test code in $1
30
+    #
31
+    JAT__BEID_NS=$BeidNs
32
+    JAT__YLOG=$YLog
33
+    JAT__DIR=$SDir
34
+    bash -n "$Body" || {
35
+        warn "test body has syntax errors"
36
+        return 3
37
+    }
38
+    jat__sinit || {
39
+        warn "failed to initialize logging"
40
+        return 3
41
+    }
42
+    source "$Body"
43
+    jat__sfinish
44
+}
45
+
46
+main() {
47
+    local Body
48
+    local SDir=$JAT__DIR
49
+    local YLog=$JAT__YLOG
50
+    local BeidNs=$JAT__BEID_NS
51
+    while true; do case $1 in
52
+        -n) BeidNs=$2; shift 2 || usage -w "missing NS" ;;
53
+        -d) SDir=$2;   shift 2 || usage -w "missing SDIR" ;;
54
+        -y) YLog=$2;   shift 2 || usage -w "missing YLOG" ;;
55
+        -*) usage ;;
56
+        *)  break ;;
57
+    esac done
58
+    Body=$1; shift
59
+    test -n "$Body" || usage -w "no BODY?"
60
+    test -f "$Body" || warn "test body not found: $Body"
61
+    test -n "$SDir" && SDir=$(saturnin__conf -j -1 jattool.sdir)
62
+    test -n "$YLog" && YLog=$(saturnin__conf -j -1 jattool.ylog)
63
+    test -n "$BeidNs" && BeidNs=$(saturnin__conf -j -1 jattool.beid_ns)
64
+    test -n "$SDir" || SDir=/var/tmp/jat
65
+    debug -v Body BeidNs SDir YLog
66
+    qrun
67
+}
68
+
69
+main "$@"

+ 95
- 0
src/libexec/jattool-runtest View File

@@ -0,0 +1,95 @@
1
+#!/bin/bash
2
+#shellcheck disable=SC1090,SC2164
3
+
4
+. "$(sfpath)" || exit 3
5
+
6
+shellfu import pretty
7
+
8
+usage() {
9
+    mkusage "$@" "[options] TESTDIR" \
10
+        -- \
11
+            "Initialize session and run JAT test."                          \
12
+            ""                                                               \
13
+            "Copy whole directory into temp, launch it there under watchdog,"\
14
+            "and after the test finishes, collect any relics back into"      \
15
+            "session directory."                                             \
16
+            ""                                                               \
17
+        -o                                                                   \
18
+            "-k         Keep run directory."                                 \
19
+            "-t TIMEOUT   Kill test after TIMEOUT seconds.  Default: 0,"     \
20
+            "           which disables the timeout.       "                  \
21
+        --                                                                   \
22
+            "Test body should consist of asserts and/or phases documented"   \
23
+            "in jat.sh Shellfu module; use \`sfdoc jat\` to access its"      \
24
+            "documentation."
25
+}
26
+
27
+runtest() {
28
+    #
29
+    # Wrap in boilerplate and run test code in $1
30
+    #
31
+    JAT__TESTID=$TestId jattool qrun "./test"
32
+}
33
+
34
+JATS__PATH=${JATS__PATH:-/usr/share/jat/suite}
35
+
36
+tlocate() {
37
+    #
38
+    # Locate test $TestId under known paths
39
+    #
40
+    debug -v JATS__PATH
41
+    local trypath
42
+    for trypath in ${JATS__PATH//:/ }; do
43
+        debug -v trypath
44
+        test -n "$trypath" || continue
45
+        test -d "$trypath" || continue
46
+        case $(jattool tfind -f ALL "$trypath" | grep -c " $TestId$") in
47
+            1)  jattool tfind "$trypath"; return 0 ;;
48
+            *)  continue ;;
49
+        esac
50
+    done
51
+    return 3
52
+}
53
+
54
+main() {
55
+    local TestHome
56
+    local TestTmp
57
+    local TestId
58
+    local Timeout
59
+    local keeptmp=false
60
+    local es=0
61
+    while true; do case $1 in
62
+        -k) keeptmp=true; shift ;;
63
+        -t) Timeout=$2; shift 2 || usage -w "missing TIMEOUT" ;;
64
+        -*) usage ;;
65
+        *)  break ;;
66
+    esac done
67
+    test -n "$Timeout" && die "sorry TIMEOUT is not supported yet"
68
+    case $1 in
69
+        "")
70
+            usage -w "no TESTDIR or TESTID?"
71
+            ;;
72
+        jats://*)
73
+            TestId=$1
74
+            TestHome=$(tlocate) || die "could not locate test: $TestId"
75
+            ;;
76
+        */*)
77
+            TestHome=$1
78
+            TestId=$(jattool tfind) || die "could not locate test: $TestId"
79
+            ;;
80
+    esac
81
+    test -f "$TestHome/test" \
82
+     || die "test body not found: $TestHome/test"
83
+    TestTmp=$(mktemp -dt jattool-runtest.XXXXXXXX)
84
+    debug -v TestHome TestId TestTmp
85
+    cp -ar "$TestHome"/* "$TestTmp" \
86
+     || die "could not copy test to tempdir"
87
+    pushd "$TestTmp" >/dev/null
88
+        runtest; es=$?
89
+    popd >/dev/null
90
+    $keeptmp || rm -rf "$TestTmp"
91
+    $keeptmp && warn "leaving temporary directory behind: $TestTmp"
92
+    return $es
93
+}
94
+
95
+main "$@"

+ 44
- 0
src/libexec/jattool-sessid View File

@@ -0,0 +1,44 @@
1
+#!/bin/bash
2
+#shellcheck disable=SC1090
3
+
4
+. "$(sfpath)" || exit 3
5
+
6
+shellfu import pretty
7
+shellfu import saturnin
8
+
9
+usage() {
10
+    mkusage "$@" "[options]" \
11
+        -- \
12
+            "Print current session id and exit with 0 or 1 if there is no"   \
13
+            "active session."                                                \
14
+        -o                                                                   \
15
+            "-d DIR     Set JAT workdir to DIR.  This is where state data"   \
16
+            "           is kept.  Default: /var/tmp/jat."
17
+}
18
+
19
+sessid() {
20
+    #
21
+    # Show session id or exit with 1
22
+    #
23
+    local sess="$SDir/session"
24
+    debug -v sess
25
+    test -f "$sess" || return 1
26
+    test -s "$sess" || return 1
27
+    grep . "$sess"  || return 1
28
+    return 0
29
+}
30
+
31
+main() {
32
+    local SDir=$JAT__DIR
33
+    while true; do case $1 in
34
+        -d) SDir=$2;   shift 2 || usage -w "missing SDIR" ;;
35
+        -*) usage ;;
36
+        *)  break ;;
37
+    esac done
38
+    test -n "$SDir" && SDir=$(saturnin__conf -j -1 jattool.sdir)
39
+    test -n "$SDir" || SDir=/var/tmp/jat
40
+    debug -v SDir
41
+    sessid
42
+}
43
+
44
+main "$@"

+ 104
- 0
src/libexec/jattool-sfind View File

@@ -0,0 +1,104 @@
1
+#!/bin/bash
2
+#shellcheck disable=SC1090
3
+
4
+. "$(sfpath)" || exit 3
5
+
6
+shellfu import pretty
7
+
8
+usage() {
9
+    mkusage "$@" "[options] BODY" \
10
+        -- \
11
+            "Discover test in suite located at PATH"                         \
12
+        -o                                                                   \
13
+            "-f FMT     Print test name in format FMT. 'jats' or 'path'."    \
14
+        --                                                                   \
15
+            "Test body should consist of asserts and/or phases documented"   \
16
+            "in jat.sh Shellfu module; use \`sfdoc jat\` to access its"    \
17
+            "documentation."
18
+}
19
+
20
+JATS__COMPAT=0.0
21
+
22
+sprop() {
23
+    #
24
+    # Get property $1 of suite at $SuiteDir
25
+    #
26
+    local pname=$1
27
+    local pvalue
28
+    local dvalue
29
+    local fpath
30
+    case $SuiteDir in
31
+        .)  fpath=.jats/$pname ;;
32
+        *)  fpath=$SuiteDir/.jats/$pname ;;
33
+    esac
34
+    case $pname in
35
+        domain)         dvalue="jats.example.org" ;;
36
+        ns)             dvalue="anonns" ;;
37
+        sut_nicename)   dvalue=$(sprop sut_pname) ;;
38
+        sut_pname)      dvalue="anonsut" ;;
39
+        sut_url)        dvalue="https://example.org/anonsut" ;;
40
+        url)            dvalue="https://$(sprop domain)/$(sprop ns)" ;;
41
+        format)         : ;;
42
+        *)              warn "unknown property: $pname"; return 2 ;;
43
+    esac
44
+    pvalue=$(cat "$fpath" 2>/dev/null)
45
+    debug -v pname dvalue pvalue
46
+    if test -n "$pvalue"; then
47
+        echo "$pvalue"
48
+        return 0
49
+    elif test "$pname" == "format"; then
50
+        warn "missing mandatory property: $fpath"
51
+        return 3
52
+    else
53
+        echo "$dvalue"
54
+    fi
55
+}
56
+
57
+discover() {
58
+    #
59
+    # Find tests under dirs ${FindDirs[@]}
60
+    #
61
+    local SuiteDir  # each suite root dir
62
+    local SuiteFmt  # suite format version
63
+    find "${FindDirs[@]}" -type d -path '*/.jats' \
64
+      | sed 's:/\.jats::' \
65
+      | while read -r SuiteDir; do
66
+            debug -v SuiteDir
67
+            SuiteFmt=$(sprop format) || continue
68
+            debug -v SuiteFmt
69
+            test "$SuiteFmt" == "$JATS__COMPAT" || continue
70
+            SuiteDomain=$(sprop domain)
71
+            SuiteNs=$(sprop ns)
72
+            SuiteSutPname=$(sprop sut_pname)
73
+            case $Fmt in
74
+                jats)
75
+                    echo -n "jats://$SuiteDomain/$SuiteNs"
76
+                    test -n "$SuiteSutPname" && echo -n "/$SuiteSutPname"
77
+                    echo
78
+                    ;;
79
+                path)
80
+                    echo "$SuiteDir"
81
+                    ;;
82
+            esac
83
+        done
84
+}
85
+
86
+main() {
87
+    local SuiteDir
88
+    local FindDirs=()
89
+    local Fmt=path
90
+    while true; do case $1 in
91
+        -f) Fmt=$2; shift 2 || usage -w "missing FMT" ;;
92
+        -*) usage -w "unknown argument: $1" ;;
93
+        *)  break ;;
94
+    esac done
95
+    FindDirs=("$@")
96
+    case $Fmt in
97
+        jats|path) : ;;
98
+        *) usage -w "unknown FMT: $Fmt" ;;
99
+    esac
100
+    debug -v FindDirs Fmt
101
+    discover
102
+}
103
+
104
+main "$@"

+ 58
- 0
src/libexec/jattool-tfind View File

@@ -0,0 +1,58 @@
1
+#!/bin/bash
2
+#shellcheck disable=SC1090,SC2164
3
+
4
+. "$(sfpath)" || exit 3
5
+
6
+shellfu import pretty
7
+
8
+usage() {
9
+    mkusage "$@" "[options] PATH" \
10
+        -- \
11
+            "Discover all JATS tests under directory PATH."                  \
12
+        -o                                                                   \
13
+            "-f FMT     Print test name in format FMT. 'jats' or 'path'."
14
+}
15
+
16
+discover() {
17
+    #
18
+    # Find tests under dirs ${FindDirs[@]}
19
+    #
20
+    local SuiteDir  # suite root dir
21
+    local TRPath    # relative path to test directory within $SuiteDir
22
+    local SuiteId   # suite's jats: id
23
+    jattool sfind -f path "${FindDirs[@]}" \
24
+      | while read -r SuiteDir; do
25
+            SuiteId=$(jattool sfind "$SuiteDir")
26
+            debug -v SuiteDir SuiteId
27
+            pushd "$SuiteDir">/dev/null
28
+                find . -type f -name test -printf '%P\n' \
29
+                  | sed 's:/test::' \
30
+                  | while read -r TRPath; do
31
+                        case $Fmt in
32
+                            path) echo "$SuiteDir/$TRPath" ;;
33
+                            jats) echo "$SuiteId/$TRPath" ;;
34
+                        esac
35
+                        debug -v TRPath
36
+                    done
37
+            popd >/dev/null
38
+        done
39
+}
40
+
41
+main() {
42
+    local FindDirs=()
43
+    local Fmt=path
44
+    while true; do case $1 in
45
+        -f) Fmt=$2; shift 2 || usage -w "missing FMT" ;;
46
+        -*) usage -w "unknown argument: $1" ;;
47
+        *)  break ;;
48
+    esac done
49
+    FindDirs=("$@")
50
+    case $Fmt in
51
+        jats|path) : ;;
52
+        *) usage -w "unknown FMT: $Fmt" ;;
53
+    esac
54
+    debug -v FindDirs Fmt
55
+    discover
56
+}
57
+
58
+main "$@"

+ 258
- 0
src/python/jat.py View File

@@ -0,0 +1,258 @@
1
+#!/usr/bin/python2
2
+
3
+import yaml
4
+
5
+
6
+class ParsingError(ValueError):
7
+    pass
8
+
9
+
10
+class _EventGroup(object):
11
+
12
+    def __init__(self, events):
13
+        if not events:
14
+            raise ValueError("no events in event group")
15
+        self._events = events
16
+
17
+    @property
18
+    def all_events(self):
19
+        return self._events
20
+
21
+    @property
22
+    def asserts(self):
23
+        return [e for e in self._events if e.is_assert]
24
+
25
+    @property
26
+    def fails(self):
27
+        return [e for e in self._events if e.etype == 'FAIL']
28
+
29
+    @property
30
+    def passes(self):
31
+        return [e for e in self._events if e.etype == 'PASS']
32
+
33
+    @property
34
+    def events(self):
35
+        return self._events
36
+
37
+    @property
38
+    def lints(self):
39
+        lints = []
40
+        for e in self._events:
41
+            lints += e.lints
42
+        return lints
43
+
44
+
45
+class Event(object):
46
+
47
+    is_assert = False
48
+
49
+    def __str__(self):
50
+        return str(self._rawdata)
51
+
52
+    def __init__(self, rawdata):
53
+        self._rawdata = rawdata
54
+        self.origin = rawdata['origin']
55
+        self.stamp = rawdata['stamp']
56
+        self.hint = rawdata['hint']
57
+        self.beids = [BeId(b) for b in rawdata['beids']]
58
+        self.edata = rawdata['data']
59
+        self.etype = rawdata['etype']
60
+        self.phaseid = rawdata['phase']['id']
61
+        self.phasename = rawdata['phase']['name']
62
+        self.phasetype = rawdata['phase']['type']
63
+
64
+    @staticmethod
65
+    def from_data(data):
66
+        etype = data['etype']
67
+        if etype in ['PASS', 'FAIL']:
68
+            cls = AssertEvent
69
+        elif etype == 'SINFO':
70
+            cls = StructureInfoEvent
71
+        elif etype == 'TEST_ERROR':
72
+            cls = TestErrorEvent
73
+        elif etype == 'PROMISE':
74
+            cls = PromiseEvent
75
+        else:
76
+            raise ParsingError("unknown event type: %s" % etype)
77
+        return cls(data)
78
+
79
+    @property
80
+    def lints(self):
81
+        return []
82
+
83
+
84
+class StrayEvent(Event):
85
+    pass
86
+
87
+
88
+class TestErrorEvent(Event):
89
+
90
+    def lints(self):
91
+        return [Lint("test error", self._rawdata)]
92
+
93
+class PromiseEvent(Event):
94
+    pass
95
+
96
+
97
+class StructureInfoEvent(Event):
98
+    pass
99
+
100
+
101
+class AssertEvent(Event):
102
+
103
+    is_assert = True
104
+
105
+    @property
106
+    def lints(self):
107
+        lints = []
108
+        if self.phaseid == '0000000000-000000000':
109
+            lints.append(Lint('assert outside phase', self))
110
+        return lints
111
+
112
+
113
+class BeId(object):
114
+
115
+    def __init__(self, data):
116
+        self._data = data
117
+
118
+
119
+class Phase(_EventGroup):
120
+
121
+    @property
122
+    def name(self):
123
+        return self.all_events[0].phasename
124
+
125
+    @property
126
+    def type(self):
127
+        return self.all_events[0].phasetype
128
+
129
+
130
+class EventLog(_EventGroup):
131
+    """
132
+    Session event log (all events from session)
133
+    """
134
+
135
+    @classmethod
136
+    def from_data(cls, data):
137
+        return cls([Event.from_data(e) for e in data])
138
+
139
+
140
+class Lint(object):
141
+    """
142
+    Lint-like warning coming from log parsing (eg. unclosed phase)
143
+    """
144
+
145
+    def __init__(self, msg, data):
146
+        self.msg = msg
147
+        self._data = data
148
+
149
+
150
+class Session(object):
151
+
152
+    def __init__(self, doc):
153
+        self._doc = doc
154
+        self._format = doc['format']
155
+        if not self._format.startswith('jat/0.'):
156
+            raise ParsingError('unsupported log format: %s' % self._format)
157
+        self.jat_version = doc['jat_version']
158
+        self.start = doc['start']
159
+        self.sessid = 'noid'
160
+        self.finalized = doc.get('finalized', False)
161
+        self.end = doc.get('end')
162
+        self.lints = []
163
+        self.eventlog = EventLog.from_data(doc['events'])
164
+        self.lints += self.eventlog.lints
165
+        self.phases, lints = self._es2ps(self.eventlog)
166
+        self.lints += lints
167
+        if not self.finalized:
168
+            self.lints.append(Lint("session not finalized", self.sessid))
169
+
170
+    class _PhaseBuff:
171
+
172
+        def __init__(self):
173
+            self.phaseid = None
174
+            self.events = []
175
+
176
+        def is_anon(self):
177
+            return self.phaseid == '0000000000.000000000'
178
+
179
+        def dump2phase(self):
180
+            phase = Phase(self.events) 
181
+            self.phaseid = None
182
+            self.events = []
183
+            return phase
184
+
185
+        def match(self, event):
186
+            if self.phaseid is None:
187
+                return True
188
+            else:
189
+                return self.phaseid == event.phaseid
190
+
191
+        def append(self, event):
192
+            self.phaseid = event.phaseid
193
+            self.events.append(event)
194
+
195
+        def __nonzero__(self):
196
+            return bool(self.events)
197
+
198
+        def __bool__(self):
199
+            return bool(self.events)
200
+
201
+        def __len__(self):
202
+            return len(self.events)
203
+
204
+    @staticmethod
205
+    def _es2ps(eventlog):
206
+
207
+        def addlint(msg):
208
+            lints.append(Lint(msg, event))
209
+
210
+        phases = []
211
+        lints = []
212
+        this_phaseid = None
213
+        pbuff = Session._PhaseBuff()
214
+        for event in eventlog.all_events:
215
+            if event.origin == 'jat__sinit':
216
+                continue
217
+            if event.origin == 'jat__sfinish':
218
+                if pbuff:
219
+                    phases.append(pbuff.dump2phase())
220
+                    addlint('unfinished phase: %s' % pbuff.phaseid)
221
+                continue
222
+            if event.origin == 'jat__pend':
223
+                #
224
+                # Phase end
225
+                #
226
+                if pbuff:
227
+                    phases.append(pbuff.dump2phase())
228
+                else:
229
+                    addlint('dangling phase end')
230
+            elif event.origin == '__jat__pstart':
231
+                #
232
+                # Phase start
233
+                #
234
+                if pbuff:
235
+                    phases.append(pbuff.dump2phase())
236
+                    if not pbuff.is_anon():
237
+                        addlint('phase starts before previous ends')
238
+            elif pbuff:
239
+                #
240
+                # Second or later event
241
+                #
242
+                if not pbuff.match(event):
243
+                    phases.append(pbuff.dump2phase())
244
+                    addlint('phase mismatch: %s =! %s'\
245
+                            % (event.phaseid, pbuff.phaseid))
246
+                pbuff.append(event)
247
+            else:
248
+                #
249
+                # First event
250
+                #
251
+                pbuff.append(event)
252
+        return phases, lints
253
+
254
+
255
+def load(fpath):
256
+    with open(fpath) as ylog:
257
+        sessions = [Session(doc) for doc in yaml.load_all(ylog)]
258
+    return sessions

+ 5
- 0
src/tdk/Makefile View File

@@ -0,0 +1,5 @@
1
+# jats Makefile include
2
+# See LICENSE.md file for copyright and license details.
3
+
4
+MKIT_DIR=utils/mkit
5
+include $(MKIT_DIR)/mkit.mk

+ 24
- 0
src/tdk/mkit.ini.skel View File

@@ -0,0 +1,24 @@
1
+[project]
2
+    name = [macros:__JATS_SUITENAME__] JATS test suite
3
+    tagline = [macros:__JATS_SUITENAME__] test suite in JATS format
4
+
5
+[dist]
6
+    tarball  = Makefile
7
+    tarball  = mkit.ini
8
+    tarball  = src
9
+    rpmstuff = __JATTOOL_TDK_SKEL__/packaging/template.spec
10
+    debstuff = __JATTOOL_TDK_SKEL__/packaging/debian
11
+
12
+[ENV]
13
+    PREFIX = /usr/local
14
+
15
+[macros]
16
+    __JATTOOL_VERSION__ = __MKIT_PROJ_VERSION__
17
+    __JATS_REQUIRES__ = jattool
18
+    __JATS_REQUIRES__ = shellfu-bash-jat
19
+    __JATS_REQUIRES__ = shellfu-bash-pretty
20
+
21
+[roots]
22
+    jats = [ENV:PREFIX]/share/jats/suite
23
+
24
+#mkit version=0.0.32

+ 5
- 0
src/tdk/packaging/debian/changelog View File

@@ -0,0 +1,5 @@
1
+__MKIT_PROJ_PKGNAME__ (__MKIT_PROJ_VERSION__-1) UNRELEASED; urgency=medium
2
+
3
+  * Initial release. (Closes: #XXXXXX)
4
+
5
+ -- __MKIT_PROJ_MAINTAINER__  Tue, 10 Apr 2018 23:43:01 +0200

+ 1
- 0
src/tdk/packaging/debian/compat View File

@@ -0,0 +1 @@
1
+9

+ 19
- 0
src/tdk/packaging/debian/control View File

@@ -0,0 +1,19 @@
1
+Source: __MKIT_PROJ_PKGNAME__
2
+Maintainer: __MKIT_PROJ_MAINTAINER__
3
+Section: misc
4
+Priority: extra
5
+Standards-Version: 3.9.2
6
+Build-Depends:
7
+ jattool-tdk,
8
+ debhelper (>= 9),
9
+
10
+Package: __MKIT_PROJ_PKGNAME__
11
+Architecture: all
12
+Depends:
13
+ __JATS_REQUIRES__,
14
+Description: __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__
15
+ __MKIT_PROJ_TAGLINE__
16
+ .
17
+ Built with jattool-tdk-__JATTOOL_VERSION__
18
+
19
+# control file built with MKit __MKIT_SELF_VERSION__

+ 1
- 0
src/tdk/packaging/debian/copyright View File

@@ -0,0 +1 @@
1
+

+ 0
- 0
src/tdk/packaging/debian/install View File


+ 9
- 0
src/tdk/packaging/debian/rules View File

@@ -0,0 +1,9 @@
1
+#!/usr/bin/make -f
2
+
3
+%:
4
+
5
+	dh $@
6
+
7
+override_dh_auto_install:
8
+
9
+	make install PREFIX=/usr DESTDIR=debian/tmp

+ 1
- 0
src/tdk/packaging/debian/source/format View File

@@ -0,0 +1 @@
1
+3.0 (quilt)

+ 36
- 0
src/tdk/packaging/template.spec View File

@@ -0,0 +1,36 @@
1
+%global _jats_dir %{_datadir}/jats/suite
2
+%global _jats_suitename __JATS_SUITENAME__
3
+
4
+Name:          __MKIT_PROJ_PKGNAME__
5
+Version:       __MKIT_PROJ_VERSION__
6
+Release:       1%{?dist}
7
+Summary:       __MKIT_PROJ_NAME__
8
+License:       GPLv2
9
+Source0:       %{name}-%{version}.tar.gz
10
+BuildArch:     noarch
11
+BuildRequires: jattool-tdk
12
+
13
+Requires: __JATS_REQUIRES__
14
+%description
15
+JATS test suite.
16
+
17
+Built with jattool-tdk-__JATTOOL_VERSION__
18
+
19
+%prep
20
+%setup -q
21
+
22
+%build
23
+make %{?_smp_mflags} PREFIX=/usr
24
+
25
+%install
26
+%make_install PREFIX=/usr
27
+
28
+%files
29
+%dir %{_jats_dir}/%{_jats_suitename}
30
+%dir %{_jats_dir}/%{_jats_suitename}/*
31
+%{_jats_dir}/%{_jats_suitename}/.jats/*
32
+%{_jats_dir}/%{_jats_suitename}/*
33
+
34
+%changelog
35
+
36
+# specfile built with MKit __MKIT_SELF_VERSION__

+ 290
- 0
src/tdk/utils/mkit/include/build.sh View File

@@ -0,0 +1,290 @@
1
+#!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
5
+mkit_import ini
6
+mkit_import facts
7
+
8
+
9
+__build1() {
10
+    #
11
+    # Process one skeleton $1 of type $3 (or guessed) to path $2
12
+    #
13
+    local srcpath=$1    # skeleton path
14
+    local dstpath=$2    # destination meaty animal path
15
+    local ftype=$3      # file/builder type
16
+    test -n "$dstpath"  || dstpath=${srcpath%.skel}
17
+    test -n "$ftype"    || ftype=$(__guess_ftype "$dstpath")
18
+    debug_var srcpath dstpath ftype
19
+    <"$srcpath" __build1_ftype "$ftype" >"$dstpath"
20
+    __rec_built "$dstpath"
21
+}
22
+
23
+__build1_ftype() {
24
+    #
25
+    # Build a file of type $1; fom stdin to stdout
26
+    #
27
+    local ftype=$1      # file/builder type
28
+    case $ftype in
29
+        MKIT_COMMON)    __expand_macros "macros" ;;
30
+        rpmstuff)       __expand_macros "macros" "rpmstuff:macros" ;;
31
+        debstuff)       __expand_macros "macros" "debstuff:macros" ;;
32
+        *)              die "unknown file type: $ftype" ;;
33
+    esac
34
+}
35
+
36
+__expand_line() {
37
+    #
38
+    # Expand macro from $MacroMap in single line $1
39
+    #
40
+    # If macro value has multiple lines, repeat original line with
41
+    # different substitution.
42
+    #
43
+    # E.g. if macro value is "foo\nbar" and macro name is __FOO__,
44
+    # line `see: "__FOO__"` will expand to two lines: `see: "foo"`
45
+    # and `see: "bar"`.
46
+    #
47
+    local line=$1   # line to process
48
+    local mname     # macro name
49
+    local mvline    # line of macro value
50
+    local xline     # expanded line
51
+    xline=$line
52
+    for mname in "${!MacroMap[@]}"; do
53
+        if ! test "${line//$mname}" == "$line"; then
54
+            xline=$(
55
+                while IFS= read -r mvline; do
56
+                    echo "${line//$mname/$mvline}"
57
+                done <<<"${MacroMap[$mname]}"
58
+            )
59
+        fi
60
+        line=$xline
61
+    done
62
+    echo "$xline"
63
+    return 1
64
+}
65
+
66
+__expand_macros() {
67
+    #
68
+    # Read stdin, expanding macros from sections $@
69
+    #
70
+    local section       # each section to expand macros from
71
+    local line          # each line on stdin
72
+    local mname         # each macro name
73
+    local -A MacroMap   # macro value map
74
+    MacroMap[__MKIT_PROJ_NAME__]=$(ini 1value project:name)
75
+    MacroMap[__MKIT_PROJ_CODENAME__]=$(ini 1value project:codename)
76
+    MacroMap[__MKIT_PROJ_LICENSE__]=$(ini 1value project:license)
77
+    MacroMap[__MKIT_PROJ_PKGNAME__]=$(ini 1value project:pkgname)
78
+    MacroMap[__MKIT_PROJ_TAGLINE__]=$(ini 1value project:tagline)
79
+    MacroMap[__MKIT_PROJ_MAINTAINER__]=$(ini 1value project:maintainer)
80
+    MacroMap[__MKIT_PROJ_VCS_BROWSER__]=$(ini 1value project:vcs_browser)
81
+    MacroMap[__MKIT_PROJ_GIT_LASTHASH__]=$(__cached git_lasthash)
82
+    MacroMap[__MKIT_PROJ_VERSION__]=$(__cached semver)
83
+    MacroMap[__MKIT_SELF_VERSION__]=$MKIT_VERSION
84
+    for section in "$@"; do
85
+        for mname in $(ini lskeys "$section"); do
86
+            MacroMap[$mname]=$(ini values "$section:$mname")
87
+        done
88
+    done
89
+    debug_var MacroMap
90
+    while IFS= read -r line; do
91
+        __expand_line "$line"
92
+    done
93
+}
94
+
95
+__guess_ftype() {
96
+    #
97
+    # Guess file type from destination path $1
98
+    #
99
+    local dstpath=$1    # destination path
100
+    case $dstpath in
101
+        *)    echo MKIT_COMMON ;;
102
+    esac
103
+}
104
+
105
+__qfs() {
106
+    #
107
+    # Quote for our sed scipt's RHS
108
+    #
109
+    sed '
110
+        s:\\:\\\\:g
111
+        s:|:\\|:g
112
+    '
113
+}
114
+
115
+__cached() {
116
+    #
117
+    # Cached value $1 of function $1()
118
+    #
119
+    # In order to support git-less builds, some values might be cached
120
+    # in $MKIT_LOCAL.  This function gets file $1 from that cache (cache
121
+    # hit) or re-creates it (cache miss), but prints its body in either
122
+    # case.
123
+    #
124
+    # The command to re-create file is the same as the key (ie. no
125
+    # arguments).
126
+    #
127
+    local name=$1
128
+    __local_get "$name" && return 0
129
+    "$name" | __local_putb "$name"
130
+    __local_get "$name"
131
+}
132
+
133
+__local_putb() {
134
+    #
135
+    # Make file $1 in $MKIT_LOCAL from stdin and mark as built
136
+    #
137
+    local fpath=$1
138
+    __local_put "$fpath" && __rec_built "$MKIT_LOCAL/$fpath"
139
+}
140
+
141
+__local_put() {
142
+    #
143
+    # Make file $1 in $MKIT_LOCAL from stdin
144
+    #
145
+    local fpath="$MKIT_LOCAL/$1"
146
+    { mkdir -p "${fpath%/*}" && cat >"$fpath"; } \
147
+     || die "cannot write to local cache: $fpath"
148
+}
149
+
150
+__local_get() {
151
+    #
152
+    # Read file $1 in $MKIT_LOCAL
153
+    #
154
+    local fpath="$MKIT_LOCAL/$1"
155
+    cat "$fpath" 2>/dev/null
156
+}
157
+
158
+__rec_built() {
159
+    #
160
+    # Record file $1 for deletion on `clean`
161
+    #
162
+    local file=$1
163
+    mkdir -p "$MKIT_LOCAL"
164
+    echo "$file" >> "$MKIT_LOCAL/built.lst"
165
+}
166
+
167
+_mkit_data() {
168
+    #
169
+    # Build sampler showing all macro values
170
+    #
171
+    local macro
172
+    local section
173
+    local sections
174
+    sections=()
175
+    ini lskeys macros | grep -q . && sections=(macros)
176
+    sections+=( $(ini lssect | grep ':macros$') )
177
+    {
178
+        echo "(builtin):"
179
+        echo "  x_MKIT_PROJ_NAME__ => '__MKIT_PROJ_NAME__'"
180
+        echo "  x_MKIT_PROJ_CODENAME__ => '__MKIT_PROJ_CODENAME__'"
181
+        echo "  x_MKIT_PROJ_LICENSE__ => '__MKIT_PROJ_LICENSE__'"
182
+        echo "  x_MKIT_PROJ_PKGNAME__ => '__MKIT_PROJ_PKGNAME__'"
183
+        echo "  x_MKIT_PROJ_TAGLINE__ => '__MKIT_PROJ_TAGLINE__'"
184
+        echo "  x_MKIT_PROJ_MAINTAINER__ => '__MKIT_PROJ_MAINTAINER__'"
185
+        echo "  x_MKIT_PROJ_VCS_BROWSER__ => '__MKIT_PROJ_VCS_BROWSER__'"
186
+        echo "  x_MKIT_PROJ_GIT_LASTHASH__ => '__MKIT_PROJ_GIT_LASTHASH__'"
187
+        echo "  x_MKIT_PROJ_VERSION__ => '__MKIT_PROJ_VERSION__'"
188
+        echo "  x_MKIT_SELF_VERSION__ => '__MKIT_SELF_VERSION__'"
189
+        for section in "${sections[@]}"; do
190
+            echo "$section:"
191
+            for macro in $(ini lskeys "$section"); do
192
+                echo "  x${macro:1} => '$macro'"
193
+            done
194
+        done
195
+    } \
196
+      | __expand_macros "MKIT_BUILTIN" "${sections[@]}" \
197
+      | sed '/^  x/ s|x|_|'
198
+}
199
+
200
+build() {
201
+    #
202
+    # Add meat to all skeletons
203
+    #
204
+    local srcpath   # each source path
205
+    find . -type f -name '*.skel' \
206
+     | while read -r srcpath; do
207
+           __build1 "$srcpath"
208
+       done
209
+}
210
+
211
+clean() {
212
+    #
213
+    # Clean up tree after building
214
+    #
215
+    test -f "$MKIT_LOCAL/built.lst" && {
216
+        <"$MKIT_LOCAL/built.lst" grep -v -e '\.\.' -e ^/ \
217
+          | xargs -r rm -rf
218
+        rm -f "$MKIT_LOCAL/built.lst"
219
+        rmdir --ignore-fail-on-non-empty "$MKIT_LOCAL"
220
+    }
221
+    true
222
+}
223
+
224
+debstuff() {
225
+    #
226
+    # Build Debian stuff (eamed tarball, debian dir)
227
+    #
228
+    local version       # package version
229
+    local debian_skel   # 'debian' folder skeleton
230
+    local dfsrc         # each source file from ^^
231
+    local dftgt         # each built packaging file
232
+    version=$(__cached semver)
233
+
234
+    # tarball - we should already have by means of 'dist'
235
+    #
236
+    mv "${MKIT_PROJ_PKGNAME}-$version.tar.gz" \
237
+       "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz" \
238
+     || die "could not rename tarball"
239
+    __rec_built "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz"
240
+
241
+    # read content of each mandatory file from debian_skel
242
+    #
243
+    debian_skel=$(ini 1value dist:debstuff)
244
+    test -n "$debian_skel" || die "dist:debstuff not specified"
245
+    test -d "$debian_skel" || die "debian directory template found: $debian_skel"
246
+    mkdir -p debian/source
247
+    find "$debian_skel" -type f \
248
+      | while read -r dfsrc; do
249
+            dftgt="debian/${dfsrc#$debian_skel}"
250
+            mkdir -p "$(dirname "$dftgt")"
251
+            __build1 "$dfsrc" "$dftgt" debstuff
252
+        done
253
+    __rec_built debian
254
+}
255
+
256
+dist() {
257
+    #
258
+    # Create distributable tarball
259
+    #
260
+    #FIXME: lacking Makefile skills, we do this step twice for
261
+    #       rpmstuff, hence -f hack for gzip
262
+    #
263
+    local version           # tarball version
264
+    local git_lasthash      # last git commit hash
265
+    local dirname           # directory and tarball name
266
+    version=$(semver)
267
+    dirname=$MKIT_PROJ_PKGNAME-$version
268
+    git_lasthash=$(git_lasthash)
269
+    mkdir -p "$dirname"
270
+    ini values "dist:tarball" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
271
+    mkdir -p "$dirname/.mkit"
272
+    echo -n "$version" > "$dirname/.mkit/semver"
273
+    echo -n "$git_lasthash" > "$dirname/.mkit/git_lasthash"
274
+    tar -cf "$dirname.tar" "$dirname"
275
+    gzip -f "$dirname.tar"      # see above FIXME
276
+    __rec_built "$dirname.tar.gz"
277
+    rm -rf "$dirname"
278
+}
279
+
280
+rpmstuff() {
281
+    #
282
+    # Build specfile
283
+    #
284
+    local specname=$MKIT_PROJ_PKGNAME.spec      # .spec filename
285
+    local specsrc                               # source of specfile
286
+    specsrc="$(ini 1value "dist:rpmstuff")"
287
+    test -n "$specsrc" || die "dist:rpmstuff not specified"
288
+    test -f "$specsrc" || die "specfile template not found: $specsrc"
289
+    __build1 "$specsrc" "$specname" rpmstuff
290
+}

+ 130
- 0
src/tdk/utils/mkit/include/deploy.sh View File

@@ -0,0 +1,130 @@
1
+#!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
5
+mkit_import ini
6
+
7
+__deploy_item() {
8
+    #
9
+    # Deploy item and make it look like wanted
10
+    #
11
+    # usage: __deploy_item src dst [mode]
12
+    #
13
+    # Both src and dst must be names of actual items[1],
14
+    # whereas dst must not exist.  On update, dst is
15
+    # usually to be replaced but that is uninstall's
16
+    # job!
17
+    #
18
+    #  [1] Ie. src=foo and dst=/foo/bar does *always*
19
+    #      mean that foo will become 'bar'.  This is
20
+    #      different than traditional `cp` behavior,
21
+    #      when this depends if 'bar' already exists
22
+    #      as a directory.
23
+    #
24
+    # If mode is omitted or empty, MKIT_DEFAULT_MODE is
25
+    # used instead.
26
+    #
27
+    # Directories are copied recursively, and mode is
28
+    # applied only to files.
29
+    #
30
+    local src=$1                            # source path
31
+    local dst=$2                            # destination path
32
+    local mode=${3:-$MKIT_DEFAULT_MODE}     # mode
33
+    local item                              # each in directory
34
+    if test -d "$src"; then
35
+        find "$src" -type f \
36
+          | while read -r item; do
37
+                [[ $item =~ .skel$ ]] \
38
+                 && grep -q "${item%.skel}" "$MKIT_LOCAL/built.lst" \
39
+                 && continue
40
+                __deploy_item "$item" "$dst${item#$src}" "$mode"
41
+            done
42
+    else
43
+        test "$mode" == "SRC" && mode=$(stat -c "%a" "$src")
44
+        __maybe install -DTvm "$mode" "$src" "$dst"
45
+    fi
46
+}
47
+
48
+__get_dst() {
49
+    #
50
+    # Find out target path for src file $2 of group $1
51
+    #
52
+    local grp=$1        # deploy group
53
+    local src=$2        # each source
54
+    local dst=$3        # alternative destination name
55
+    test -n "$dst" || dst=${src##*/}
56
+    echo "$(__get_root "$grp")/$dst"
57
+}
58
+
59
+__get_root() {
60
+    #
61
+    # Find out target root for group $1
62
+    #
63
+    local grp=$1        # deploy group
64
+    local root          # root for this group
65
+    local destdir       # value of DESTDIR
66
+    root=$(ini 1value "roots:$grp")
67
+    destdir=$(ini 1value ENV:DESTDIR)
68
+    destdir=${destdir%/}
69
+    case $destdir:$root in
70
+        *:)     die "missing in config.ini: roots:$grp" ;;
71
+        :*)     echo "$root" ;;
72
+        *:*)    echo "$destdir/$root" ;;
73
+    esac
74
+}
75
+
76
+__maybe() {
77
+    #
78
+    # Call the deploy command $1 $@ unless in dry mode
79
+    #
80
+    debug "$@"
81
+    local cmd="$1"; shift
82
+    $MKIT_DRY && return
83
+    case "$cmd" in
84
+        cp|rm|rmdir|chmod|mkdir) $cmd "$@" ;;
85
+        install)                 command -p install "$@" ;;
86
+        *)                       die "bad command called";;
87
+    esac
88
+}
89
+
90
+install() {
91
+    #
92
+    # Install product
93
+    #
94
+    local group     # each deploy group
95
+    local mode      # mode (group-specific)
96
+    local src       # each source path
97
+    local dst       # each (final absolute) destination path
98
+    ini lskeys "files" \
99
+      | sort \
100
+      | uniq \
101
+      | while read -r group; do
102
+            mode=$(ini 1value "modes:$group")
103
+            ini values "files:$group" \
104
+              | while read -r src dst; do
105
+                    dst=$(__get_dst "$group" "$src" "$dst")
106
+                    __deploy_item "$src" "$dst" "$mode"
107
+                done
108
+        done
109
+    test -f "$MKIT_LOCAL/autoclean" && clean
110
+    true
111
+}
112
+
113
+uninstall() {
114
+    #
115
+    # Uninstall product
116
+    #
117
+    local group     # each deploy group
118
+    local src       # each source path
119
+    local dst       # each (final absolute) destination path
120
+    ini lskeys "files" \
121
+      | sort \
122
+      | uniq \
123
+      | while read -r group; do
124
+            ini values "files:$group" \
125
+              | while read -r src dst; do
126
+                    dst=$(__get_dst "$group" "$src" "$dst")
127
+                    __maybe rm -vrf "$dst"
128
+                done
129
+        done
130
+}

+ 175
- 0
src/tdk/utils/mkit/include/facts.sh View File

@@ -0,0 +1,175 @@
1
+#!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
5
+mkit_import ini
6
+
7
+git_bool() {
8
+    #
9
+    # Get git bool (ie. exit status counts) $1
10
+    #
11
+    local bool_name=$1      # name of boolean to get
12
+    git_present || warn "can't give bool outside git repo: $bool_name"
13
+    case "$bool_name" in
14
+        dirty_files)
15
+            git diff-files | grep -qm 1 .
16
+            ;;
17
+        dirty_index)
18
+            git diff-index HEAD | grep -qm 1 .
19
+            ;;
20
+        dirty)
21
+            git_bool dirty_files || git_bool dirty_index
22
+            ;;
23
+        *)
24
+            warn "unknown git bool asked: $bool_name"
25
+            return 2
26
+            ;;
27
+    esac
28
+}
29
+
30
+git_fact() {
31
+    #
32
+    # Get git fact $1
33
+    #
34
+    local fact_name=$1      # name of fact to get
35
+    git_present || warn "can't give fact outside git repo: $fact_name"
36
+    case "$fact_name" in
37
+        latest_tag)
38
+            git log --format="%d" \
39
+              | sed 's/,/\n/g' \
40
+              | sed 's/^[[:blank:]]*//' \
41
+              | grep -E '^\(?tag' \
42
+              | tr -cd '[[:digit:]].v\n' \
43
+              | grep . -m 1
44
+            ;;
45
+        latest_version)
46
+            git_fact latest_tag | git_tag2ver
47
+            ;;
48
+        current_branch)
49
+            git rev-parse --abbrev-ref HEAD
50
+            ;;
51
+        reldiff)
52
+            git log --oneline "$(git_fact latest_tag)..HEAD" --name-only
53
+            ;;
54
+        latest_sha)
55
+            git log -1 --pretty=format:%h HEAD
56
+            ;;
57
+        *)
58
+            warn "unknown git fact asked: $fact_name"
59
+            ;;
60
+    esac
61
+}
62
+
63
+git_present() {
64
+    #
65
+    # True if we're in a git repo
66
+    #
67
+    git rev-parse HEAD >&/dev/null
68
+}
69
+
70
+git_tag2ver() {
71
+    #
72
+    # Convert tag to version
73
+    #
74
+    sed s/^v//
75
+}
76
+
77
+git_ver2tag() {
78
+    #
79
+    # Convert version to tag
80
+    #
81
+    sed s/^/v/
82
+}
83
+
84
+git_lasthash() {
85
+    #
86
+    # Show last commit hash (with .dirty suffix if needed)
87
+    #
88
+    # We can't do it outside git repo (or without git) but we should
89
+    # not be asked to; targets that don't require git should make use
90
+    # of cache built by dist target.
91
+    #
92
+    local last_hash     # last commit hash
93
+    git_present || {
94
+        echo UNKNOWN_HASH
95
+        warn "no git present; could not determine last hash"
96
+        return 3
97
+    }
98
+    last_hash=$(git rev-parse HEAD)
99
+    echo -n "$last_hash"
100
+    git_bool dirty && echo -n ".dirty"
101
+}
102
+
103
+semver() {
104
+    #
105
+    # Build proper SemVer version string
106
+    #
107
+    # Build version string from available info using following
108
+    # logic:
109
+    #
110
+    #  1. Use version from last git tag (or mkit.ini if there is no
111
+    #     tag, which is possible on new project)
112
+    #  2. if set, add project:prerl (from mkit.ini) as pre-release ID
113
+    #     (afer dash)
114
+    #  3. if we are at a later commit than the last tag, add branch
115
+    #     name and commit sha1 to build metadata (after plus sign)
116
+    #  4. if the tree is "dirty", i.e. has uncommited changes,
117
+    #     add "dirty" to build metadata
118
+    #
119
+    # The version is compatible with SemVer 2.0.0.
120
+    #
121
+    # Examples:
122
+    #
123
+    #     foo v1.0.7                            # all clear; proper release
124
+    #     foo v1.0.7-beta                       # mkit.ini: project:prerl="beta"
125
+    #     foo v1.0.7-beta+g1aef811.master       # ^^ + some commits after
126
+    #     foo v1.0.7-beta+gf14fc4f.api2         # ^^ + on a feature branch
127
+    #     foo v1.0.7-beta+gf14fc4f.api2.dirty   # ^^ + tree edited
128
+    #     foo v1.0.7-beta+dirty                 # tag OK but tree edited
129
+    #     foo v1.0.7+dirty                      # ^^ but no pre-release id
130
+    #
131
+    # Note that versions with "dirty" should be perceived as kind of
132
+    # dangerous outside developer's own machine.  Versions with sha1 are
133
+    # safer but must not be released.
134
+    #
135
+    # FIXME:  Using project:prerl for release IDs may not be compatible with
136
+    #         release strategy implemented in release.sh
137
+    #
138
+    local xyz           # base version string
139
+    local prerl         # pre-release keyword (from mkit.ini, eg. 'beta')
140
+    local latest_tag    # latest git tag
141
+    local commit        # commit indicator (CURRENT_BRANCH.gHASH)
142
+    local dirty         # 0 if dirty, 1 if clean
143
+    local suffix        # version suffix
144
+    prerl=$(ini 1value project:prerl)
145
+    grep ":" <<<"$prerl" \
146
+     && warn "colon in project:prerl may corrupt version data: $prerl"
147
+    git_present || {
148
+        echo UNKNOWN_VERSION
149
+        warn "no git present; could not determine SemVer"
150
+        return 3
151
+    }
152
+    latest_tag=$(git_fact latest_tag)
153
+    case $latest_tag in
154
+        v*) xyz=${latest_tag:1} ;;
155
+        "") warn "no tags, using base version from mkit.ini (ok for new project)"
156
+            xyz=$(ini 1value project:version) ;;
157
+        *)  warn "bad form of last tag, using base version from mkit.ini: tag is '$latest_tag'"
158
+            xyz=$(ini 1value project:version) ;;
159
+    esac
160
+    if ! git describe --tags --exact-match HEAD >&/dev/null;
161
+    then    # we are at a later commit than the last tag
162
+        commit="$(git_fact current_branch).g$(git_fact latest_sha)"
163
+    fi
164
+    git_bool dirty; dirty=$?
165
+    case "$dirty:$commit" in
166
+        1:)  suffix=""               ;;
167
+        0:)  suffix="+dirty"         ;;
168
+        1:*) suffix="+$commit"       ;;
169
+        0:*) suffix="+$commit.dirty" ;;
170
+        *)   suffix=MKIT_BUG
171
+             warn "MKIT_BUG: bad dirt/commit detection" ;;
172
+    esac
173
+    test -n "$prerl" && suffix="-$prerl$suffix"
174
+    echo "$xyz$suffix"
175
+}

+ 177
- 0
src/tdk/utils/mkit/include/ini.sh View File

@@ -0,0 +1,177 @@
1
+#!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
5
+__ini_cat() {
6
+    #
7
+    # A no-op for text stream
8
+    #
9
+    local line      # each line
10
+    while read -r line; do
11
+        printf -- "%s\n" "$line"
12
+    done
13
+}
14
+
15
+__ini_expand() {
16
+    #
17
+    # Expand reference value (prefix only)
18
+    #
19
+    local line      # each input line
20
+    local suffix    # tail of the line
21
+    local ref       # reference
22
+    local value     # value if reference
23
+    while read -r line; do                  # [foo:bar]/path
24
+        suffix="${line#\[*\]}"              # /path
25
+        ref="${line%$suffix}"               # [foo:bar]
26
+        ref="${ref%\]}"                     # [foo:bar
27
+        ref="${ref#\[}"                     # foo:bar
28
+        value="$(ini 1value "$ref")"        # foo_bar_value
29
+        printf -- "%s\n" "$value$suffix"    # foo_bar_value/path
30
+    done
31
+}
32
+
33
+__ini_grepcmt() {
34
+    #
35
+    # Remove comments from INI file on stdin
36
+    #
37
+    grep -v '^[[:space:]]*#'
38
+}
39
+
40
+__ini_grepkey() {
41
+    #
42
+    # Read key from a section
43
+    #
44
+    local wnt=$1    # wanted key
45
+    grep '.' \
46
+      | sed -e 's/ *= */=/; s/ +$//; s/^//;' \
47
+      | grep -e "^$wnt=" \
48
+      | cut -d= -f2- \
49
+      | __ini_maybe_expand
50
+}
51
+
52
+__ini_greppath() {
53
+    #
54
+    # Read key from the right section
55
+    #
56
+    # E.g. `files:share:my/lib.sh` should read
57
+    #
58
+    #     [files:share]
59
+    #         my/lib.sh   = proj/my/lib.sh
60
+    #
61
+    local wnt=$1                    # wanted path
62
+    local wntkey=${wnt##*:}         # ^^ key part
63
+    local wntsec=${wnt%:$wntkey}    # ^^ section part
64
+    local override                  # ENV override (only ENV section)
65
+    if test "$wntsec" = 'ENV'; then
66
+        override=${!wntkey}
67
+        test -n "$override" \
68
+         && echo "$override" \
69
+         && return
70
+    fi
71
+    __ini_grepsec "$wntsec" | __ini_grepkey "$wntkey"
72
+}
73
+
74
+__ini_grepsec() {
75
+    #
76
+    # Read one INI section
77
+    #
78
+    local wnt=$1        # wanted section name
79
+    local ok=false      # are we in the section?
80
+    local line          # each input line
81
+    grep '.' \
82
+      | while read -r line; do
83
+            case "$line" in
84
+                \[$wnt\]) ok=true;  continue ;;
85
+                \[*\])    ok=false; continue ;;
86
+            esac
87
+            $ok || continue
88
+            printf -- "%s\n" "$line"
89
+        done \
90
+      | sed -e 's/ *= */=/; s/ +$//; s/^//;'
91
+}
92
+
93
+__ini_lskeys() {
94
+    #
95
+    # List keys from a section
96
+    #
97
+    local sct=$1    # section of interest
98
+    __ini_grepsec "$sct" | cut -d= -f1 | awk '!x[$0]++'
99
+}
100
+
101
+__ini_lssect() {
102
+    #
103
+    # List all section names
104
+    #
105
+    local arg=$1    # unused argument
106
+    grep -x '\[.*\]' | sed 's/^.//; s/.$//'
107
+}
108
+
109
+__ini_maybe_expand() {
110
+    #
111
+    # Decide whether or not to expand
112
+    #
113
+    if test "$MKIT_INI_EXPAND" -gt 0; then
114
+        MKIT_INI_EXPAND=$(( --MKIT_INI_EXPAND )) __ini_expand
115
+    else
116
+        __ini_cat
117
+    fi
118
+}
119
+
120
+__ini_body() {
121
+    #
122
+    # Produce mkit.ini body including INCLUDE
123
+    #
124
+    # Note: recursive includes are not supported.
125
+    #
126
+    local inc                       # file to include
127
+    local incre='\[INCLUDE:.*\]'    # include directive regex
128
+    local iline                     # include directive line
129
+    if iline=$(grep -m1 -x "$incre" "$MKIT_INI"); then
130
+        inc=${iline#*:}; inc=${inc%]}
131
+        grep -vx "$incre" "$inc"
132
+        grep -vx "$incre" "$MKIT_INI"
133
+    else
134
+        cat "$MKIT_INI"
135
+    fi | __ini_grepcmt
136
+}
137
+
138
+ini() {
139
+    #
140
+    # do ini operation
141
+    #
142
+    local op=$1             # operator
143
+    local arg=$2            # argument
144
+    local fn                # internal function implementing $op
145
+    local limit=__ini_cat    # limiting internal function
146
+    case $op in
147
+        lskeys) fn=__ini_lskeys   ;;
148
+        lssect) fn=__ini_lssect   ;;
149
+        sec)    fn=__ini_grepsec  ;;
150
+        values) fn=__ini_greppath ;;
151
+        1value) fn=__ini_greppath; limit="tail -1" ;;
152
+        *)      die "incorrect use of \`ini()\`"
153
+    esac
154
+    __ini_body | $fn "$arg" | $limit
155
+}
156
+
157
+update_version() {
158
+    #
159
+    # Change project:version in mkit.ini at path $2 to value $1
160
+    #
161
+    local version=$1    # new version
162
+    local inifile=$2    # mkit.ini path
163
+    local tmp           # mkit.ini cache
164
+    tmp=$(mktemp -t mkit.update_version.XXXXXXXX)
165
+    <"$inifile" perl -e '
166
+        my $hit = 0;
167
+        my $done = 0;
168
+        foreach (<STDIN>) {
169
+            if      ($done) { print; next; }
170
+            elsif   (m/\[project\]/) { $hit++; print; next; }
171
+            elsif   (m/\[/) { $hit = 0; print; next; }
172
+            elsif   ($hit) { s/\bversion\b( *)=( *).*/version$1=$2$ARGV[0]/ and $done++; print; }
173
+            else { print; next; }
174
+        }
175
+    ' "$version" >"$tmp" || die "failed to update version in mkit.ini"
176
+    mv "$tmp" "$inifile"
177
+}

+ 162
- 0
src/tdk/utils/mkit/include/mkit.sh View File

@@ -0,0 +1,162 @@
1
+#!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
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
32
+
33
+__valid_targets() {
34
+    #
35
+    # List valid routes
36
+    #
37
+    echo _mkit_data
38
+    echo build
39
+    echo clean
40
+    echo debstuff
41
+    echo dist
42
+    echo install
43
+    echo release
44
+    echo release_x
45
+    echo release_y
46
+    echo release_z
47
+    echo rpmstuff
48
+    echo uninstall
49
+    echo vbump
50
+    echo vbump_x
51
+    echo vbump_y
52
+    echo vbump_z
53
+}
54
+
55
+debug() {
56
+    #
57
+    # Print debug message
58
+    #
59
+    $MKIT_DEBUG || return 0
60
+    echo "MKIT_DEBUG: ${FUNCNAME[1]}()" "$@" >&2
61
+}
62
+
63
+debug_var() {
64
+    #
65
+    # Print debug message
66
+    #
67
+    $MKIT_DEBUG || return 0
68
+    local __mkit_debug_var_name__       # variable name to debug
69
+    local decl                          # declare string
70
+    for __mkit_debug_var_name__ in "$@"; do
71
+        {
72
+            decl=$(declare -p "$__mkit_debug_var_name__")
73
+            decl=${decl#declare ?? }
74
+            echo "MKIT_DEBUG: ${FUNCNAME[1]}(): $decl"
75
+        } >&2
76
+    done
77
+}
78
+
79
+__compver() {
80
+    #
81
+    # True if version $1 matches our version
82
+    #
83
+    # If our x is 0, check first two fragments, otherwise check just
84
+    # the x.  Fragments must equal.
85
+    #
86
+    local their_ver=$1      # their version
87
+    local our_x             # our X
88
+    local our_y             # our Y
89
+    local their_x           # their X
90
+    local their_y           # their Y
91
+    their_x=${their_ver%%.*}
92
+    their_y=${their_ver##$their_x.}
93
+    their_y=${their_y%%.*}
94
+    our_x=${MKIT_VERSION%%.*}
95
+    our_y=${MKIT_VERSION##$our_x.}
96
+    our_y=${our_y%%.*}
97
+    debug_var MKIT_VERSION our_x our_y their_ver their_x their_y
98
+    test "$their_x" -eq "$our_x" || return 1
99
+    test "$our_x" -eq 0 && {
100
+        test "$their_y" = "$our_y"
101
+        return $?
102
+    }
103
+    return 0
104
+}
105
+
106
+__chkiniversion() {
107
+    #
108
+    # Check if ini version is supported
109
+    #
110
+    # Look for "#mkit version=0.0.0" or similar in first or last
111
+    # 3 lines of the file; then check if the version is supported.
112
+    #
113
+    local ver_line      # line declaring version
114
+    local their_ver     # the declared version
115
+    ver_line=$(
116
+        {
117
+            head -3 "$MKIT_INI"
118
+            tail -3 "$MKIT_INI"
119
+        } | grep -m 1 -E '^# *mkit +version *= *v?[0-9]+\.[0-9]+\.[0-9]+'
120
+    )
121
+    test -n "$ver_line" \
122
+     || die "version mark ('#mkit version=x.y.z') not found in: $MKIT_INI"
123
+    their_ver="$(tr -d '[:blank:]v' <<<"${ver_line##*=}")"
124
+    __compver "$their_ver" \
125
+     || die "bad mkit.ini version: $their_ver does not match $MKIT_VERSION"
126
+}
127
+
128
+mkit_init() {
129
+    #
130
+    # Do basic initialization
131
+    #
132
+    # Check for ini file and some variables
133
+    #
134
+    $MKIT_DRY && MKIT_DEBUG=true
135
+    #shellcheck disable=SC2034
136
+    MKIT_PROJ_PKGNAME=$(ini 1value "project:pkgname")
137
+    test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
138
+    __chkiniversion
139
+}
140
+
141
+route() {
142
+    #
143
+    # Call correct function based on $1
144
+    #
145
+    if __valid_targets | grep -qwx "^$1"; then
146
+        "$1"
147
+    else
148
+        {
149
+            echo "usage: $(basename "$0") TARGET"
150
+            echo
151
+            echo "valid targets:"
152
+            __valid_targets | sed 's/^/    /'
153
+        } >&2
154
+    fi
155
+}
156
+
157
+warn() {
158
+    #
159
+    # Print warning message
160
+    #
161
+    echo "$@" >&2
162
+}

+ 232
- 0
src/tdk/utils/mkit/include/release.sh View File

@@ -0,0 +1,232 @@
1
+#!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
5
+mkit_import ini
6
+mkit_import facts
7
+
8
+__bump_version() {
9
+    #
10
+    # Bump version on stdin by level $1 (x, y or z)
11
+    #
12
+    local rlevel=$1     # release level
13
+    local old           # old version
14
+    local oldx          # ... X
15
+    local oldz          # ... Z
16
+    local oldy          # ... Y
17
+    local tmpy          # Y parsing cache
18
+    local new           # bumped version
19
+    read -r old
20
+    oldx=${old%.*.*}
21
+    oldz=${old#*.*.}
22
+    tmpy=${old%.*}
23
+    oldy=${tmpy#*.}
24
+    case $rlevel in
25
+        x) new="$((oldx+MKIT_BUMPSIZE)).0.0"            ;;
26
+        y) new="$oldx.$((oldy+MKIT_BUMPSIZE)).0"        ;;
27
+        z) new="$oldx.$oldy.$((oldz+MKIT_BUMPSIZE))"    ;;
28
+        *) die "invalid release level: $1"  ;;
29
+    esac
30
+    echo "$new"
31
+}
32
+
33
+__relck() {
34
+    #
35
+    # Die if blocking condition $1 is detected
36
+    #
37
+    local condition=$1      # condition name
38
+    local oracle            # expected value
39
+    case "$condition" in
40
+        git_present)
41
+            git rev-parse HEAD >&/dev/null\
42
+             || die "cannot do this outside git repo"
43
+            ;;
44
+        at_relsrc)
45
+            oracle=$(ini 1value project:relsrc)
46
+            git_fact current_branch \
47
+              | grep -qFx "$oracle" \
48
+             || die "you are not on release source branch: $oracle"
49
+            ;;
50
+        not_dirty)
51
+            git diff --shortstat 2>/dev/null \
52
+              | grep -q . \
53
+             && die "tree is dirty!"
54
+            ;;
55
+        tags_ok)
56
+            git_fact latest_tag \
57
+              | grep -q . \
58
+             || die "cannot find latest tag"
59
+            ;;
60
+        vbump_hot)
61
+            git diff-tree --no-commit-id --name-only -r HEAD \
62
+              | grep -qFx mkit.ini \
63
+             || die "last change must be version bump in mkit.ini"
64
+            ;;
65
+        no_wip)
66
+            git_fact reldiff \
67
+              | grep '^....... WIP ' \
68
+             && die "WIP commit since $(git_fact latest_tag)"
69
+            ;;
70
+        ini_version)
71
+            oracle=$(git_fact latest_version | __bump_version "$rlevel")
72
+            ini 1value project:version  \
73
+              | grep -qFx "$oracle" \
74
+             || die "new version not in mkit.ini: $oracle"
75
+            ;;
76
+        *)
77
+            die "unknown release check: $condition"
78
+            ;;
79
+    esac
80
+}
81
+
82
+__release() {
83
+    #
84
+    # Prepare release
85
+    #
86
+    # Span release routines: make a signed tag, check branch
87
+    # and update release branch
88
+    #
89
+    # FIXME: Using project:prerl as build.sh:semver() does may not be
90
+    #        compatible with this release strategy
91
+    #
92
+    local rlevel=$1     # release level (x, y or z)
93
+    local newtag        # new tag
94
+    local relsrc        # release source branch (if any)
95
+    local reldst        # release destination branch (if any)
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
104
+
105
+    newtag=$(git_fact latest_version | __bump_version "$rlevel" | git_ver2tag )
106
+    set -e
107
+    debug_var newtag
108
+    $MKIT_DRY && return
109
+    git tag -m "$(__release_msg)" "$newtag"
110
+
111
+    relsrc=$(ini 1value project:relsrc)
112
+    reldst=$(ini 1value project:reldst)
113
+    debug_var relsrc reldst
114
+    if test -n "$reldst" && test "$reldst" != "$relsrc"; then
115
+        git branch -f "$reldst" "$newtag"
116
+    fi
117
+}
118
+
119
+__release_msg() {
120
+    #
121
+    # Generate message for annotated tag
122
+    #
123
+    # The last commit before issuing a release must be "Bump version" commit
124
+    # suggested by _vbump_gitmsg() and  manually edited by user.  Since the
125
+    # commit contains changelog, this function just uses the message body.
126
+    #
127
+    # The sort message (first line) is replaced with a nicer one (with project
128
+    # name, codename and version).
129
+    #
130
+    echo "$(ini 1value project:name) $newtag - $(ini 1value project:codename)"
131
+    echo
132
+    git show -s --format=%B \
133
+      | tail -n +3
134
+}
135
+
136
+__vbump() {
137
+    #
138
+    # Do version bump at level $1
139
+    #
140
+    # Perform checks, compute new version, update mkit.ini and initiate
141
+    # 'Bump version' commit with changelog template.
142
+    #
143
+    local rlevel=$1     # bump level (x, y or z)
144
+    local nextver       # version after the bump
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")
150
+    debug_var nextver
151
+    $MKIT_DRY && return
152
+    update_version "$nextver" mkit.ini \
153
+      || die "failed to update version in mkit.ini"
154
+    git add mkit.ini \
155
+      || die "failed to add mkit.ini to the index"
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"
160
+}
161
+
162
+_vbump_gitmsg() {
163
+    #
164
+    # Compose git message template for 'Bump version' commit
165
+    #
166
+    echo "Bump version"
167
+    echo ""
168
+    echo "Overview of changes:"
169
+    echo ""
170
+    git_fact reldiff \
171
+      | sed '
172
+            s/^[a-f0-9]\{7\} /\n *  &/; t PATHS
173
+            s/^/        /
174
+            :PATHS
175
+        '
176
+}
177
+
178
+release() {
179
+    #
180
+    # Perform release on Z level
181
+    #
182
+    __release z
183
+}
184
+
185
+release_x() {
186
+    #
187
+    # Perform release on X level
188
+    #
189
+    __release x
190
+}
191
+
192
+release_y() {
193
+    #
194
+    # Perform release on Y level
195
+    #
196
+    __release y
197
+}
198
+
199
+release_z() {
200
+    #
201
+    # Perform release on Z level
202
+    #
203
+    __release z
204
+}
205
+
206
+vbump() {
207
+    #
208
+    # Perform version bump on Z level
209
+    #
210
+    __vbump z
211
+}
212
+
213
+vbump_x() {
214
+    #
215
+    # Perform version bump on X level
216
+    #
217
+    __vbump x
218
+}
219
+
220
+vbump_y() {
221
+    #
222
+    # Perform version bump on Y level
223
+    #
224
+    __vbump y
225
+}
226
+
227
+vbump_z() {
228
+    #
229
+    # Perform version bump on Z level
230
+    #
231
+    __vbump z
232
+}

+ 61
- 0
src/tdk/utils/mkit/include/vars.sh View File

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

+ 34
- 0
src/tdk/utils/mkit/make View File

@@ -0,0 +1,34 @@
1
+#!/bin/bash
2
+#shellcheck disable=SC2034
3
+# mkit - simple install helper
4
+# See LICENSE file for copyright and license details.
5
+
6
+init_core() {
7
+    #
8
+    # Load core module (or die)
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
16
+}
17
+
18
+#
19
+# Path to MKit dir (where 'include' is)
20
+#
21
+MKIT_DIR=${MKIT_DIR:-$(dirname "$0")}
22
+
23
+
24
+init_core
25
+
26
+case "$1" in
27
+    -V|--version-semver)    echo "$MKIT_VERSION"; exit 0 ;;
28
+    --version)              echo "Mkit (Simple Makefile target helper) $MKIT_VERSION"
29
+                            exit 0 ;;
30
+esac
31
+
32
+mkit_init
33
+
34
+route "$@"

+ 56
- 0
src/tdk/utils/mkit/mkit.mk View File

@@ -0,0 +1,56 @@
1
+# mkit - Simple Makefile target helper
2
+# See LICENSE file for copyright and license details.
3
+
4
+export MKIT_DIR
5
+
6
+all: build
7
+
8
+_mkit_data:
9
+	@"$(MKIT_DIR)"/make _mkit_data
10
+
11
+build:
12
+	@"$(MKIT_DIR)"/make build
13
+
14
+clean:
15
+	@"$(MKIT_DIR)"/make clean
16
+
17
+debstuff: dist
18
+	@"$(MKIT_DIR)"/make debstuff
19
+
20
+dist: clean
21
+	@"$(MKIT_DIR)"/make dist
22
+
23
+rpmstuff: dist
24
+	@"$(MKIT_DIR)"/make rpmstuff
25
+
26
+install: all
27
+	@"$(MKIT_DIR)"/make install
28
+
29
+release:
30
+	@"$(MKIT_DIR)"/make release
31
+
32
+release_x:
33
+	@"$(MKIT_DIR)"/make release_x
34
+
35
+release_y:
36
+	@"$(MKIT_DIR)"/make release_y
37
+
38
+release_z:
39
+	@"$(MKIT_DIR)"/make release_z
40
+
41
+uninstall:
42
+	@"$(MKIT_DIR)"/make uninstall
43
+
44
+vbump:
45
+	@"$(MKIT_DIR)"/make vbump
46
+
47
+vbump_x:
48
+	@"$(MKIT_DIR)"/make vbump_x
49
+
50
+vbump_y:
51
+	@"$(MKIT_DIR)"/make vbump_y
52
+
53
+vbump_z:
54
+	@"$(MKIT_DIR)"/make vbump_z
55
+
56
+.PHONY: all _mkit_data clean dist rpmstuff install uninstall release release_x release_y release_z vbump vbump_x vbump_y vbump_z

+ 715
- 0
src/tdk/utils/mkit/stub View File

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

+ 286
- 0
utils/mkit/include/build.sh View File

@@ -0,0 +1,286 @@
1
+#!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
5
+mkit_import ini
6
+mkit_import facts
7
+
8
+
9
+__build1() {
10
+    #
11
+    # Process one skeleton $1 of type $3 (or guessed) to path $2
12
+    #
13
+    local srcpath=$1    # skeleton path
14
+    local dstpath=$2    # destination meaty animal path
15
+    local ftype=$3      # file/builder type
16
+    test -n "$dstpath"  || dstpath=${srcpath%.skel}
17
+    test -n "$ftype"    || ftype=$(__guess_ftype "$dstpath")
18
+    debug_var srcpath dstpath ftype
19
+    <"$srcpath" __build1_ftype "$ftype" >"$dstpath"
20
+    __rec_built "$dstpath"
21
+}
22
+
23
+__build1_ftype() {
24
+    #
25
+    # Build a file of type $1; fom stdin to stdout
26
+    #
27
+    local ftype=$1      # file/builder type
28
+    case $ftype in
29
+        MKIT_COMMON)    __expand_macros "macros" ;;
30
+        rpmstuff)       __expand_macros "macros" "rpmstuff:macros" ;;
31
+        debstuff)       __expand_macros "macros" "debstuff:macros" ;;
32
+        *)              die "unknown file type: $ftype" ;;
33
+    esac
34
+}
35
+
36
+__expand_line() {
37
+    #
38
+    # Expand macro from $MacroMap in single line $1
39
+    #
40
+    # If macro value has multiple lines, repeat original line with
41
+    # different substitution.
42
+    #
43
+    # E.g. if macro value is "foo\nbar" and macro name is __FOO__,
44
+    # line `see: "__FOO__"` will expand to two lines: `see: "foo"`
45
+    # and `see: "bar"`.
46
+    #
47
+    local line=$1   # line to process
48
+    local mname     # macro name
49
+    local mvline    # line of macro value
50
+    for mname in "${!MacroMap[@]}"; do
51
+        if ! test "${line//$mname}" == "$line"; then
52
+            while IFS= read -r mvline; do
53
+                echo "${line//$mname/$mvline}"
54
+            done <<<"${MacroMap[$mname]}"
55
+            return 0
56
+        fi
57
+    done
58
+    echo "$line"
59
+    return 1
60
+}
61
+
62
+__expand_macros() {
63
+    #
64
+    # Read stdin, expanding macros from sections $@
65
+    #
66
+    local section       # each section to expand macros from
67
+    local line          # each line on stdin
68
+    local mname         # each macro name
69
+    local -A MacroMap   # macro value map
70
+    MacroMap[__MKIT_PROJ_NAME__]=$(ini 1value project:name)
71
+    MacroMap[__MKIT_PROJ_CODENAME__]=$(ini 1value project:codename)
72
+    MacroMap[__MKIT_PROJ_LICENSE__]=$(ini 1value project:license)
73
+    MacroMap[__MKIT_PROJ_PKGNAME__]=$(ini 1value project:pkgname)
74
+    MacroMap[__MKIT_PROJ_TAGLINE__]=$(ini 1value project:tagline)
75
+    MacroMap[__MKIT_PROJ_MAINTAINER__]=$(ini 1value project:maintainer)
76
+    MacroMap[__MKIT_PROJ_VCS_BROWSER__]=$(ini 1value project:vcs_browser)
77
+    MacroMap[__MKIT_PROJ_GIT_LASTHASH__]=$(__cached git_lasthash)
78
+    MacroMap[__MKIT_PROJ_VERSION__]=$(__cached semver)
79
+    MacroMap[__MKIT_SELF_VERSION__]=$MKIT_VERSION
80
+    for section in "$@"; do
81
+        for mname in $(ini lskeys "$section"); do
82
+            MacroMap[$mname]=$(ini values "$section:$mname")
83
+        done
84
+    done
85
+    debug_var MacroMap
86
+    while IFS= read -r line; do
87
+        __expand_line "$line"
88
+    done
89
+}
90
+
91
+__guess_ftype() {
92
+    #
93
+    # Guess file type from destination path $1
94
+    #
95
+    local dstpath=$1    # destination path
96
+    case $dstpath in
97
+        *)    echo MKIT_COMMON ;;
98
+    esac
99
+}
100
+
101
+__qfs() {
102
+    #
103
+    # Quote for our sed scipt's RHS
104
+    #
105
+    sed '
106
+        s:\\:\\\\:g
107
+        s:|:\\|:g
108
+    '
109
+}
110
+
111
+__cached() {
112
+    #
113
+    # Cached value $1 of function $1()
114
+    #
115
+    # In order to support git-less builds, some values might be cached
116
+    # in $MKIT_LOCAL.  This function gets file $1 from that cache (cache
117
+    # hit) or re-creates it (cache miss), but prints its body in either
118
+    # case.
119
+    #
120
+    # The command to re-create file is the same as the key (ie. no
121
+    # arguments).
122
+    #
123
+    local name=$1
124
+    __local_get "$name" && return 0
125
+    "$name" | __local_putb "$name"
126
+    __local_get "$name"
127
+}
128
+
129
+__local_putb() {
130
+    #
131
+    # Make file $1 in $MKIT_LOCAL from stdin and mark as built
132
+    #
133
+    local fpath=$1
134
+    __local_put "$fpath" && __rec_built "$MKIT_LOCAL/$fpath"
135
+}
136
+
137
+__local_put() {
138
+    #
139
+    # Make file $1 in $MKIT_LOCAL from stdin
140
+    #
141
+    local fpath="$MKIT_LOCAL/$1"
142
+    { mkdir -p "${fpath%/*}" && cat >"$fpath"; } \
143
+     || die "cannot write to local cache: $fpath"
144
+}
145
+
146
+__local_get() {
147
+    #
148
+    # Read file $1 in $MKIT_LOCAL
149
+    #
150
+    local fpath="$MKIT_LOCAL/$1"
151
+    cat "$fpath" 2>/dev/null
152
+}
153
+
154
+__rec_built() {
155
+    #
156
+    # Record file $1 for deletion on `clean`
157
+    #
158
+    local file=$1
159
+    mkdir -p "$MKIT_LOCAL"
160
+    echo "$file" >> "$MKIT_LOCAL/built.lst"
161
+}
162
+
163
+_mkit_data() {
164
+    #
165
+    # Build sampler showing all macro values
166
+    #
167
+    local macro
168
+    local section
169
+    local sections
170
+    sections=()
171
+    ini lskeys macros | grep -q . && sections=(macros)
172
+    sections+=( $(ini lssect | grep ':macros$') )
173
+    {
174
+        echo "(builtin):"
175
+        echo "  x_MKIT_PROJ_NAME__ => '__MKIT_PROJ_NAME__'"
176
+        echo "  x_MKIT_PROJ_CODENAME__ => '__MKIT_PROJ_CODENAME__'"
177
+        echo "  x_MKIT_PROJ_LICENSE__ => '__MKIT_PROJ_LICENSE__'"
178
+        echo "  x_MKIT_PROJ_PKGNAME__ => '__MKIT_PROJ_PKGNAME__'"
179
+        echo "  x_MKIT_PROJ_TAGLINE__ => '__MKIT_PROJ_TAGLINE__'"
180
+        echo "  x_MKIT_PROJ_MAINTAINER__ => '__MKIT_PROJ_MAINTAINER__'"
181
+        echo "  x_MKIT_PROJ_VCS_BROWSER__ => '__MKIT_PROJ_VCS_BROWSER__'"
182
+        echo "  x_MKIT_PROJ_GIT_LASTHASH__ => '__MKIT_PROJ_GIT_LASTHASH__'"
183
+        echo "  x_MKIT_PROJ_VERSION__ => '__MKIT_PROJ_VERSION__'"
184
+        echo "  x_MKIT_SELF_VERSION__ => '__MKIT_SELF_VERSION__'"
185
+        for section in "${sections[@]}"; do
186
+            echo "$section:"
187
+            for macro in $(ini lskeys "$section"); do
188
+                echo "  x${macro:1} => '$macro'"
189
+            done
190
+        done
191
+    } \
192
+      | __expand_macros "MKIT_BUILTIN" "${sections[@]}" \
193
+      | sed '/^  x/ s|x|_|'
194
+}
195
+
196
+build() {
197
+    #
198
+    # Add meat to all skeletons
199
+    #
200
+    local srcpath   # each source path
201
+    find . -type f -name '*.skel' \
202
+     | while read -r srcpath; do
203
+           __build1 "$srcpath"
204
+       done
205
+}
206
+
207
+clean() {
208
+    #
209
+    # Clean up tree after building
210
+    #
211
+    test -f "$MKIT_LOCAL/built.lst" && {
212
+        <"$MKIT_LOCAL/built.lst" grep -v -e '\.\.' -e ^/ \
213
+          | xargs -r rm -rf
214
+        rm -f "$MKIT_LOCAL/built.lst"
215
+        rmdir --ignore-fail-on-non-empty "$MKIT_LOCAL"
216
+    }
217
+    true
218
+}
219
+
220
+debstuff() {
221
+    #
222
+    # Build Debian stuff (eamed tarball, debian dir)
223
+    #
224
+    local version       # package version
225
+    local debian_skel   # 'debian' folder skeleton
226
+    local dfsrc         # each source file from ^^
227
+    local dftgt         # each built packaging file
228
+    version=$(__cached semver)
229
+
230
+    # tarball - we should already have by means of 'dist'
231
+    #
232
+    mv "${MKIT_PROJ_PKGNAME}-$version.tar.gz" \
233
+       "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz" \
234
+     || die "could not rename tarball"
235
+    __rec_built "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz"
236
+
237
+    # read content of each mandatory file from debian_skel
238
+    #
239
+    debian_skel=$(ini 1value dist:debstuff)
240
+    test -n "$debian_skel" || die "dist:debstuff not specified"
241
+    test -d "$debian_skel" || die "debian directory template found: $debian_skel"
242
+    mkdir -p debian/source
243
+    find "$debian_skel" -type f \
244
+      | while read -r dfsrc; do
245
+            dftgt="debian/${dfsrc#$debian_skel}"
246
+            mkdir -p "$(dirname "$dftgt")"
247
+            __build1 "$dfsrc" "$dftgt" debstuff
248
+        done
249
+    __rec_built debian
250
+}
251
+
252
+dist() {
253
+    #
254
+    # Create distributable tarball
255
+    #
256
+    #FIXME: lacking Makefile skills, we do this step twice for
257
+    #       rpmstuff, hence -f hack for gzip
258
+    #
259
+    local version           # tarball version
260
+    local git_lasthash      # last git commit hash
261
+    local dirname           # directory and tarball name
262
+    version=$(semver)
263
+    dirname=$MKIT_PROJ_PKGNAME-$version
264
+    git_lasthash=$(git_lasthash)
265
+    mkdir -p "$dirname"
266
+    ini values "dist:tarball" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
267
+    mkdir -p "$dirname/.mkit"
268
+    echo -n "$version" > "$dirname/.mkit/semver"
269
+    echo -n "$git_lasthash" > "$dirname/.mkit/git_lasthash"
270
+    tar -cf "$dirname.tar" "$dirname"
271
+    gzip -f "$dirname.tar"      # see above FIXME
272
+    __rec_built "$dirname.tar.gz"
273
+    rm -rf "$dirname"
274
+}
275
+
276
+rpmstuff() {
277
+    #
278
+    # Build specfile
279
+    #
280
+    local specname=$MKIT_PROJ_PKGNAME.spec      # .spec filename
281
+    local specsrc                               # source of specfile
282
+    specsrc="$(ini 1value "dist:rpmstuff")"
283
+    test -n "$specsrc" || die "dist:rpmstuff not specified"
284
+    test -f "$specsrc" || die "specfile template not found: $specsrc"
285
+    __build1 "$specsrc" "$specname" rpmstuff
286
+}

+ 130
- 0
utils/mkit/include/deploy.sh View File

@@ -0,0 +1,130 @@
1
+#!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
5
+mkit_import ini
6
+
7
+__deploy_item() {
8
+    #
9
+    # Deploy item and make it look like wanted
10
+    #
11
+    # usage: __deploy_item src dst [mode]
12
+    #
13
+    # Both src and dst must be names of actual items[1],
14
+    # whereas dst must not exist.  On update, dst is
15
+    # usually to be replaced but that is uninstall's
16
+    # job!
17
+    #
18
+    #  [1] Ie. src=foo and dst=/foo/bar does *always*
19
+    #      mean that foo will become 'bar'.  This is
20
+    #      different than traditional `cp` behavior,
21
+    #      when this depends if 'bar' already exists
22
+    #      as a directory.
23
+    #
24
+    # If mode is omitted or empty, MKIT_DEFAULT_MODE is
25
+    # used instead.
26
+    #
27
+    # Directories are copied recursively, and mode is
28
+    # applied only to files.
29
+    #
30
+    local src=$1                            # source path
31
+    local dst=$2                            # destination path
32
+    local mode=${3:-$MKIT_DEFAULT_MODE}     # mode
33
+    local item                              # each in directory
34
+    if test -d "$src"; then
35
+        find "$src" -type f \
36
+          | while read -r item; do
37
+                [[ $item =~ .skel$ ]] \
38
+                 && grep -q "${item%.skel}" "$MKIT_LOCAL/built.lst" \
39
+                 && continue
40
+                __deploy_item "$item" "$dst${item#$src}" "$mode"
41
+            done
42
+    else
43
+        test "$mode" == "SRC" && mode=$(stat -c "%a" "$src")
44
+        __maybe install -DTvm "$mode" "$src" "$dst"
45
+    fi
46
+}
47
+
48
+__get_dst() {
49
+    #
50
+    # Find out target path for src file $2 of group $1
51
+    #
52
+    local grp=$1        # deploy group
53
+    local src=$2        # each source
54
+    local dst=$3        # alternative destination name
55
+    test -n "$dst" || dst=${src##*/}
56
+    echo "$(__get_root "$grp")/$dst"
57
+}
58
+
59
+__get_root() {
60
+    #
61
+    # Find out target root for group $1
62
+    #
63
+    local grp=$1        # deploy group
64
+    local root          # root for this group
65
+    local destdir       # value of DESTDIR
66
+    root=$(ini 1value "roots:$grp")
67
+    destdir=$(ini 1value ENV:DESTDIR)
68
+    destdir=${destdir%/}
69
+    case $destdir:$root in
70
+        *:)     die "missing in config.ini: roots:$grp" ;;
71
+        :*)     echo "$root" ;;
72
+        *:*)    echo "$destdir/$root" ;;
73
+    esac
74
+}
75
+
76
+__maybe() {
77
+    #
78
+    # Call the deploy command $1 $@ unless in dry mode
79
+    #
80
+    debug "$@"
81
+    local cmd="$1"; shift
82
+    $MKIT_DRY && return
83
+    case "$cmd" in
84
+        cp|rm|rmdir|chmod|mkdir) $cmd "$@" ;;
85
+        install)                 command -p install "$@" ;;
86
+        *)                       die "bad command called";;
87
+    esac
88
+}
89
+
90
+install() {
91
+    #
92
+    # Install product
93
+    #
94
+    local group     # each deploy group
95
+    local mode      # mode (group-specific)
96
+    local src       # each source path
97
+    local dst       # each (final absolute) destination path
98
+    ini lskeys "files" \
99
+      | sort \
100
+      | uniq \
101
+      | while read -r group; do
102
+            mode=$(ini 1value "modes:$group")
103
+            ini values "files:$group" \
104
+              | while read -r src dst; do
105
+                    dst=$(__get_dst "$group" "$src" "$dst")
106
+                    __deploy_item "$src" "$dst" "$mode"
107
+                done
108
+        done
109
+    test -f "$MKIT_LOCAL/autoclean" && clean
110
+    true
111
+}
112
+
113
+uninstall() {
114
+    #
115
+    # Uninstall product
116
+    #
117
+    local group     # each deploy group
118
+    local src       # each source path
119
+    local dst       # each (final absolute) destination path
120
+    ini lskeys "files" \
121
+      | sort \
122
+      | uniq \
123
+      | while read -r group; do
124
+            ini values "files:$group" \
125
+              | while read -r src dst; do
126
+                    dst=$(__get_dst "$group" "$src" "$dst")
127
+                    __maybe rm -vrf "$dst"
128
+                done
129
+        done
130
+}

+ 175
- 0
utils/mkit/include/facts.sh View File

@@ -0,0 +1,175 @@
1
+#!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
5
+mkit_import ini
6
+
7
+git_bool() {
8
+    #
9
+    # Get git bool (ie. exit status counts) $1
10
+    #
11
+    local bool_name=$1      # name of boolean to get
12
+    git_present || warn "can't give bool outside git repo: $bool_name"
13
+    case "$bool_name" in
14
+        dirty_files)
15
+            git diff-files | grep -qm 1 .
16
+            ;;
17
+        dirty_index)
18
+            git diff-index HEAD | grep -qm 1 .
19
+            ;;
20
+        dirty)
21
+            git_bool dirty_files || git_bool dirty_index
22
+            ;;
23
+        *)
24
+            warn "unknown git bool asked: $bool_name"
25
+            return 2
26
+            ;;
27
+    esac
28
+}
29
+
30
+git_fact() {
31
+    #
32
+    # Get git fact $1
33
+    #
34
+    local fact_name=$1      # name of fact to get
35
+    git_present || warn "can't give fact outside git repo: $fact_name"
36
+    case "$fact_name" in
37
+        latest_tag)
38
+            git log --format="%d" \
39
+              | sed 's/,/\n/g' \
40
+              | sed 's/^[[:blank:]]*//' \
41
+              | grep -E '^\(?tag' \
42
+              | tr -cd '[[:digit:]].v\n' \
43
+              | grep . -m 1
44
+            ;;
45
+        latest_version)
46
+            git_fact latest_tag | git_tag2ver
47
+            ;;
48
+        current_branch)
49
+            git rev-parse --abbrev-ref HEAD
50
+            ;;
51
+        reldiff)
52
+            git log --oneline "$(git_fact latest_tag)..HEAD" --name-only
53
+            ;;
54
+        latest_sha)
55
+            git log -1 --pretty=format:%h HEAD
56
+            ;;
57
+        *)
58
+            warn "unknown git fact asked: $fact_name"
59
+            ;;
60
+    esac
61
+}
62
+
63
+git_present() {
64
+    #
65
+    # True if we're in a git repo
66
+    #
67
+    git rev-parse HEAD >&/dev/null
68
+}
69
+
70
+git_tag2ver() {
71
+    #
72
+    # Convert tag to version
73
+    #
74
+    sed s/^v//
75
+}
76
+
77
+git_ver2tag() {
78
+    #
79
+    # Convert version to tag
80
+    #
81
+    sed s/^/v/
82
+}
83
+
84
+git_lasthash() {
85
+    #
86
+    # Show last commit hash (with .dirty suffix if needed)
87
+    #
88
+    # We can't do it outside git repo (or without git) but we should
89
+    # not be asked to; targets that don't require git should make use
90
+    # of cache built by dist target.
91
+    #
92
+    local last_hash     # last commit hash
93
+    git_present || {
94
+        echo UNKNOWN_HASH
95
+        warn "no git present; could not determine last hash"
96
+        return 3
97
+    }
98
+    last_hash=$(git rev-parse HEAD)
99
+    echo -n "$last_hash"
100
+    git_bool dirty && echo -n ".dirty"
101
+}
102
+
103
+semver() {
104
+    #
105
+    # Build proper SemVer version string
106
+    #
107
+    # Build version string from available info using following
108
+    # logic:
109
+    #
110
+    #  1. Use version from last git tag (or mkit.ini if there is no
111
+    #     tag, which is possible on new project)
112
+    #  2. if set, add project:prerl (from mkit.ini) as pre-release ID
113
+    #     (afer dash)
114
+    #  3. if we are at a later commit than the last tag, add branch
115
+    #     name and commit sha1 to build metadata (after plus sign)
116
+    #  4. if the tree is "dirty", i.e. has uncommited changes,
117
+    #     add "dirty" to build metadata
118
+    #
119
+    # The version is compatible with SemVer 2.0.0.
120
+    #
121
+    # Examples:
122
+    #
123
+    #     foo v1.0.7                            # all clear; proper release
124
+    #     foo v1.0.7-beta                       # mkit.ini: project:prerl="beta"
125
+    #     foo v1.0.7-beta+g1aef811.master       # ^^ + some commits after
126
+    #     foo v1.0.7-beta+gf14fc4f.api2         # ^^ + on a feature branch
127
+    #     foo v1.0.7-beta+gf14fc4f.api2.dirty   # ^^ + tree edited
128
+    #     foo v1.0.7-beta+dirty                 # tag OK but tree edited
129
+    #     foo v1.0.7+dirty                      # ^^ but no pre-release id
130
+    #
131
+    # Note that versions with "dirty" should be perceived as kind of
132
+    # dangerous outside developer's own machine.  Versions with sha1 are
133
+    # safer but must not be released.
134
+    #
135
+    # FIXME:  Using project:prerl for release IDs may not be compatible with
136
+    #         release strategy implemented in release.sh
137
+    #
138
+    local xyz           # base version string
139
+    local prerl         # pre-release keyword (from mkit.ini, eg. 'beta')
140
+    local latest_tag    # latest git tag
141
+    local commit        # commit indicator (CURRENT_BRANCH.gHASH)
142
+    local dirty         # 0 if dirty, 1 if clean
143
+    local suffix        # version suffix
144
+    prerl=$(ini 1value project:prerl)
145
+    grep ":" <<<"$prerl" \
146
+     && warn "colon in project:prerl may corrupt version data: $prerl"
147
+    git_present || {
148
+        echo UNKNOWN_VERSION
149
+        warn "no git present; could not determine SemVer"
150
+        return 3
151
+    }
152
+    latest_tag=$(git_fact latest_tag)
153
+    case $latest_tag in
154
+        v*) xyz=${latest_tag:1} ;;
155
+        "") warn "no tags, using base version from mkit.ini (ok for new project)"
156
+            xyz=$(ini 1value project:version) ;;
157
+        *)  warn "bad form of last tag, using base version from mkit.ini: tag is '$latest_tag'"
158
+            xyz=$(ini 1value project:version) ;;
159
+    esac
160
+    if ! git describe --tags --exact-match HEAD >&/dev/null;
161
+    then    # we are at a later commit than the last tag
162
+        commit="$(git_fact current_branch).g$(git_fact latest_sha)"
163
+    fi
164
+    git_bool dirty; dirty=$?
165
+    case "$dirty:$commit" in
166
+        1:)  suffix=""               ;;
167
+        0:)  suffix="+dirty"         ;;
168
+        1:*) suffix="+$commit"       ;;
169
+        0:*) suffix="+$commit.dirty" ;;
170
+        *)   suffix=MKIT_BUG
171
+             warn "MKIT_BUG: bad dirt/commit detection" ;;
172
+    esac
173
+    test -n "$prerl" && suffix="-$prerl$suffix"
174
+    echo "$xyz$suffix"
175
+}

+ 178
- 0
utils/mkit/include/ini.sh View File

@@ -0,0 +1,178 @@
1
+#!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
5
+__ini_cat() {
6
+    #
7
+    # A no-op for text stream
8
+    #
9
+    local line      # each line
10
+    while read -r line; do
11
+        printf -- "%s\n" "$line"
12
+    done
13
+}
14
+
15
+__ini_expand() {
16
+    #
17
+    # Expand reference value (prefix only)
18
+    #
19
+    local line      # each input line
20
+    local suffix    # tail of the line
21
+    local ref       # reference
22
+    local value     # value if reference
23
+    while read -r line; do                  # [foo:bar]/path
24
+        suffix="${line#\[*\]}"              # /path
25
+        ref="${line%$suffix}"               # [foo:bar]
26
+        ref="${ref%\]}"                     # [foo:bar
27
+        ref="${ref#\[}"                     # foo:bar
28
+        value="$(ini 1value "$ref")"        # foo_bar_value
29
+        printf -- "%s\n" "$value$suffix"    # foo_bar_value/path
30
+    done
31
+}
32
+
33
+__ini_grepcmt() {
34
+    #
35
+    # Remove comments from INI file on stdin
36
+    #
37
+    grep -v '^[[:space:]]*#'
38
+}
39
+
40
+__ini_grepkey() {
41
+    #
42
+    # Read key from a section
43
+    #
44
+    local wnt=$1    # wanted key
45
+    grep '.' \
46
+      | sed -e 's/ *= */=/; s/ +$//; s/^//;' \
47
+      | grep -e "^$wnt=" \
48
+      | cut -d= -f2- \
49
+      | __ini_maybe_expand
50
+}
51
+
52
+__ini_greppath() {
53
+    #
54
+    # Read key from the right section
55
+    #
56
+    # E.g. `files:share:my/lib.sh` should read
57
+    #
58
+    #     [files:share]
59
+    #         my/lib.sh   = proj/my/lib.sh
60
+    #
61
+    local wnt=$1                    # wanted path
62
+    local wntkey=${wnt##*:}         # ^^ key part
63
+    local wntsec=${wnt%:$wntkey}    # ^^ section part
64
+    local override                  # ENV override (only ENV section)
65
+    if test "$wntsec" = 'ENV'; then
66
+        override=${!wntkey}
67
+        test -n "$override" \
68
+         && echo "$override" \
69
+         && return
70
+    fi
71
+    __ini_grepsec "$wntsec" | __ini_grepkey "$wntkey"
72
+}
73
+
74
+__ini_grepsec() {
75
+    #
76
+    # Read one INI section
77
+    #
78
+    local wnt=$1        # wanted section name
79
+    local ok=false      # are we in the section?
80
+    local line          # each input line
81
+    grep '.' \
82
+      | grep -v '\s*#' \
83
+      | while read -r line; do
84
+            case "$line" in
85
+                \[$wnt\]) ok=true;  continue ;;
86
+                \[*\])    ok=false; continue ;;
87
+            esac
88
+            $ok || continue
89
+            printf -- "%s\n" "$line"
90
+        done \
91
+      | sed -e 's/ *= */=/; s/ +$//; s/^//;'
92
+}
93
+
94
+__ini_lskeys() {
95
+    #
96
+    # List keys from a section
97
+    #
98
+    local sct=$1    # section of interest
99
+    __ini_grepsec "$sct" | cut -d= -f1 | awk '!x[$0]++'
100
+}
101
+
102
+__ini_lssect() {
103
+    #
104
+    # List all section names
105
+    #
106
+    local arg=$1    # unused argument
107
+    grep -x '\[.*\]' | sed 's/^.//; s/.$//'
108
+}
109
+
110
+__ini_maybe_expand() {
111
+    #
112
+    # Decide whether or not to expand
113
+    #
114
+    if test "$MKIT_INI_EXPAND" -gt 0; then
115
+        MKIT_INI_EXPAND=$(( --MKIT_INI_EXPAND )) __ini_expand
116
+    else
117
+        __ini_cat
118
+    fi
119
+}
120
+
121
+__ini_body() {
122
+    #
123
+    # Produce mkit.ini body including INCLUDE
124
+    #
125
+    # Note: recursive includes are not supported.
126
+    #
127
+    local inc                       # file to include
128
+    local incre='\[INCLUDE:.*\]'    # include directive regex
129
+    local iline                     # include directive line
130
+    if iline=$(grep -m1 -x "$incre" "$MKIT_INI"); then
131
+        inc=${iline#*:}; inc=${inc%]}
132
+        grep -vx "$incre" "$inc"
133
+        grep -vx "$incre" "$MKIT_INI"
134
+    else
135
+        cat "$MKIT_INI"
136
+    fi | __ini_grepcmt
137
+}
138
+
139
+ini() {
140
+    #
141
+    # do ini operation
142
+    #
143
+    local op=$1             # operator
144
+    local arg=$2            # argument
145
+    local fn                # internal function implementing $op
146
+    local limit=__ini_cat    # limiting internal function
147
+    case $op in
148
+        lskeys) fn=__ini_lskeys   ;;
149
+        lssect) fn=__ini_lssect   ;;
150
+        sec)    fn=__ini_grepsec  ;;
151
+        values) fn=__ini_greppath ;;
152
+        1value) fn=__ini_greppath; limit="tail -1" ;;
153
+        *)      die "incorrect use of \`ini()\`"
154
+    esac
155
+    __ini_body | $fn "$arg" | $limit
156
+}
157
+
158
+update_version() {
159
+    #
160
+    # Change project:version in mkit.ini at path $2 to value $1
161
+    #
162
+    local version=$1    # new version
163
+    local inifile=$2    # mkit.ini path
164
+    local tmp           # mkit.ini cache
165
+    tmp=$(mktemp -t mkit.update_version.XXXXXXXX)
166
+    <"$inifile" perl -e '
167
+        my $hit = 0;
168
+        my $done = 0;
169
+        foreach (<STDIN>) {
170
+            if      ($done) { print; next; }
171
+            elsif   (m/\[project\]/) { $hit++; print; next; }
172
+            elsif   (m/\[/) { $hit = 0; print; next; }
173
+            elsif   ($hit) { s/\bversion\b( *)=( *).*/version$1=$2$ARGV[0]/ and $done++; print; }
174
+            else { print; next; }
175
+        }
176
+    ' "$version" >"$tmp" || die "failed to update version in mkit.ini"
177
+    mv "$tmp" "$inifile"
178
+}

+ 162
- 0
utils/mkit/include/mkit.sh View File

@@ -0,0 +1,162 @@
1
+#!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
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
32
+
33
+__valid_targets() {
34
+    #
35
+    # List valid routes
36
+    #
37
+    echo _mkit_data
38
+    echo build
39
+    echo clean
40
+    echo debstuff
41
+    echo dist
42
+    echo install
43
+    echo release
44
+    echo release_x
45
+    echo release_y
46
+    echo release_z
47
+    echo rpmstuff
48
+    echo uninstall
49
+    echo vbump
50
+    echo vbump_x
51
+    echo vbump_y
52
+    echo vbump_z
53
+}
54
+
55
+debug() {
56
+    #
57
+    # Print debug message
58
+    #
59
+    $MKIT_DEBUG || return 0
60
+    echo "MKIT_DEBUG: ${FUNCNAME[1]}()" "$@" >&2
61
+}
62
+
63
+debug_var() {
64
+    #
65
+    # Print debug message
66
+    #
67
+    $MKIT_DEBUG || return 0
68
+    local __mkit_debug_var_name__       # variable name to debug
69
+    local decl                          # declare string
70
+    for __mkit_debug_var_name__ in "$@"; do
71
+        {
72
+            decl=$(declare -p "$__mkit_debug_var_name__")
73
+            decl=${decl#declare ?? }
74
+            echo "MKIT_DEBUG: ${FUNCNAME[1]}(): $decl"
75
+        } >&2
76
+    done
77
+}
78
+
79
+__compver() {
80
+    #
81
+    # True if version $1 matches our version
82
+    #
83
+    # If our x is 0, check first two fragments, otherwise check just
84
+    # the x.  Fragments must equal.
85
+    #
86
+    local their_ver=$1      # their version
87
+    local our_x             # our X
88
+    local our_y             # our Y
89
+    local their_x           # their X
90
+    local their_y           # their Y
91
+    their_x=${their_ver%%.*}
92
+    their_y=${their_ver##$their_x.}
93
+    their_y=${their_y%%.*}
94
+    our_x=${MKIT_VERSION%%.*}
95
+    our_y=${MKIT_VERSION##$our_x.}
96
+    our_y=${our_y%%.*}
97
+    debug_var MKIT_VERSION our_x our_y their_ver their_x their_y
98
+    test "$their_x" -eq "$our_x" || return 1
99
+    test "$our_x" -eq 0 && {
100
+        test "$their_y" = "$our_y"
101
+        return $?
102
+    }
103
+    return 0
104
+}
105
+
106
+__chkiniversion() {
107
+    #
108
+    # Check if ini version is supported
109
+    #
110
+    # Look for "#mkit version=0.0.0" or similar in first or last
111
+    # 3 lines of the file; then check if the version is supported.
112
+    #
113
+    local ver_line      # line declaring version
114
+    local their_ver     # the declared version
115
+    ver_line=$(
116
+        {
117
+            head -3 "$MKIT_INI"
118
+            tail -3 "$MKIT_INI"
119
+        } | grep -m 1 -E '^# *mkit +version *= *v?[0-9]+\.[0-9]+\.[0-9]+'
120
+    )
121
+    test -n "$ver_line" \
122
+     || die "version mark ('#mkit version=x.y.z') not found in: $MKIT_INI"
123
+    their_ver="$(tr -d '[:blank:]v' <<<"${ver_line##*=}")"
124
+    __compver "$their_ver" \
125
+     || die "bad mkit.ini version: $their_ver does not match $MKIT_VERSION"
126
+}
127
+
128
+mkit_init() {
129
+    #
130
+    # Do basic initialization
131
+    #
132
+    # Check for ini file and some variables
133
+    #
134
+    $MKIT_DRY && MKIT_DEBUG=true
135
+    #shellcheck disable=SC2034
136
+    MKIT_PROJ_PKGNAME=$(ini 1value "project:pkgname")
137
+    test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
138
+    __chkiniversion
139
+}
140
+
141
+route() {
142
+    #
143
+    # Call correct function based on $1
144
+    #
145
+    if __valid_targets | grep -qwx "^$1"; then
146
+        "$1"
147
+    else
148
+        {
149
+            echo "usage: $(basename "$0") TARGET"
150
+            echo
151
+            echo "valid targets:"
152
+            __valid_targets | sed 's/^/    /'
153
+        } >&2
154
+    fi
155
+}
156
+
157
+warn() {
158
+    #
159
+    # Print warning message
160
+    #
161
+    echo "$@" >&2
162
+}

+ 232
- 0
utils/mkit/include/release.sh View File

@@ -0,0 +1,232 @@
1
+#!/bin/bash
2
+# MKit - simple install helper
3
+# See LICENSE file for copyright and license details.
4
+
5
+mkit_import ini
6
+mkit_import facts
7
+
8
+__bump_version() {
9
+    #
10
+    # Bump version on stdin by level $1 (x, y or z)
11
+    #
12
+    local rlevel=$1     # release level
13
+    local old           # old version
14
+    local oldx          # ... X
15
+    local oldz          # ... Z
16
+    local oldy          # ... Y
17
+    local tmpy          # Y parsing cache
18
+    local new           # bumped version
19
+    read -r old
20
+    oldx=${old%.*.*}
21
+    oldz=${old#*.*.}
22
+    tmpy=${old%.*}
23
+    oldy=${tmpy#*.}
24
+    case $rlevel in
25
+        x) new="$((oldx+MKIT_BUMPSIZE)).0.0"            ;;
26
+        y) new="$oldx.$((oldy+MKIT_BUMPSIZE)).0"        ;;
27
+        z) new="$oldx.$oldy.$((oldz+MKIT_BUMPSIZE))"    ;;
28
+        *) die "invalid release level: $1"  ;;
29
+    esac
30
+    echo "$new"
31
+}
32
+
33
+__relck() {
34
+    #
35
+    # Die if blocking condition $1 is detected
36
+    #
37
+    local condition=$1      # condition name
38
+    local oracle            # expected value
39
+    case "$condition" in
40
+        git_present)
41
+            git rev-parse HEAD >&/dev/null\
42
+             || die "cannot do this outside git repo"
43
+            ;;
44
+        at_relsrc)
45
+            oracle=$(ini 1value project:relsrc)
46
+            git_fact current_branch \
47
+              | grep -qFx "$oracle" \
48
+             || die "you are not on release source branch: $oracle"
49
+            ;;
50
+        not_dirty)
51
+            git diff --shortstat 2>/dev/null \
52
+              | grep -q . \
53
+             && die "tree is dirty!"
54
+            ;;
55
+        tags_ok)
56
+            git_fact latest_tag \
57
+              | grep -q . \
58
+             || die "cannot find latest tag"
59
+            ;;
60
+        vbump_hot)
61
+            git diff-tree --no-commit-id --name-only -r HEAD \
62
+              | grep -qFx mkit.ini \
63
+             || die "last change must be version bump in mkit.ini"
64
+            ;;
65
+        no_wip)
66
+            git_fact reldiff \
67
+              | grep '^....... WIP ' \
68
+             && die "WIP commit since $(git_fact latest_tag)"
69
+            ;;
70
+        ini_version)
71
+            oracle=$(git_fact latest_version | __bump_version "$rlevel")
72
+            ini 1value project:version  \
73
+              | grep -qFx "$oracle" \
74
+             || die "new version not in mkit.ini: $oracle"
75
+            ;;
76
+        *)
77
+            die "unknown release check: $condition"
78
+            ;;
79
+    esac
80
+}
81
+
82
+__release() {
83
+    #
84
+    # Prepare release
85
+    #
86
+    # Span release routines: make a signed tag, check branch
87
+    # and update release branch
88
+    #
89
+    # FIXME: Using project:prerl as build.sh:semver() does may not be
90
+    #        compatible with this release strategy
91
+    #
92
+    local rlevel=$1     # release level (x, y or z)
93
+    local newtag        # new tag
94
+    local relsrc        # release source branch (if any)
95
+    local reldst        # release destination branch (if any)
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
104
+
105
+    newtag=$(git_fact latest_version | __bump_version "$rlevel" | git_ver2tag )
106
+    set -e
107
+    debug_var newtag
108
+    $MKIT_DRY && return
109
+    git tag -m "$(__release_msg)" "$newtag"
110
+
111
+    relsrc=$(ini 1value project:relsrc)
112
+    reldst=$(ini 1value project:reldst)
113
+    debug_var relsrc reldst
114
+    if test -n "$reldst" && test "$reldst" != "$relsrc"; then
115
+        git branch -f "$reldst" "$newtag"
116
+    fi
117
+}
118
+
119
+__release_msg() {
120
+    #
121
+    # Generate message for annotated tag
122
+    #
123
+    # The last commit before issuing a release must be "Bump version" commit
124
+    # suggested by _vbump_gitmsg() and  manually edited by user.  Since the
125
+    # commit contains changelog, this function just uses the message body.
126
+    #
127
+    # The sort message (first line) is replaced with a nicer one (with project
128
+    # name, codename and version).
129
+    #
130
+    echo "$(ini 1value project:name) $newtag - $(ini 1value project:codename)"
131
+    echo
132
+    git show -s --format=%B \
133
+      | tail -n +3
134
+}
135
+
136
+__vbump() {
137
+    #
138
+    # Do version bump at level $1
139
+    #
140
+    # Perform checks, compute new version, update mkit.ini and initiate
141
+    # 'Bump version' commit with changelog template.
142
+    #
143
+    local rlevel=$1     # bump level (x, y or z)
144
+    local nextver       # version after the bump
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")
150
+    debug_var nextver
151
+    $MKIT_DRY && return
152
+    update_version "$nextver" mkit.ini \
153
+      || die "failed to update version in mkit.ini"
154
+    git add mkit.ini \
155
+      || die "failed to add mkit.ini to the index"
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"
160
+}
161
+
162
+_vbump_gitmsg() {
163
+    #
164
+    # Compose git message template for 'Bump version' commit
165
+    #
166
+    echo "Bump version"
167
+    echo ""
168
+    echo "Overview of changes:"
169
+    echo ""
170
+    git_fact reldiff \
171
+      | sed '
172
+            s/^[a-f0-9]\{7\} /\n *  &/; t PATHS
173
+            s/^/        /
174
+            :PATHS
175
+        '
176
+}
177
+
178
+release() {
179
+    #
180
+    # Perform release on Z level
181
+    #
182
+    __release z
183
+}
184
+
185
+release_x() {
186
+    #
187
+    # Perform release on X level
188
+    #
189
+    __release x
190
+}
191
+
192
+release_y() {
193
+    #
194
+    # Perform release on Y level
195
+    #
196
+    __release y
197
+}
198
+
199
+release_z() {
200
+    #
201
+    # Perform release on Z level
202
+    #
203
+    __release z
204
+}
205
+
206
+vbump() {
207
+    #
208
+    # Perform version bump on Z level
209
+    #
210
+    __vbump z
211
+}
212
+
213
+vbump_x() {
214
+    #
215
+    # Perform version bump on X level
216
+    #
217
+    __vbump x
218
+}
219
+
220
+vbump_y() {
221
+    #
222
+    # Perform version bump on Y level
223
+    #
224
+    __vbump y
225
+}
226
+
227
+vbump_z() {
228
+    #
229
+    # Perform version bump on Z level
230
+    #
231
+    __vbump z
232
+}

+ 61
- 0
utils/mkit/include/vars.sh View File

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

+ 34
- 0
utils/mkit/make View File

@@ -0,0 +1,34 @@
1
+#!/bin/bash
2
+#shellcheck disable=SC2034
3
+# mkit - simple install helper
4
+# See LICENSE file for copyright and license details.
5
+
6
+init_core() {
7
+    #
8
+    # Load core module (or die)
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
16
+}
17
+
18
+#
19
+# Path to MKit dir (where 'include' is)
20
+#
21
+MKIT_DIR=${MKIT_DIR:-$(dirname "$0")}
22
+
23
+
24
+init_core
25
+
26
+case "$1" in
27
+    -V|--version-semver)    echo "$MKIT_VERSION"; exit 0 ;;
28
+    --version)              echo "Mkit (Simple Makefile target helper) $MKIT_VERSION"
29
+                            exit 0 ;;
30
+esac
31
+
32
+mkit_init
33
+
34
+route "$@"

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

@@ -0,0 +1,56 @@
1
+# mkit - Simple Makefile target helper
2
+# See LICENSE file for copyright and license details.
3
+
4
+export MKIT_DIR
5
+
6
+all: build
7
+
8
+_mkit_data:
9
+	@"$(MKIT_DIR)"/make _mkit_data
10
+
11
+build:
12
+	@"$(MKIT_DIR)"/make build
13
+
14
+clean:
15
+	@"$(MKIT_DIR)"/make clean
16
+
17
+debstuff: dist
18
+	@"$(MKIT_DIR)"/make debstuff
19
+
20
+dist: clean
21
+	@"$(MKIT_DIR)"/make dist
22
+
23
+rpmstuff: dist
24
+	@"$(MKIT_DIR)"/make rpmstuff
25
+
26
+install: all
27
+	@"$(MKIT_DIR)"/make install
28
+
29
+release:
30
+	@"$(MKIT_DIR)"/make release
31
+
32
+release_x:
33
+	@"$(MKIT_DIR)"/make release_x
34
+
35
+release_y:
36
+	@"$(MKIT_DIR)"/make release_y
37
+
38
+release_z:
39
+	@"$(MKIT_DIR)"/make release_z
40
+
41
+uninstall:
42
+	@"$(MKIT_DIR)"/make uninstall
43
+
44
+vbump:
45
+	@"$(MKIT_DIR)"/make vbump
46
+
47
+vbump_x:
48
+	@"$(MKIT_DIR)"/make vbump_x
49
+
50
+vbump_y:
51
+	@"$(MKIT_DIR)"/make vbump_y
52
+
53
+vbump_z:
54
+	@"$(MKIT_DIR)"/make vbump_z
55
+
56
+.PHONY: all _mkit_data clean dist rpmstuff install uninstall release release_x release_y release_z vbump vbump_x vbump_y vbump_z

+ 715
- 0
utils/mkit/stub View File

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