Alois Mahdal 10 anni fa
commit
58786d1bb8

+ 3
- 0
.gitignore Vedi File

@@ -0,0 +1,3 @@
1
+.mkit/autoclean
2
+saturnin-demo-*.tar.gz
3
+artifacts

+ 344
- 0
LICENSE Vedi File

@@ -0,0 +1,344 @@
1
+		    GNU GENERAL PUBLIC LICENSE
2
+		       Version 2, June 1991
3
+
4
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
5
+                       51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
6
+ Everyone is permitted to copy and distribute verbatim copies
7
+ of this license document, but changing it is not allowed.
8
+
9
+			    Preamble
10
+
11
+  The licenses for most software are designed to take away your
12
+freedom to share and change it.  By contrast, the GNU General Public
13
+License is intended to guarantee your freedom to share and change free
14
+software--to make sure the software is free for all its users.  This
15
+General Public License applies to most of the Free Software
16
+Foundation's software and to any other program whose authors commit to
17
+using it.  (Some other Free Software Foundation software is covered by
18
+the GNU Library General Public License instead.)  You can apply it to
19
+your programs, too.
20
+
21
+  When we speak of free software, we are referring to freedom, not
22
+price.  Our General Public Licenses are designed to make sure that you
23
+have the freedom to distribute copies of free software (and charge for
24
+this service if you wish), that you receive source code or can get it
25
+if you want it, that you can change the software or use pieces of it
26
+in new free programs; and that you know you can do these things.
27
+
28
+  To protect your rights, we need to make restrictions that forbid
29
+anyone to deny you these rights or to ask you to surrender the rights.
30
+These restrictions translate to certain responsibilities for you if you
31
+distribute copies of the software, or if you modify it.
32
+
33
+  For example, if you distribute copies of such a program, whether
34
+gratis or for a fee, you must give the recipients all the rights that
35
+you have.  You must make sure that they, too, receive or can get the
36
+source code.  And you must show them these terms so they know their
37
+rights.
38
+
39
+  We protect your rights with two steps: (1) copyright the software, and
40
+(2) offer you this license which gives you legal permission to copy,
41
+distribute and/or modify the software.
42
+
43
+  Also, for each author's protection and ours, we want to make certain
44
+that everyone understands that there is no warranty for this free
45
+software.  If the software is modified by someone else and passed on, we
46
+want its recipients to know that what they have is not the original, so
47
+that any problems introduced by others will not reflect on the original
48
+authors' reputations.
49
+
50
+  Finally, any free program is threatened constantly by software
51
+patents.  We wish to avoid the danger that redistributors of a free
52
+program will individually obtain patent licenses, in effect making the
53
+program proprietary.  To prevent this, we have made it clear that any
54
+patent must be licensed for everyone's free use or not licensed at all.
55
+
56
+  The precise terms and conditions for copying, distribution and
57
+modification follow.
58
+
59
+		    GNU GENERAL PUBLIC LICENSE
60
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
61
+
62
+  0. This License applies to any program or other work which contains
63
+a notice placed by the copyright holder saying it may be distributed
64
+under the terms of this General Public License.  The "Program", below,
65
+refers to any such program or work, and a "work based on the Program"
66
+means either the Program or any derivative work under copyright law:
67
+that is to say, a work containing the Program or a portion of it,
68
+either verbatim or with modifications and/or translated into another
69
+language.  (Hereinafter, translation is included without limitation in
70
+the term "modification".)  Each licensee is addressed as "you".
71
+
72
+Activities other than copying, distribution and modification are not
73
+covered by this License; they are outside its scope.  The act of
74
+running the Program is not restricted, and the output from the Program
75
+is covered only if its contents constitute a work based on the
76
+Program (independent of having been made by running the Program).
77
+Whether that is true depends on what the Program does.
78
+
79
+  1. You may copy and distribute verbatim copies of the Program's
80
+source code as you receive it, in any medium, provided that you
81
+conspicuously and appropriately publish on each copy an appropriate
82
+copyright notice and disclaimer of warranty; keep intact all the
83
+notices that refer to this License and to the absence of any warranty;
84
+and give any other recipients of the Program a copy of this License
85
+along with the Program.
86
+
87
+You may charge a fee for the physical act of transferring a copy, and
88
+you may at your option offer warranty protection in exchange for a fee.
89
+
90
+  2. You may modify your copy or copies of the Program or any portion
91
+of it, thus forming a work based on the Program, and copy and
92
+distribute such modifications or work under the terms of Section 1
93
+above, provided that you also meet all of these conditions:
94
+
95
+    a) You must cause the modified files to carry prominent notices
96
+    stating that you changed the files and the date of any change.
97
+
98
+    b) You must cause any work that you distribute or publish, that in
99
+    whole or in part contains or is derived from the Program or any
100
+    part thereof, to be licensed as a whole at no charge to all third
101
+    parties under the terms of this License.
102
+
103
+    c) If the modified program normally reads commands interactively
104
+    when run, you must cause it, when started running for such
105
+    interactive use in the most ordinary way, to print or display an
106
+    announcement including an appropriate copyright notice and a
107
+    notice that there is no warranty (or else, saying that you provide
108
+    a warranty) and that users may redistribute the program under
109
+    these conditions, and telling the user how to view a copy of this
110
+    License.  (Exception: if the Program itself is interactive but
111
+    does not normally print such an announcement, your work based on
112
+    the Program is not required to print an announcement.)
113
+
114
+These requirements apply to the modified work as a whole.  If
115
+identifiable sections of that work are not derived from the Program,
116
+and can be reasonably considered independent and separate works in
117
+themselves, then this License, and its terms, do not apply to those
118
+sections when you distribute them as separate works.  But when you
119
+distribute the same sections as part of a whole which is a work based
120
+on the Program, the distribution of the whole must be on the terms of
121
+this License, whose permissions for other licensees extend to the
122
+entire whole, and thus to each and every part regardless of who wrote it.
123
+
124
+Thus, it is not the intent of this section to claim rights or contest
125
+your rights to work written entirely by you; rather, the intent is to
126
+exercise the right to control the distribution of derivative or
127
+collective works based on the Program.
128
+
129
+In addition, mere aggregation of another work not based on the Program
130
+with the Program (or with a work based on the Program) on a volume of
131
+a storage or distribution medium does not bring the other work under
132
+the scope of this License.
133
+
134
+  3. You may copy and distribute the Program (or a work based on it,
135
+under Section 2) in object code or executable form under the terms of
136
+Sections 1 and 2 above provided that you also do one of the following:
137
+
138
+    a) Accompany it with the complete corresponding machine-readable
139
+    source code, which must be distributed under the terms of Sections
140
+    1 and 2 above on a medium customarily used for software
141
+    interchange; or,
142
+
143
+    b) Accompany it with a written offer, valid for at least three
144
+    years, to give any third party, for a charge no more than your
145
+    cost of physically performing source distribution, a complete
146
+    machine-readable copy of the corresponding source code, to be
147
+    distributed under the terms of Sections 1 and 2 above on a medium
148
+    customarily used for software interchange; or,
149
+
150
+    c) Accompany it with the information you received as to the offer
151
+    to distribute corresponding source code.  (This alternative is
152
+    allowed only for noncommercial distribution and only if you
153
+    received the program in object code or executable form with such
154
+    an offer, in accord with Subsection b above.)
155
+
156
+The source code for a work means the preferred form of the work for
157
+making modifications to it.  For an executable work, complete source
158
+code means all the source code for all modules it contains, plus any
159
+associated interface definition files, plus the scripts used to
160
+control compilation and installation of the executable.  However, as a
161
+special exception, the source code distributed need not include
162
+anything that is normally distributed (in either source or binary
163
+form) with the major components (compiler, kernel, and so on) of the
164
+operating system on which the executable runs, unless that component
165
+itself accompanies the executable.
166
+
167
+If distribution of executable or object code is made by offering
168
+access to copy from a designated place, then offering equivalent
169
+access to copy the source code from the same place counts as
170
+distribution of the source code, even though third parties are not
171
+compelled to copy the source along with the object code.
172
+
173
+  4. You may not copy, modify, sublicense, or distribute the Program
174
+except as expressly provided under this License.  Any attempt
175
+otherwise to copy, modify, sublicense or distribute the Program is
176
+void, and will automatically terminate your rights under this License.
177
+However, parties who have received copies, or rights, from you under
178
+this License will not have their licenses terminated so long as such
179
+parties remain in full compliance.
180
+
181
+  5. You are not required to accept this License, since you have not
182
+signed it.  However, nothing else grants you permission to modify or
183
+distribute the Program or its derivative works.  These actions are
184
+prohibited by law if you do not accept this License.  Therefore, by
185
+modifying or distributing the Program (or any work based on the
186
+Program), you indicate your acceptance of this License to do so, and
187
+all its terms and conditions for copying, distributing or modifying
188
+the Program or works based on it.
189
+
190
+  6. Each time you redistribute the Program (or any work based on the
191
+Program), the recipient automatically receives a license from the
192
+original licensor to copy, distribute or modify the Program subject to
193
+these terms and conditions.  You may not impose any further
194
+restrictions on the recipients' exercise of the rights granted herein.
195
+You are not responsible for enforcing compliance by third parties to
196
+this License.
197
+
198
+  7. If, as a consequence of a court judgment or allegation of patent
199
+infringement or for any other reason (not limited to patent issues),
200
+conditions are imposed on you (whether by court order, agreement or
201
+otherwise) that contradict the conditions of this License, they do not
202
+excuse you from the conditions of this License.  If you cannot
203
+distribute so as to satisfy simultaneously your obligations under this
204
+License and any other pertinent obligations, then as a consequence you
205
+may not distribute the Program at all.  For example, if a patent
206
+license would not permit royalty-free redistribution of the Program by
207
+all those who receive copies directly or indirectly through you, then
208
+the only way you could satisfy both it and this License would be to
209
+refrain entirely from distribution of the Program.
210
+
211
+If any portion of this section is held invalid or unenforceable under
212
+any particular circumstance, the balance of the section is intended to
213
+apply and the section as a whole is intended to apply in other
214
+circumstances.
215
+
216
+It is not the purpose of this section to induce you to infringe any
217
+patents or other property right claims or to contest validity of any
218
+such claims; this section has the sole purpose of protecting the
219
+integrity of the free software distribution system, which is
220
+implemented by public license practices.  Many people have made
221
+generous contributions to the wide range of software distributed
222
+through that system in reliance on consistent application of that
223
+system; it is up to the author/donor to decide if he or she is willing
224
+to distribute software through any other system and a licensee cannot
225
+impose that choice.
226
+
227
+This section is intended to make thoroughly clear what is believed to
228
+be a consequence of the rest of this License.
229
+
230
+  8. If the distribution and/or use of the Program is restricted in
231
+certain countries either by patents or by copyrighted interfaces, the
232
+original copyright holder who places the Program under this License
233
+may add an explicit geographical distribution limitation excluding
234
+those countries, so that distribution is permitted only in or among
235
+countries not thus excluded.  In such case, this License incorporates
236
+the limitation as if written in the body of this License.
237
+
238
+  9. The Free Software Foundation may publish revised and/or new versions
239
+of the General Public License from time to time.  Such new versions will
240
+be similar in spirit to the present version, but may differ in detail to
241
+address new problems or concerns.
242
+
243
+Each version is given a distinguishing version number.  If the Program
244
+specifies a version number of this License which applies to it and
245
+"any later version", you have the option of following the terms and
246
+conditions either of that version or of any later version published by
247
+the Free Software Foundation.  If the Program does not specify a
248
+version number of this License, you may choose any version ever
249
+published by the Free Software Foundation.
250
+
251
+  10. If you wish to incorporate parts of the Program into other free
252
+programs whose distribution conditions are different, write to the author
253
+to ask for permission.  For software which is copyrighted by the Free
254
+Software Foundation, write to the Free Software Foundation; we sometimes
255
+make exceptions for this.  Our decision will be guided by the two goals
256
+of preserving the free status of all derivatives of our free software and
257
+of promoting the sharing and reuse of software generally.
258
+
259
+			    NO WARRANTY
260
+
261
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO
262
+WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.
263
+EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR
264
+OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY
265
+KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
266
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
267
+PURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE
268
+PROGRAM IS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME
269
+THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
270
+
271
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN
272
+WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY
273
+AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU
274
+FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR
275
+CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE
276
+PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING
277
+RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A
278
+FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF
279
+SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
280
+DAMAGES.
281
+
282
+		     END OF TERMS AND CONDITIONS
283
+
284
+	    How to Apply These Terms to Your New Programs
285
+
286
+  If you develop a new program, and you want it to be of the greatest
287
+possible use to the public, the best way to achieve this is to make it
288
+free software which everyone can redistribute and change under these
289
+terms.
290
+
291
+  To do so, attach the following notices to the program.  It is safest
292
+to attach them to the start of each source file to most effectively
293
+convey the exclusion of warranty; and each file should have at least
294
+the "copyright" line and a pointer to where the full notice is found.
295
+
296
+    <one line to give the program's name and a brief idea of what it does.>
297
+    Copyright (C) <year>  <name of author>
298
+
299
+    This program is free software; you can redistribute it and/or modify
300
+    it under the terms of the GNU General Public License as published by
301
+    the Free Software Foundation; either version 2 of the License, or
302
+    (at your option) any later version.
303
+
304
+    This program is distributed in the hope that it will be useful,
305
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
306
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
307
+    GNU General Public License for more details.
308
+
309
+    You should have received a copy of the GNU General Public License
310
+    along with this program; if not, write to the Free Software
311
+    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
312
+
313
+
314
+Also add information on how to contact you by electronic and paper mail.
315
+
316
+If the program is interactive, make it output a short notice like this
317
+when it starts in an interactive mode:
318
+
319
+    Gnomovision version 69, Copyright (C) year name of author
320
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
321
+    This is free software, and you are welcome to redistribute it
322
+    under certain conditions; type `show c' for details.
323
+
324
+The hypothetical commands `show w' and `show c' should show the appropriate
325
+parts of the General Public License.  Of course, the commands you use may
326
+be called something other than `show w' and `show c'; they could even be
327
+mouse-clicks or menu items--whatever suits your program.
328
+
329
+You should also get your employer (if you work as a programmer) or your
330
+school, if any, to sign a "copyright disclaimer" for the program, if
331
+necessary.  Here is a sample; alter the names:
332
+
333
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
334
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
335
+
336
+  <signature of Ty Coon>, 1 April 1989
337
+  Ty Coon, President of Vice
338
+
339
+This General Public License does not permit incorporating your program into
340
+proprietary programs.  If your program is a subroutine library, you may
341
+consider it more useful to permit linking proprietary applications with the
342
+library.  If this is what you want to do, use the GNU Library General
343
+Public License instead of this License.
344
+

+ 5
- 0
Makefile Vedi File

@@ -0,0 +1,5 @@
1
+# saturnin - Spirit of your toolbox
2
+# See LICENSE file for copyright and license details.
3
+
4
+MKIT_DIR=utils/mkit
5
+include $(MKIT_DIR)/mkit.mk

+ 4
- 0
README.md Vedi File

@@ -0,0 +1,4 @@
1
+SATURNIN
2
+========
3
+
4
+Spirit of your toolbox

+ 50
- 0
mkit.ini Vedi File

@@ -0,0 +1,50 @@
1
+#mkit version=0.0.14
2
+
3
+[project]
4
+    version     = 0.0.1
5
+    name        = SATURNIN-DEMO
6
+    tagline     = saturnin example toolkit
7
+    pkgname     = saturnin-demo
8
+    relsrc      = devel
9
+
10
+[dist]
11
+    tarball = LICENSE
12
+    tarball = Makefile
13
+    tarball = README.md
14
+    tarball = mkit.ini
15
+    tarball = packaging
16
+    tarball = src
17
+    tarball = utils
18
+    rpmstuff = packaging/template.spec
19
+    debstuff = packaging/debian
20
+
21
+[ENV]
22
+    PREFIX = /usr/local
23
+
24
+[roots]
25
+    bin     = [ENV:PREFIX]/bin
26
+    libexec = [ENV:PREFIX]/libexec/saturnin-demo
27
+    share   = [ENV:PREFIX]/share/saturnin-demo
28
+    doc     = [ENV:PREFIX]/share/doc/saturnin-demo
29
+    etc     = /etc/saturnin-demo
30
+    etc_bc  = /etc/bash_completion.d
31
+
32
+[tokens]
33
+    __SATURNIN_DEMO_CACHE_HOME__     = $HOME/.cache/saturnin-demo
34
+    __SATURNIN_DEMO_CONFIG_USER__    = $HOME/.saturnin-demo
35
+    __SATURNIN_DEMO_CONFIG_LOCAL__   = [roots:etc]
36
+    __SATURNIN_DEMO_LIBEXEC__        = [roots:libexec]
37
+    __SATURNIN_DEMO_SHARE__          = [roots:share]
38
+
39
+[modes]
40
+    bin     = 755
41
+    libexec = 755
42
+    share   = 644
43
+
44
+[files]
45
+    bin = src/bin/app saturnin-demo
46
+    doc = README.md
47
+    etc_bc = src/complete.bash          saturnin-demo.bash
48
+    libexec = src/libexec/saturnin-demo-dump
49
+    libexec = src/libexec/saturnin-demo-echo
50
+    share = src/ini.d/main/echo.ini     ini.d/main/echo.ini

+ 5
- 0
packaging/debian/changelog Vedi File

@@ -0,0 +1,5 @@
1
+saturnin-demo (__MKIT_PROJ_VERSION__-1) UNRELEASED; urgency=medium
2
+
3
+  * Initial release. (Closes: #XXXXXX)
4
+
5
+ -- Alois Mahdal <netvor@vornet.cz>  Sat, 27 Feb 2016 01:38:03 +0100

+ 1
- 0
packaging/debian/compat Vedi File

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

+ 22
- 0
packaging/debian/control Vedi File

@@ -0,0 +1,22 @@
1
+Source: saturnin-demo
2
+Maintainer: Alois Mahdal <netvor@vornet.cz>
3
+Vcs-Browser: http://git.vornet.cz/cgit/saturnin.git/
4
+Section: misc
5
+Priority: extra
6
+Standards-Version: 3.9.2
7
+Build-Depends: debhelper (>= 9)
8
+
9
+Package: saturnin-demo
10
+Architecture: all
11
+Depends: bash, shellfu-bash, shellfu-bash-core, shellfu-bash-saturnin
12
+Description: __MKIT_PROJ_TAGLINE__
13
+ saturnin is Shellfu library that helps you easily build toolkit from
14
+ various scripts that you may have lying around.  Instead of having a
15
+ herd of untamed undocumented and hard-to-share scripts, with help of
16
+ saturnin you can easily create and package a meta-command with a set
17
+ of discoverable and maintainable sub-commands.
18
+ .
19
+ This package contains a demo meta-command built with saturnin; you can
20
+ also re-use the source as template for your new toolkit.
21
+
22
+# control file built with MKit __MKIT_SELF_VERSION__

+ 1
- 0
packaging/debian/copyright Vedi File

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

+ 13
- 0
packaging/debian/rules Vedi File

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

+ 6
- 0
packaging/debian/saturnin-demo.install Vedi File

@@ -0,0 +1,6 @@
1
+/etc/bash_completion.d/saturnin-demo.bash
2
+/usr/local/bin/saturnin-demo
3
+/usr/local/libexec/saturnin-demo/saturnin-demo-dump
4
+/usr/local/libexec/saturnin-demo/saturnin-demo-echo
5
+/usr/local/share/doc/saturnin-demo/README.md
6
+/usr/local/share/saturnin-demo/ini.d/main/echo.ini

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

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

+ 51
- 0
packaging/template.spec Vedi File

@@ -0,0 +1,51 @@
1
+Name:		__MKIT_PROJ_PKGNAME__
2
+Version:	__MKIT_PROJ_VERSION__
3
+Release:	1%{?dist}
4
+Summary:	__MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__
5
+
6
+License:	LGPLv2
7
+Source0:	%{name}-%{version}.tar.gz
8
+
9
+BuildArch:	noarch
10
+BuildRequires:	coreutils git
11
+Requires:	shellfu-bash
12
+Requires:	shellfu-bash-core
13
+Requires:	shellfu-bash-saturnin
14
+
15
+%description
16
+saturnin is Shellfu library that helps you easily build toolkit from
17
+various scripts that you may have lying around.  Instead of having a
18
+herd of untamed undocumented and hard-to-share scripts, with help of
19
+saturnin you can easily create and package a meta-command with a set
20
+of discoverable and maintainable sub-commands.
21
+
22
+This package contains a demo meta-command built with saturnin; you can
23
+also re-use the source as template for your new toolkit.
24
+
25
+%prep
26
+%setup -q
27
+
28
+
29
+%build
30
+# %%configure
31
+make %{?_smp_mflags}
32
+
33
+%install
34
+%make_install
35
+
36
+%files
37
+%config %{_sysconfdir}/bash_completion.d/saturnin-demo.bash
38
+%dir /usr/local/libexec/saturnin-demo
39
+%dir /usr/local/share/saturnin-demo
40
+%dir /usr/local/share/saturnin-demo/ini.d
41
+%dir /usr/local/share/saturnin-demo/ini.d/main
42
+%doc /usr/local/share/doc/saturnin-demo/README.md
43
+/usr/local/bin/saturnin-demo
44
+/usr/local/libexec/saturnin-demo/saturnin-demo-dump
45
+/usr/local/libexec/saturnin-demo/saturnin-demo-echo
46
+/usr/local/share/saturnin-demo/ini.d/main/echo.ini
47
+
48
+
49
+%changelog
50
+
51
+# specfile built with MKit __MKIT_SELF_VERSION__

+ 38
- 0
src/bin/app.skel Vedi File

@@ -0,0 +1,38 @@
1
+#!/bin/bash
2
+
3
+. "$(shellfu-get path)" || exit 3
4
+
5
+#
6
+# =====BEGIN BUILT PART=====
7
+#
8
+
9
+#shellcheck disable=SC2034
10
+{
11
+    SATURNIN_APP_CODENAME="__MKIT_PROJ_CODENAME__"
12
+    SATURNIN_APP_TAGLINE="__MKIT_PROJ_TAGLINE__"
13
+    SATURNIN_APP_VERSION="__MKIT_PROJ_VERSION__"
14
+    SATURNIN_APP_GIT_HASH="__MKIT_PROJ_GIT_LASTHASH__"
15
+    SATURNIN_CACHE_HOME="__SATURNIN_DEMO_CACHE_HOME__"
16
+    SATURNIN_LIBEXEC="__SATURNIN_DEMO_LIBEXEC__"
17
+    SATURNIN_LIBEXEC_PREFIX="__MKIT_PROJ_PKGNAME__-"
18
+    PRETTY_USAGE="subcommand"
19
+}
20
+
21
+shellfu import saturnin
22
+
23
+SATURNIN_CONF_PATH="$(
24
+    saturnin__conf_mkpath \
25
+        __SATURNIN_DEMO_CONFIG_USER__/ini.d \
26
+        __SATURNIN_DEMO_CONFIG_USER__ \
27
+        __SATURNIN_DEMO_CONFIG_LOCAL__ \
28
+        __SATURNIN_DEMO_SHARE__/ini.d
29
+)"
30
+
31
+#
32
+# =====END BUILT PART=====
33
+#
34
+
35
+export SATURNIN_CONF_PATH SHELLFU_PATH PRETTY_USAGE \
36
+       SATURNIN_CACHE_HOME
37
+
38
+saturnin__main "$@"

+ 38
- 0
src/complete.bash Vedi File

@@ -0,0 +1,38 @@
1
+#!/bin/bash
2
+
3
+__SATURNIN_COMPLETE_CMDNAME=saturnin-demo
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 -h -v"
12
+    opts="--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 _ls_sc)" "${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"

+ 7
- 0
src/ini.d/main/echo.ini Vedi File

@@ -0,0 +1,7 @@
1
+
2
+[echo]
3
+
4
+    #
5
+    # default prefix
6
+    #
7
+    prefix = so:

+ 5
- 0
src/libexec/saturnin-demo-dump Vedi File

@@ -0,0 +1,5 @@
1
+#!/bin/bash
2
+
3
+. "$(shellfu-get path)" || exit 3
4
+
5
+env | sort | xargs -L 1 saturnin-demo echo

+ 10
- 0
src/libexec/saturnin-demo-echo Vedi File

@@ -0,0 +1,10 @@
1
+#!/bin/bash
2
+
3
+. "$(shellfu-get path)" || exit 3
4
+
5
+shellfu import saturnin
6
+
7
+SATCMD_ECHO__PREFIX="${SATCMD_ECHO__PREFIX:-$(saturnin__conf "echo.prefix")}"
8
+
9
+echo -n "$SATCMD_ECHO__PREFIX"
10
+echo "$@"

+ 410
- 0
src/shellfu/saturnin.sh Vedi File

@@ -0,0 +1,410 @@
1
+#!/bin/bash
2
+
3
+shellfu import exit
4
+shellfu import inigrep
5
+shellfu import pretty
6
+
7
+#
8
+# Path where saturnin__conf should look for files
9
+#
10
+# If filename does not contain slash, it is looked up in each
11
+# (or all, based on strategy--see saturnin__conf() doc) path in this
12
+# list.  The list is colon-separated and non-dirs as well as
13
+# empty strings are silently ignored.
14
+#
15
+SATURNIN_CONF_PATH="${SATURNIN_CONF_PATH:-}"
16
+
17
+#
18
+# Expected config filename extension (for guessing from path head)
19
+#
20
+# If no filename to read is given, saturnin__conf() will guess
21
+# filename as the path head plus this suffix (e.g. `foo.ini` for
22
+# `saturnin__conf foo.bar.baz`)
23
+#
24
+SATURNIN_CONF_SUFFIX="${SATURNIN_CONF_SUFFIX:-.ini}"
25
+
26
+saturnin__conf() {
27
+    #
28
+    # inigrep smart loader
29
+    #
30
+    # Usage:
31
+    #   saturnin__conf [-j] [inigrep-query] [-- [file]..]
32
+    #
33
+    #
34
+    # File arguments
35
+    # ==============
36
+    #
37
+    # If omitted, *file* argument is inferred by taking part of
38
+    # kpath name before first dot and appending value of
39
+    # `$SATURNIN_CONF_SUFFIX`, (".ini" by default).
40
+    #
41
+    # Each *file* argument is then processed as follows:
42
+    #
43
+    #  *  `-` (single dash) is interpreted as reading from
44
+    #     STDIN.
45
+    #
46
+    #  *  If argument contains slash, it is expanded as a regular
47
+    #     path (relative or absolute).
48
+    #
49
+    #  *  Otherwise, it is taken as filename and searched for
50
+    #     in directories given in `$SATURNIN_CONF_PATH`.  (This can
51
+    #     yield more than one path, which is equivalent as if
52
+    #     all paths were provided.)
53
+    #
54
+    #     Not all files expanded based on `$SATURNIN_CONF_PATH`
55
+    #     are read by default; reading is governed by "merge
56
+    #     strategy": the default strategy "first" reads only
57
+    #     the first existing file.
58
+    #
59
+    #     "join" strategy on the other hand, means that any
60
+    #     files are simply concatenated and prefixed with
61
+    #     comment (visible only in raw mode) containing path
62
+    #     to the file.
63
+    #
64
+    #     This means that if a section is queried that is
65
+    #     present in both files, it is effectively concatenated
66
+    #     as well.
67
+    #
68
+    # Following calls are equivalent
69
+    #
70
+    #     saturnin__conf foo.bar.baz
71
+    #     saturnin__conf foo.bar.baz foo.ini
72
+    #
73
+    # and both result in reading of key *baz* from section *foo.bar*
74
+    # in file *foo.ini*, which is selected from *SATURNIN_CONF_PATH*.
75
+    # Should there be more foo.ini's, the first is selected.
76
+    # Using `-j` switch
77
+    #
78
+    #     saturnin__conf -j foo.bar.baz
79
+    #
80
+    # would cause all foo.ini's on *SATURNIN_CONF_PATH* be
81
+    # concatenated instead.
82
+    #
83
+    local ig_mode               # retrieval mode
84
+    local ig_query              # keypath or section name (when listing keys)
85
+    local ig_limit              # line limit
86
+    local files=()              # file specification
87
+    local Strategy=first        # merge strategy
88
+    while true; do case $1:$2 in
89
+        "":*)   break ;;
90
+        -j:*)   Strategy=join;           shift 1        ;;
91
+        -1:*)   ig_limit=$1;             shift 1        ;;
92
+        -e:*.*) ig_mode=$1; ig_query=$2; shift 2; break ;;
93
+        -r:*.*) ig_mode=$1; ig_query=$2; shift 2; break ;;
94
+        -K:*)   ig_mode=$1; ig_query=$2; shift 2; break ;;
95
+        -S:*)   ig_mode=$1; ig_query=""; shift 1; break ;;
96
+        -P:*)   ig_mode=$1; ig_query=""; shift 1; break ;;
97
+        .*:*)   warn "bad syntax: $*"; _saturnin__conf_usage ;;
98
+        *.*:*)  ig_mode=-e; ig_query=$1; shift 1; break ;;
99
+        --help:*) _saturnin__conf_usage -e 0                 ;;
100
+        *)      warn "bad syntax: $*"; _saturnin__conf_usage ;;
101
+    esac done
102
+    test -n "$ig_mode" || { warn "could not determine inigrep mode"; _saturnin__conf_usage; }
103
+    debug -v ig_limit ig_query ig_mode Strategy
104
+    if test -n "$*";
105
+    then
106
+        files=("$@")
107
+    elif test -n "$ig_query";
108
+    then
109
+        files=("${ig_query%%.*}$SATURNIN_CONF_SUFFIX")
110
+    else
111
+        warn "dunno what to load"
112
+        _saturnin__conf_usage
113
+    fi
114
+    debug -v files
115
+    #shellcheck disable=SC2086
116
+    _saturnin__conf__load "${files[@]}" | inigrep $ig_limit $ig_mode "$ig_query"
117
+    return "${PIPESTATUS[0]}"
118
+}
119
+
120
+saturnin__get() {
121
+    #
122
+    # Show Saturnin Internal info by key $1 and exit
123
+    #
124
+    # Key $1 can be whole `--saturnin-get-stuff` argument or just
125
+    # the part after `--saturnin-get-`.
126
+    #
127
+    # This is aimed to help debugging and testing the app (or
128
+    # Saturnin itself) by showing packaging and deployment related
129
+    # info.
130
+    #
131
+    local key=${1#--saturnin-get-}
132
+    case "$key" in
133
+        shellfu-path)   echo "$SHELLFU_PATH"                ;;
134
+        saturnin-conf-path) echo "$SATURNIN_CONF_PATH"      ;;
135
+        app-git-hash)   echo "$SATURNIN_APP_GIT_HASH"       ;;
136
+        app-version)    echo "$SATURNIN_APP_VERSION"        ;;
137
+        cache-home)     echo "$SATURNIN_CACHE_HOME"         ;;
138
+        libexec)        echo "$SATURNIN_LIBEXEC"            ;;
139
+        libexec-prefix) echo "$SATURNIN_LIBEXEC_PREFIX"     ;;
140
+        *)              warn "unknown devel key: $key"
141
+                        exit "$EXIT_USAGE" ;;
142
+    esac
143
+    exit "$EXIT_OK"
144
+}
145
+
146
+saturnin__lssc() {
147
+    #
148
+    # List subcommands
149
+    #
150
+    echo conf
151
+    find "$SATURNIN_LIBEXEC" \
152
+        -mindepth 1 \
153
+        -maxdepth 1 \
154
+        -executable \
155
+      | sed -e "s|^.*/||; s|^$SATURNIN_LIBEXEC_PREFIX||" \
156
+      | sort
157
+}
158
+
159
+saturnin__main() {
160
+    local subcommand
161
+    while true; do case $1 in
162
+        -d|--debug)     export PRETTY_DEBUG=true;   shift ;;
163
+        -v|--verbose)   export PRETTY_VERBOSE=true; shift ;;
164
+        -h|--help)      saturnin__usage -e 0;       exit  ;;
165
+        --version)      saturnin__version;          exit  ;;
166
+        --version-semver) saturnin__get app-version ;;
167
+        --saturnin-get-*) saturnin__get "$1"        ;;
168
+        -*)             saturnin__usage;            ;;
169
+        --*)            saturnin__usage;            ;;
170
+        --)             shift; break                ;;
171
+        "")             saturnin__usage;            ;;
172
+        *)              break;                      ;;
173
+    esac done
174
+    subcommand="$1"; shift
175
+    debug -v SHELLFU_PATH SATURNIN_LIBEXEC SATURNIN_CONF_PATH
176
+    case "$subcommand" in
177
+        conf)    saturnin__conf "$@"                ;;
178
+        _ls_sc)  saturnin__lssc                     ;;
179
+        _lsfun)  shellfu-get lsfun                  ;;
180
+        _lsmod)  shellfu-get lsmod                  ;;
181
+        *)       saturnin__runsc "$subcommand" "$@" ;;
182
+    esac
183
+}
184
+
185
+saturnin__conf_mkpath() {
186
+    #
187
+    # Assemble SATURNIN_CONF_PATH from locations $@
188
+    #
189
+    # For each location, print colon-delimited list of
190
+    # directories.  If location ends with "/ini.d", list of
191
+    # subfolders, sorted by C locale is printed--this allows
192
+    # for modular configuration.  Otherwise the location
193
+    # is printed.  Non-existent or non-directory locations
194
+    # are silently ignored.
195
+    #
196
+    local location      # one location argument
197
+    local path          # one path listed
198
+    for location in "$@";
199
+    do
200
+        test -d "$location" || continue
201
+        case "$location" in
202
+            */ini.d)    # modular location--sort subfolders
203
+                find -L "$location" -mindepth 1 -maxdepth 1 -type d \
204
+                  | LC_ALL=C sort
205
+                ;;
206
+            *)
207
+                echo "$location"
208
+                ;;
209
+        esac
210
+    done \
211
+      | _saturnin__nl2colon
212
+}
213
+
214
+saturnin__runhook() {
215
+    #
216
+    # Run custom hook
217
+    #
218
+    local hname="$1"
219
+    local hook_code
220
+    test -n "$SATURNIN_SUBCOMMAND" || {
221
+        warn "unknown subcommand, ignoring hook: $hname"
222
+        return 0
223
+    }
224
+    hook_code="$(saturnin__conf -j "hook.$SATURNIN_SUBCOMMAND.$hname")"
225
+    debug -v SATURNIN_SUBCOMMAND hook_code hname
226
+    bash -n <<<"$hook_code" || {
227
+        warn "syntax errors, ignoring hook: $hname"
228
+        return 0
229
+    }
230
+    eval "$hook_code"
231
+}
232
+
233
+saturnin__runsc() {
234
+    #
235
+    # Run subcommand $SATURNIN_SUBCOMMAND
236
+    #
237
+    local subcommand="$1"; shift
238
+    local binpath   # path to subcommand's binary
239
+    binpath+="$SATURNIN_LIBEXEC/"
240
+    binpath+="$SATURNIN_LIBEXEC_PREFIX$subcommand"
241
+    debug -v binpath
242
+    debug "\$*='$*'"
243
+    test -x "$binpath" || {
244
+        warn "invalid sub-command: $subcommand"
245
+        saturnin__usage
246
+    }
247
+    SATURNIN_SUBCOMMAND="$subcommand" "$binpath" "$@"
248
+}
249
+
250
+saturnin__usage() {
251
+    #
252
+    # Show usage message and exit
253
+    #
254
+    #shellcheck disable=SC2046
255
+    mkusage "$@"                                            \
256
+            "[options] COMMAND [ARG...]"                    \
257
+        -o                                                  \
258
+            "-d, --debug    turn on debugging"              \
259
+            "-h, --help     show this help message and exit"\
260
+            "-v, --verbose  turn on verbosity"              \
261
+            "--version      show version and exit"          \
262
+        -c                                                  \
263
+            $(saturnin__lssc)
264
+}
265
+
266
+saturnin__version() {
267
+    #
268
+    # Print version info
269
+    #
270
+    local tagline=${SATURNIN_APP_TAGLINE:-Some app with default tagline}
271
+    local maybe_codename=""
272
+    test -n "$SATURNIN_APP_CODENAME" && maybe_codename=" - $SATURNIN_APP_CODENAME"
273
+    echo "$(basename "$0") ($tagline) $SATURNIN_APP_VERSION$maybe_codename"
274
+    return "$EXIT_OK"
275
+}
276
+
277
+saturnin__wraphook() {
278
+    #
279
+    # Wrap command "$@" in hooks
280
+    #
281
+    # Run pre hook, then "$@", then post hook.  Always exit
282
+    # with status of "$@", even if hooks fail.  Ignore
283
+    # post-hook if "$@" failed.
284
+    #
285
+    local es=0
286
+    saturnin__runhook pre
287
+    "$@" || return $?
288
+    es=$?
289
+    saturnin__runhook post
290
+    return $es
291
+}
292
+
293
+
294
+#          #                           that what you see below this line #
295
+# INTERNAL # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
296
+#          #                        use in your code to anger the divine #
297
+
298
+_saturnin__conf__merge() {
299
+    #
300
+    # Take paths and applying merge strategy, load file(s)
301
+    #
302
+    local path
303
+    local found=false
304
+    while read -r path;
305
+    do
306
+        test -f "$path" || continue
307
+        found=true
308
+        case $Strategy in
309
+            first)
310
+                debug "winner: $path"
311
+                cat "$path"
312
+                cat >/dev/null  # throw away rest of paths
313
+                ;;
314
+            join)
315
+                echo "# file: ${path/$HOME/~}"
316
+                cat "$path" 2>/dev/null
317
+                ;;
318
+        esac
319
+    done
320
+    $found
321
+}
322
+
323
+_saturnin__conf__load() {
324
+    #
325
+    # Print contents of files specified in $@
326
+    #
327
+    # Each argument means possible file candidate.  If candidate
328
+    # contains slash, it's treated as file path and is printed
329
+    # directly.  If it's single dash, standard input is copied.
330
+    #
331
+    # In all other cases, filename is searched in all elements
332
+    # of SATURNIN_CONF_PATH; output then depends on chosen $Strategy:
333
+    # with 'first' strategy, first existing file is printed, with
334
+    # 'join' strategy. all existing files are printed.
335
+    #
336
+    local arg trydir trypath es
337
+    es=0
338
+    for arg in "$@";
339
+    do
340
+        case $arg in
341
+            -|*/*)      # stdin, or path (with slash)
342
+                cat "$arg" || es=3
343
+            ;;
344
+        *)              # name given, find all its incarnations
345
+            debug -v SATURNIN_CONF_PATH
346
+            echos "$SATURNIN_CONF_PATH" \
347
+              | tr ':' '\n' \
348
+              | while read -r trydir;
349
+                do
350
+                    test -n "$trydir" || continue
351
+                    trypath="$trydir/$arg"
352
+                    echos "$trypath"
353
+                done \
354
+              |  _saturnin__conf__merge; es=$?
355
+            ;;
356
+        esac
357
+    done
358
+    return $es
359
+}
360
+
361
+_saturnin__conf_usage() {
362
+    #
363
+    # Show usage message and exit
364
+    #
365
+    PRETTY_USAGE="self=${0##*/} conf" \
366
+    mkusage "$@"                                                               \
367
+            "[options] [-e] SECTION.KEY [FNAME]"                               \
368
+            "[options] -r SECTION.KEY [FNAME]"                                 \
369
+            "[options] -K SECTION [FNAME]"                                     \
370
+            "[options] -P FNAME"                                               \
371
+            "[options] -S FNAME"                                               \
372
+        --                                                                     \
373
+            "Use inigrep to query config files."                               \
374
+        -o                                                                     \
375
+            "-j     join all files before applying query"                      \
376
+            "-1     ensure single line is returned"                            \
377
+        -c                                                                     \
378
+            "-e     use normal mode (default)"                                 \
379
+            "-r     use raw mode (preserves RHS whitespace and some comments)" \
380
+            "-K     list available keys in SECTION"                            \
381
+            "-S     list available sections in FNAME"                          \
382
+            "-P     list available keypaths (SECTION.KEY) in FNAME"            \
383
+        --                                                                     \
384
+            "FNAME is filename, which is then searched on all paths specified" \
385
+            "in SATURNIN_CONF_PATH and depending on -j parameter, first one"   \
386
+            "wins or all are joined.  If FNAME contains slash, this search is" \
387
+            "not done and FNAME is taken as path to file that is then queried."\
388
+            ""                                                                 \
389
+            "If FNAME is omitted, it is inferred from SECTION (e.g. .'foo.ini'"\
390
+            "if 'foo.bar' was section name; note that section name may contain"\
391
+            "dot)."
392
+}
393
+
394
+_saturnin__nl2colon() {
395
+    #
396
+    # Convert newline-based list of paths to colon:based:list
397
+    #
398
+    # Empty paths must not be included in the resulting list,
399
+    # so we need to drop them and also get the colons right.
400
+    #
401
+    local idx=0     # current item index (zero-based)
402
+    local path
403
+    while read -r path;
404
+    do
405
+        test -z "$path" && continue
406
+        test $idx -gt 0 && echo -n ':'
407
+        echo -n "$path"
408
+        ((idx++))
409
+    done
410
+}

+ 217
- 0
utils/mkit/include/build.sh Vedi File

@@ -0,0 +1,217 @@
1
+#!/bin/bash
2
+
3
+. "$MKIT_DIR/include/ini.sh"   || die "cannot import ini.sh"
4
+. "$MKIT_DIR/include/facts.sh" || die "cannot import facts.sh"
5
+
6
+
7
+_build1() {
8
+    #
9
+    # Process one skeleton
10
+    #
11
+    local srcpath="$1"
12
+    local dstpath="$2"
13
+    local ftype="$3"
14
+    test -n "$dstpath"  || dstpath=${srcpath%.skel}
15
+    test -n "$ftype"    || ftype=$(_guess_ftype "$dstpath")
16
+    debug_var srcpath dstpath ftype
17
+    <"$srcpath" _build1_ftype "$ftype" >"$dstpath"
18
+    mkdir -p "$MKIT_LOCAL"
19
+    echo "$dstpath" >> "$MKIT_LOCAL/built.lst"
20
+}
21
+
22
+_build1_ftype() {
23
+    #
24
+    # Build a file of type $1
25
+    #
26
+    local ftype="$1"
27
+    case $ftype in
28
+        MKIT_COMMON)    _expand_tokens "tokens" ;;
29
+        markdown)       _expand_includes | _expand_tokens "tokens" ;;
30
+        rpmstuff)       _expand_tokens "tokens" "rpmstuff:tokens" ;;
31
+        *)              die "unknown file type: $ftype" ;;
32
+    esac
33
+}
34
+
35
+_expand_includes() {
36
+    #
37
+    # Expand include directives
38
+    #
39
+    # Expand e.g. `<!-- include4: foo.sh -->` to include code of foo.sh
40
+    #
41
+    perl -we '
42
+        use strict;
43
+        my $text;
44
+        while (<>) {
45
+            chomp;
46
+            if (m/<!-- include4: (\S+) -->/) {
47
+                open my $fh, $1 or warn "cannot find: $1";
48
+                my $text = do { local($/); <$fh> };
49
+                close $fh;
50
+                $text =~ s/^(.)/    $1/gm;
51
+                chomp $text;
52
+                print "$text\n";
53
+            } else {
54
+                print "$_\n";
55
+            }
56
+        }
57
+    '
58
+}
59
+
60
+_expand_tokens() {
61
+    #
62
+    # Expand tokens from sections $@
63
+    #
64
+    local script=$(mktemp --tmpdir mkit-tmp.XXXXXXXXXX)
65
+    local section varname varvalue
66
+    {
67
+        for section in "$@";
68
+        do
69
+            debug_var section
70
+            ini lskeys "$section" \
71
+              | while read varname;
72
+                do
73
+                    varvalue="$(ini 1value "$section:$varname" | _qfs )"
74
+                    echo "s|$varname|$varvalue|g;"
75
+                    debug_var varname varvalue
76
+                done
77
+        done
78
+        echo "s|__MKIT_PROJ_NAME__|$(ini 1value project:name | _qfs)|g;"
79
+        echo "s|__MKIT_PROJ_CODENAME__|$(ini 1value project:codename | _qfs)|g;"
80
+        echo "s|__MKIT_PROJ_PKGNAME__|$(ini 1value project:pkgname | _qfs)|g;"
81
+        echo "s|__MKIT_PROJ_TAGLINE__|$(ini 1value project:tagline | _qfs)|g;"
82
+        echo "s|__MKIT_PROJ_MAINTAINER__|$(ini 1value project:maintainer | _qfs)|g;"
83
+        echo "s|__MKIT_PROJ_VCS_BROWSER__|$(ini 1value project:vcs_browser | _qfs)|g;"
84
+        echo "s|__MKIT_PROJ_GIT_LASTHASH__|$(git_lasthash | _qfs)|g;"
85
+        echo "s|__MKIT_PROJ_VERSION__|$(semver | _qfs)|g;"
86
+        echo "s|__MKIT_SELF_VERSION__|$MKIT_VERSION|g;"
87
+    } >> "$script"
88
+    sed -f "$script" || die "_expand_tokens failed"
89
+    rm "$script"
90
+}
91
+
92
+_guess_ftype() {
93
+    #
94
+    # Guess file type from destination path $1
95
+    #
96
+    local dstpath="$1"
97
+    case $dstpath in
98
+        *.md) echo markdown    ;;
99
+        *)    echo MKIT_COMMON ;;
100
+    esac
101
+}
102
+
103
+_qfs() {
104
+    #
105
+    # Quote for our sed scipt's RHS
106
+    #
107
+    sed '
108
+        s:\\:\\\\:g
109
+        s:|:\\|:g
110
+    '
111
+}
112
+
113
+build() {
114
+    #
115
+    # Add meat to all skeletons
116
+    #
117
+    local srcpath
118
+    find -type f -name '*.skel' \
119
+     | while read srcpath;
120
+       do
121
+           _build1 "$srcpath"
122
+       done
123
+}
124
+
125
+build_manpages() {
126
+    local manfile mdfile
127
+    if command -v ronn >/dev/null;
128
+    then
129
+        ini lskeys "files:man" \
130
+          | while read manfile;
131
+            do
132
+                mdfile="$manfile.md"
133
+                ronn -r "$mdfile"
134
+                mkdir -p "$MKIT_LOCAL"
135
+                echo "$manfile" >> "$MKIT_LOCAL/built.lst"
136
+            done
137
+    else
138
+        echo "ronn is not installed"
139
+        return 1
140
+    fi
141
+}
142
+
143
+clean() {
144
+    #
145
+    # Clean up tree after building
146
+    #
147
+    test -f "$MKIT_LOCAL/built.lst" && {
148
+        <"$MKIT_LOCAL/built.lst" grep -v -e '\.\.' -e ^/ \
149
+          | xargs -r rm -rf
150
+        rm -f "$MKIT_LOCAL/built.lst"
151
+        rmdir --ignore-fail-on-non-empty "$MKIT_LOCAL"
152
+    }
153
+    true
154
+}
155
+
156
+debstuff() {
157
+    #
158
+    # Build Debian stuff (eamed tarball, debian dir)
159
+    #
160
+    local version="$(semver)"
161
+
162
+    # tarball - we should already have by means of 'dist'
163
+    #
164
+    mv "${MKIT_PROJ_PKGNAME}-$version.tar.gz" \
165
+       "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz" \
166
+     || die "could not rename tarball"
167
+    echo "${MKIT_PROJ_PKGNAME}_$version.orig.tar.gz" >> "$MKIT_LOCAL/built.lst"
168
+
169
+    # read content of each mandatory file from debian_skel
170
+    #
171
+    local debian_skel=$(ini 1value dist:debstuff)
172
+    test -n "$debian_skel" || die "dist:debstuff not specified"
173
+    test -d "$debian_skel" || die "debian directory template found: $debian_skel"
174
+    mkdir -p debian/source
175
+    local dfsrc dftgt
176
+    find "$debian_skel" -type f \
177
+      | while read dfsrc;
178
+        do
179
+            dftgt="debian/${dfsrc#$debian_skel}"
180
+            mkdir -p "$(dirname "$dftgt")"
181
+            _build1 "$dfsrc" "$dftgt"
182
+        done
183
+    echo debian >> "$MKIT_LOCAL/built.lst"
184
+}
185
+
186
+dist() {
187
+    #
188
+    # Create distributable tarball
189
+    #
190
+    #FIXME: lacking Makefile skills, we do this step twice fot
191
+    #       rpmstuff, hence -f hack for gzip
192
+    #
193
+    local version=$(semver)
194
+    local git_lasthash=$(git_lasthash)
195
+    local dirname=$MKIT_PROJ_PKGNAME-$version
196
+    mkdir -p "$dirname"
197
+    ini values "dist:tarball" | xargs -I DIST_ITEM cp -R DIST_ITEM "$dirname"
198
+    update_version "$version" "$dirname/mkit.ini"
199
+    mkdir -p "$dirname/.mkit"
200
+    echo -n "$git_lasthash" > "$dirname/.mkit/git_lasthash"
201
+    tar -cf "$dirname.tar" "$dirname"
202
+    gzip -f "$dirname.tar"      # see above FIXME
203
+    mkdir -p "$MKIT_LOCAL"
204
+    echo "$dirname.tar.gz" >> "$MKIT_LOCAL/built.lst"
205
+    rm -rf "$dirname"
206
+}
207
+
208
+rpmstuff() {
209
+    #
210
+    # Build specfile
211
+    #
212
+    local specname="$MKIT_PROJ_PKGNAME.spec"
213
+    local specsrc="$(ini 1value "dist:rpmstuff")"
214
+    test -n "$specsrc" || die "dist:rpmstuff not specified"
215
+    test -f "$specsrc" || die "specfile template not found: $specsrc"
216
+    _build1 "$specsrc" "$specname"
217
+}

+ 122
- 0
utils/mkit/include/deploy.sh Vedi File

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

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

@@ -0,0 +1,175 @@
1
+#!/bin/bash
2
+
3
+. "$MKIT_DIR/include/ini.sh" || die "cannot import ini.sh"
4
+
5
+git_bool() {
6
+    #
7
+    # Get git bool (ie. exit status counts) $1
8
+    #
9
+    local bool_name="$1"
10
+    git_present || warn "can't give bool outside git repo: $bool_name"
11
+    case "$bool_name" in
12
+        dirty_files)
13
+            git diff-files | grep -qm 1 .
14
+            ;;
15
+        dirty_index)
16
+            git diff-index HEAD | grep -qm 1 .
17
+            ;;
18
+        dirty)
19
+            git_bool dirty_files || git_bool dirty_index
20
+            ;;
21
+        *)
22
+            warn "unknown git bool asked: $bool_name"
23
+            return 2
24
+            ;;
25
+    esac
26
+}
27
+
28
+git_fact() {
29
+    #
30
+    # Get git fact $1
31
+    #
32
+    local fact_name="$1"
33
+    git_present || warn "can't give fact outside git repo: $fact_name"
34
+    case "$fact_name" in
35
+        latest_tag)
36
+            git log --format="%d" \
37
+              | sed 's/,/\n/g' \
38
+              | sed 's/^[[:blank:]]*//' \
39
+              | grep -E '^\(?tag' \
40
+              | tr -cd '[[:digit:]].v\n' \
41
+              | grep . -m 1
42
+            ;;
43
+        latest_version)
44
+            git_fact latest_tag | git_tag2ver
45
+            ;;
46
+        current_branch)
47
+            git rev-parse --abbrev-ref HEAD
48
+            ;;
49
+        reldiff)
50
+            git log --oneline "$(git_fact latest_tag)..HEAD" --name-only
51
+            ;;
52
+        latest_sha)
53
+            git log -1 --pretty=format:%h HEAD
54
+            ;;
55
+        *)
56
+            warn "unknown git fact asked: $fact_name"
57
+            ;;
58
+    esac
59
+}
60
+
61
+git_present() {
62
+    #
63
+    # True if we're in a git repo
64
+    #
65
+    git rev-parse HEAD >&/dev/null
66
+}
67
+
68
+git_tag2ver() {
69
+    #
70
+    # Convert tag to version
71
+    #
72
+    sed s/^v//
73
+}
74
+
75
+git_ver2tag() {
76
+    #
77
+    # Convert version to tag
78
+    #
79
+    sed s/^/v/
80
+}
81
+
82
+git_lasthash() {
83
+    #
84
+    # Show last commit hash (with .dirty suffix if needed)
85
+    #
86
+    # If outside git repo, get it from .mkit/git_lasthash, which
87
+    # should have been put there by dist target.  (I.e., this won't
88
+    # work if you got outside the git repo in other way than dist
89
+    # target, but that's actually expected.)
90
+    #
91
+    if git_present;
92
+    then    # we are in git repo
93
+        local last_hash=$(git rev-parse HEAD)
94
+        echo -n "$last_hash"
95
+        git_bool dirty && echo -n ".dirty"
96
+    else    # we are outside (eg. distributor's build dir')
97
+        grep . .mkit/git_lasthash || {
98
+            echo UNKNOWN
99
+            warn "malformed source, could not determine git hash"
100
+        }
101
+    fi
102
+}
103
+
104
+semver() {
105
+    #
106
+    # Build semver version string with build metadata
107
+    #
108
+    # Build version string from available info using following
109
+    # logic:
110
+    #
111
+    #  1. use project.version (from mkit.ini)
112
+    #  2. if we are in git, override the version with last tag
113
+    #  3. if set, add project:prerl (from mkit.ini) as pre-release ID
114
+    #     (afer dash)
115
+    #  4. if we are at a later commit than the last tag, add branch
116
+    #     name and commit sha1 to build metadata (after plus sign)
117
+    #  5. if the tree is "dirty", i.e. has uncommited changes,
118
+    #     add "dirty" to build metadata
119
+    #
120
+    # The version is compatible with SemVer 2.0.0.
121
+    #
122
+    # Examples:
123
+    #
124
+    #     myprog v1.0.7                         # all clear
125
+    #     myprog v1.0.7-alpha                   # mkit.ini: project:prerl="alpha"
126
+    #     myprog v1.0.7-alpha+g1aef811.master   # ^^ + some commits after
127
+    #     myprog v1.0.7-alpha+gf14fc4f.api2     # ^^ + on a feature branch
128
+    #     myprog v1.0.7-alpha+gf14fc4f.api2.dirty  # ^^ + tree edited
129
+    #     myprog v1.0.7-alpha+dirty             # tag OK but tree edited
130
+    #     myprog v1.0.7+dirty                   # ^^ but no pre-release id
131
+    #
132
+    # Note that versions with "dirty" should be perceived as kind of
133
+    # dangerous outside developer's own machine.  Versions with sha1 are
134
+    # safer but must not be released.
135
+    #
136
+    # I have considered decorating the git commit refs to make them
137
+    # sort of sortable (e.g. "r1.g1aef811"), but on second thought,
138
+    # I don't think it's good idea to give *any* semantics to meta-data
139
+    # at all.  First, there is no rule that r1<r2<r3; a commit can be
140
+    # removing what other just added and one change can be split to
141
+    # multiple commits.  Also, the whole thing breaks anyway once you
142
+    # rebase your branch (no, it's not a sin).  The sole purpose of
143
+    # meta-data is to *identify* the code, and provide safe path back
144
+    # to tree; commit refs are already perfect for that.
145
+    #
146
+    # FIXME:  Using project:prerl for release IDs may not be compatible with
147
+    #         release strategy implemented in release.sh
148
+    #
149
+    local version=$(ini 1value project:version)
150
+    local prerl=$(ini 1value project:prerl)
151
+    grep ":" <<<"$prerl" && warn "colon in project:prerl may corrupt version data: $prerl"
152
+    if git_present;
153
+    then    # we are in git repo... so we can get smart
154
+        local latest_tag=$(git_fact latest_tag)
155
+        if ! git describe --tags --exact-match HEAD >&/dev/null;
156
+        then    # we are at a later commit than the last tag
157
+            local commit="$(git_fact current_branch).g$(git_fact latest_sha)"
158
+        fi
159
+        local dirty=""
160
+        local suffix=""
161
+        git_bool dirty; dirty=$?
162
+        test -n "$latest_tag" && version=${latest_tag:1}
163
+        case "$dirty:$commit" in
164
+            1:)  suffix=""               ;;
165
+            0:)  suffix="+dirty"         ;;
166
+            1:*) suffix="+$commit"       ;;
167
+            0:*) suffix="+$commit.dirty" ;;
168
+            *)   suffix=MKIT_BUG;
169
+                 warn "MKIT_BUG: bad dirt/commit detection" ;;
170
+        esac
171
+        test -n "$prerl" && suffix="-$prerl$suffix"
172
+        version="$version$suffix"
173
+    fi
174
+    echo "$version"
175
+}

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

@@ -0,0 +1,143 @@
1
+#!/bin/bash
2
+
3
+_ini_cat() {
4
+    #
5
+    # A no-op for text stream
6
+    #
7
+    while read line;
8
+    do
9
+        printf -- "%s\n" "$line"
10
+    done
11
+}
12
+
13
+_ini_expand() {
14
+    #
15
+    # Expand reference value (prefix only)
16
+    #
17
+    local line suffix ref value
18
+    while read line;                        # [foo:bar]/path
19
+    do
20
+        suffix="${line#\[*\]}"              # /path
21
+        ref="${line%$suffix}"               # [foo:bar]
22
+        ref="${ref%\]}"                     # [foo:bar
23
+        ref="${ref#\[}"                     # foo:bar
24
+        value="$(ini 1value "$ref")"        # foo_bar_value
25
+        printf -- "%s\n" "$value$suffix"    # foo_bar_value/path
26
+    done
27
+}
28
+
29
+_ini_grepkey() {
30
+    #
31
+    # Read key from a section
32
+    #
33
+    local wnt=$1
34
+    grep '.' \
35
+      | grep -v '\s*#' \
36
+      | sed -e 's/ *= */=/; s/ +$//; s/^//;' \
37
+      | grep -e "^$wnt=" \
38
+      | cut -d= -f2- \
39
+      | _ini_maybe_expand
40
+}
41
+
42
+_ini_greppath() {
43
+    #
44
+    # Read key from the right section
45
+    #
46
+    # E.g. `files:share:my/lib.sh` should read
47
+    #
48
+    #     [files:share]
49
+    #         my/lib.sh   = proj/my/lib.sh
50
+    #
51
+    local wnt="$1"
52
+    local wntkey="${wnt##*:}"
53
+    local wntsec="${wnt%:$wntkey}"
54
+    if test "$wntsec" = 'ENV';
55
+    then
56
+        local override="${!wntkey}"
57
+        if test -n "$override";
58
+        then
59
+            echo "$override"
60
+            return
61
+        fi
62
+    fi
63
+    _ini_grepsec "$wntsec" | _ini_grepkey "$wntkey"
64
+}
65
+
66
+_ini_grepsec() {
67
+    #
68
+    # Read one INI section
69
+    #
70
+    local wnt="$1"
71
+    local ok=false
72
+    grep '.' \
73
+      | grep -v '\s*#' \
74
+      | while read line;
75
+        do
76
+            case "$line" in
77
+                \[$wnt\]) ok=true;  continue ;;
78
+                \[*\])    ok=false; continue ;;
79
+            esac
80
+            $ok || continue
81
+            printf -- "%s\n" "$line"
82
+        done \
83
+      | sed -e 's/ *= */=/; s/ +$//; s/^//;'
84
+}
85
+
86
+_ini_lskeys() {
87
+    #
88
+    # List keys from a section
89
+    #
90
+    local sct="$1"
91
+    _ini_grepsec "$sct" | cut -d= -f1 | sort | uniq
92
+}
93
+
94
+_ini_maybe_expand() {
95
+    #
96
+    # Decide whether or not to expand
97
+    #
98
+    if test "$MKIT_INI_EXPAND" -gt 0;
99
+    then
100
+        MKIT_INI_EXPAND=$(( --MKIT_INI_EXPAND )) _ini_expand
101
+    else
102
+        _ini_cat
103
+    fi
104
+}
105
+
106
+ini() {
107
+    #
108
+    # do ini operation
109
+    #
110
+    local op=$1
111
+    local arg=$2
112
+    local fn
113
+    local limit=_ini_cat
114
+    case $op in
115
+        lskeys) fn=_ini_lskeys   ;;
116
+        sec)    fn=_ini_grepsec  ;;
117
+        values) fn=_ini_greppath ;;
118
+        1value) fn=_ini_greppath; limit="tail -1" ;;
119
+        *)      die "incorrect use of \`ini()\`"
120
+    esac
121
+    <"$MKIT_INI" $fn "$arg" | $limit
122
+}
123
+
124
+update_version() {
125
+    #
126
+    # Change project.version in mkit.ini at path $2 to version $1
127
+    #
128
+    local version="$1"
129
+    local inifile="$2"
130
+    local tmp=$(mktemp -t mkit.update_version.XXXXXXXX)
131
+    <"$inifile" perl -e '
132
+        my $hit = 0;
133
+        my $done = 0;
134
+        foreach (<STDIN>) {
135
+            if      ($done) { print; next; }
136
+            elsif   (m/\[project\]/) { $hit++; print; next; }
137
+            elsif   (m/\[/) { $hit = 0; print; next; }
138
+            elsif   ($hit) { s/\bversion\b( *)=( *).*/version$1=$2$ARGV[0]/ and $done++; print; }
139
+            else { print; next; }
140
+        }
141
+    ' "$version" >"$tmp" || die "failed to update version in mkit.ini"
142
+    mv "$tmp" "$inifile"
143
+}

+ 143
- 0
utils/mkit/include/mkit.sh Vedi File

@@ -0,0 +1,143 @@
1
+#!/bin/bash
2
+
3
+. "$MKIT_DIR/include/build.sh"  || die "cannot import build.sh"
4
+. "$MKIT_DIR/include/deploy.sh" || die "cannot import deploy.sh"
5
+. "$MKIT_DIR/include/release.sh" || die "cannot import release.sh"
6
+. "$MKIT_DIR/include/ini.sh"    || die "cannot import ini.sh"
7
+
8
+_valid_targets() {
9
+    #
10
+    # List valid routes
11
+    #
12
+    echo build
13
+    echo build_manpages
14
+    echo clean
15
+    echo debstuff
16
+    echo dist
17
+    echo install
18
+    echo release_x
19
+    echo release_y
20
+    echo release_z
21
+    echo rpmstuff
22
+    echo uninstall
23
+    echo vbump_x
24
+    echo vbump_y
25
+    echo vbump_z
26
+}
27
+
28
+debug() {
29
+    #
30
+    # Print debug message
31
+    #
32
+    $MKIT_DEBUG || return 0
33
+    echo "MKIT_DEBUG: ${FUNCNAME[1]}()" "$@" >&2
34
+}
35
+
36
+debug_var() {
37
+    #
38
+    # Print debug message
39
+    #
40
+    $MKIT_DEBUG || return 0
41
+    local __mkit_debug_var_name__
42
+    for __mkit_debug_var_name__ in "$@";
43
+    do
44
+        {
45
+            echo -n "MKIT_DEBUG: ${FUNCNAME[1]}():"
46
+            echo -n " $__mkit_debug_var_name__"
47
+            echo -n "='${!__mkit_debug_var_name__}'"
48
+            echo
49
+        } >&2
50
+    done
51
+}
52
+
53
+die() {
54
+    #
55
+    # Exit with message and non-zero exit status
56
+    #
57
+    echo "fatal: $*" >&2
58
+    exit 4
59
+}
60
+
61
+_compver() {
62
+    #
63
+    # True if version $1 matches our version
64
+    #
65
+    # If our x is 0, check first two fragments, otherwise check just
66
+    # the x.  Fragments must equal.
67
+    #
68
+    local their_ver our_x our_y their_x their_y
69
+    their_ver="$1"
70
+    their_x=${their_ver%%.*}
71
+    their_y=${their_ver##$their_x.}
72
+    their_y=${their_y%%.*}
73
+    our_x=${MKIT_VERSION%%.*}
74
+    our_y=${MKIT_VERSION##$our_x.}
75
+    our_y=${our_y%%.*}
76
+    debug_var MKIT_VERSION our_x our_y their_ver their_x their_y
77
+    test "$their_x" -eq "$our_x" || return 1
78
+    test "$our_x" -eq 0 && {
79
+        test "$their_y" = "$our_y"
80
+        return $?
81
+    }
82
+    return 0
83
+}
84
+
85
+_chkiniversion() {
86
+    #
87
+    # Check if ini version is supported
88
+    #
89
+    # Look for "#mkit version=0.0.0" or similar in first or last
90
+    # 3 lines of the file; then check if the version is supported.
91
+    #
92
+    local ver_line
93
+    local their_ver
94
+    ver_line=$(
95
+        {
96
+            head -3 "$MKIT_INI"
97
+            tac "$MKIT_INI" | tail -3
98
+        } | grep -m 1 -E '^# *mkit +version *= *v?[0-9]+\.[0-9]+\.[0-9]+'
99
+    )
100
+    test -n "$ver_line" \
101
+     || die "version mark ('#mkit version=x.y.z') not found in: $MKIT_INI"
102
+    their_ver="$(tr -d '[:blank:]v' <<<"${ver_line##*=}")"
103
+    _compver "$their_ver" \
104
+     || die "bad mkit.ini version: $their_ver does not match $MKIT_VERSION"
105
+}
106
+
107
+mkit_init() {
108
+    #
109
+    # Do basic initialization
110
+    #
111
+    # Check for ini file and some variables
112
+    #
113
+    $MKIT_DRY && MKIT_DEBUG=true
114
+    MKIT_PROJ_PKGNAME=$(ini 1value "project:pkgname")
115
+    test -f "$MKIT_INI" || die "cannot find mkit.ini: $MKIT_INI"
116
+    _chkiniversion
117
+    test -n "$(tr -d '[:space:]' <<<"$MKIT_LOCAL")" \
118
+     || die "MKIT_LOCAL must be non-blank: '$MKIT_LOCAL'"
119
+}
120
+
121
+route() {
122
+    #
123
+    # Call correct function based on $1
124
+    #
125
+    if _valid_targets | grep -qwx "^$1";
126
+    then
127
+        "$1"
128
+    else
129
+        {
130
+            echo "usage: $(basename "$0") TARGET"
131
+            echo
132
+            echo "valid targets:"
133
+            _valid_targets | sed 's/^/    /'
134
+        } >&2
135
+    fi
136
+}
137
+
138
+warn() {
139
+    #
140
+    # Print warning message
141
+    #
142
+    echo "$@" >&2
143
+}

+ 180
- 0
utils/mkit/include/release.sh Vedi File

@@ -0,0 +1,180 @@
1
+#!/bin/bash
2
+
3
+. "$MKIT_DIR/include/ini.sh"   || die "cannot import ini.sh"
4
+. "$MKIT_DIR/include/facts.sh" || die "cannot import facts.sh"
5
+
6
+_bump_version() {
7
+    #
8
+    # Bump version on stdin by level $1 (x, y or z)
9
+    #
10
+    local rlevel=$1
11
+    local old
12
+    read -r old
13
+    local oldx=${old%.*.*}
14
+    local oldz=${old#*.*.}
15
+    local tmpy=${old%.*}
16
+    local oldy=${tmpy#*.}
17
+    local new=""
18
+    case $rlevel in
19
+        x) new="$((oldx+MKIT_BUMPSIZE)).0.0"            ;;
20
+        y) new="$oldx.$((oldy+MKIT_BUMPSIZE)).0"        ;;
21
+        z) new="$oldx.$oldy.$((oldz+MKIT_BUMPSIZE))"    ;;
22
+        *) die "invalid release level: $1"  ;;
23
+    esac
24
+    echo "$new"
25
+}
26
+
27
+_relck() {
28
+    #
29
+    # Die if blocking condition $1 is detected
30
+    #
31
+    local condition="$1"
32
+    local x
33
+    case "$condition" in
34
+        git_present)
35
+            git rev-parse HEAD >&/dev/null\
36
+             || die "cannot do this outside git repo"
37
+            ;;
38
+        at_relsrc)
39
+            local relsrc=$(ini 1value project:relsrc)
40
+            git_fact current_branch \
41
+              | grep -qFx "$relsrc" \
42
+             || die "you are not on release source branch: $relsrc"
43
+            ;;
44
+        not_dirty)
45
+            git diff --shortstat 2>/dev/null \
46
+              | grep -q . \
47
+             && die "tree is dirty: $dirt"
48
+            ;;
49
+        tags_ok)
50
+            git_fact latest_tag \
51
+              | grep -q . \
52
+             || die "cannot find latest tag"
53
+            ;;
54
+        vbump_hot)
55
+            git diff-tree --no-commit-id --name-only -r HEAD \
56
+              | grep -qFx mkit.ini \
57
+             || die "last change must be version bump in mkit.ini"
58
+            ;;
59
+        no_wip)
60
+            git_fact reldiff \
61
+              | grep '^....... WIP ' \
62
+             && die "WIP commit since $(git_fact latest_tag)"
63
+            ;;
64
+        ini_version)
65
+            local oracle=$(git_fact latest_version | _bump_version "$rlevel")
66
+            ini 1value project:version  \
67
+              | grep -qFx "$oracle" \
68
+             || die "new version not in mkit.ini: $oracle"
69
+            ;;
70
+        *)
71
+            die "unknown release check: $condition"
72
+            ;;
73
+    esac
74
+}
75
+
76
+_release() {
77
+    #
78
+    # Prepare release
79
+    #
80
+    # Span release routines: make a signed tag, check branch
81
+    # and update release branch
82
+    #
83
+    # FIXME: Using project:prerl as build.sh:semver() does may not be
84
+    #        compatible with this release strategy
85
+    #
86
+    local rlevel=$1
87
+    local newtag
88
+    local reldst
89
+
90
+    _relck git_present
91
+    _relck at_relsrc
92
+    _relck not_dirty
93
+    _relck tags_ok
94
+    _relck vbump_hot
95
+    _relck no_wip
96
+    _relck ini_version
97
+
98
+    newtag=$(git_fact latest_version | _bump_version "$rlevel" | git_ver2tag )
99
+    set -e
100
+    debug_var newtag
101
+    $MKIT_DRY && return
102
+    git tag -m "$(_release_msg)" "$newtag"
103
+
104
+    reldst=$(ini 1value project:reldst)
105
+    debug_var reldst
106
+    if test -n "$reldst";
107
+    then
108
+        git branch -f "$reldst" "$newtag"
109
+    fi
110
+}
111
+
112
+_release_msg() {
113
+    #
114
+    # Generate message for annotated tag
115
+    #
116
+    # The last commit before issuing a release must be "Bump version" commit
117
+    # suggested by _vbump_gitmsg() and  manually edited by user.  Since the
118
+    # commit contains changelog, this function just uses the message body.
119
+    #
120
+    # The sort message (first line) is replaced with a nicer one (with project
121
+    # name, codename and version).
122
+    #
123
+    echo "$(ini 1value project:name) $newtag - $(ini 1value project:codename)"
124
+    echo
125
+    git show -s --format=%B \
126
+      | tail -n +3
127
+}
128
+
129
+_vbump() {
130
+    local rlevel="$1"
131
+    local nextver   # after the bump
132
+    _relck git_present
133
+    _relck at_relsrc
134
+    _relck not_dirty
135
+    nextver=$(ini 1value project:version | _bump_version "$rlevel")
136
+    debug_var nextver
137
+    $MKIT_DRY && return
138
+    update_version "$nextver" mkit.ini \
139
+      || die "failed to update version in mkit.ini"
140
+    git add mkit.ini \
141
+      || die "failed to add mkit.ini to the index"
142
+    git commit -e -m "$(_vbump_gitmsg)"
143
+}
144
+
145
+_vbump_gitmsg() {
146
+    echo "Bump version"
147
+    echo ""
148
+    echo "Overview of changes:"
149
+    echo ""
150
+    git_fact reldiff \
151
+      | sed '
152
+            s/^[a-f0-9]\{7\} / *  &/; t PATHS
153
+            s/^/        /
154
+            :PATHS
155
+        '
156
+}
157
+
158
+release_x() {
159
+    _release x
160
+}
161
+
162
+release_y() {
163
+    _release y
164
+}
165
+
166
+release_z() {
167
+    _release z
168
+}
169
+
170
+vbump_x() {
171
+    _vbump x
172
+}
173
+
174
+vbump_y() {
175
+    _vbump y
176
+}
177
+
178
+vbump_z() {
179
+    _vbump z
180
+}

+ 82
- 0
utils/mkit/make Vedi File

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

+ 50
- 0
utils/mkit/mkit.mk Vedi File

@@ -0,0 +1,50 @@
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
+build:
9
+	@$(MKIT_DIR)/make build
10
+
11
+manpages: build
12
+	@$(MKIT_DIR)/make build_manpages
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_x:
30
+	@$(MKIT_DIR)/make release_x
31
+
32
+release_y:
33
+	@$(MKIT_DIR)/make release_y
34
+
35
+release_z:
36
+	@$(MKIT_DIR)/make release_z
37
+
38
+uninstall:
39
+	@$(MKIT_DIR)/make uninstall
40
+
41
+vbump_x:
42
+	@$(MKIT_DIR)/make vbump_x
43
+
44
+vbump_y:
45
+	@$(MKIT_DIR)/make vbump_y
46
+
47
+vbump_z:
48
+	@$(MKIT_DIR)/make vbump_z
49
+
50
+.PHONY: all clean dist rpmstuff install uninstall release_x release_y release_z vbump_x vbump_y vbump_z