Browse Source

Initial commit

Alois Mahdal 3 years ago
commit
49757f8931

+ 1
- 0
.gitignore View File

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

+ 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
+# preupg - JAT test library for preupg
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
+preupg
2
+======
3
+
4
+JAT test library for preupg

+ 49
- 0
mkit.ini View File

@@ -0,0 +1,49 @@
1
+[project]
2
+    version     = 0.0.0
3
+    name        = preupg
4
+    tagline     = JAT test library for preupg
5
+    pkgname     = shellfu-bash-preupg
6
+    maintainer  = Alois Mahdal <amahdal+jats@redhat.com>
7
+    vcs_browser = https://github.com/upgrades-migrations/shellfu-bash-preupg
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
+
21
+[ENV]
22
+    PREFIX = /usr/local
23
+
24
+[roots]
25
+    doc    = [ENV:PREFIX]/share/doc/shellfu-bash-preupg
26
+    sfmod  = [ENV:PREFIX]/share/shellfu/include-bash
27
+    sfdata = [ENV:PREFIX]/share/shellfu-bash-preupg
28
+
29
+[macros]
30
+    __SHELLFU_MODNAME__ = preupg
31
+    __SHELLFU_MODHOME__ = [roots:sfdata]
32
+    __SHELLFU_MODDESC__ = JATS is a testing framework for Shell-based test suites.
33
+    __SHELLFU_MODDESC__ =
34
+    __SHELLFU_MODDESC__ = This sub-package contains test modules to help test preupgrade-assistant
35
+    __SHELLFU_MODDESC__ = AKA preupg.
36
+
37
+    __SHELLFU_VREQ_LO__ = 0.10.8
38
+    __SHELLFU_VREQ_HI__ = 0.11
39
+    __SHELLFU_REQUIRE__ = shellfu-bash-dist
40
+    __SHELLFU_REQUIRE__ = shellfu-bash-pxpath
41
+
42
+[files]
43
+    doc    = README.md
44
+    sfmod  = src/preupg.sh
45
+    sfmod  = src/preupg_upath.sh
46
+    sfmod  = src/preupg_fupath.sh
47
+    sfdata = src/builtins
48
+
49
+#mkit version=0.0.32

+ 52
- 0
packaging/template.spec View File

@@ -0,0 +1,52 @@
1
+%global sfincb %{_datadir}/shellfu/include-bash
2
+%global sfmodn __SHELLFU_MODNAME__
3
+%global shellfu_req shellfu >= __SHELLFU_VREQ_LO__, shellfu < __SHELLFU_VREQ_HI__
4
+%global jat_req shellfu-bash-jat >= 0.0.1, shellfu-bash-jat < 0.0.2
5
+
6
+Name:       __MKIT_PROJ_PKGNAME__
7
+Version:    __MKIT_PROJ_VERSION__
8
+Release:    1%{?dist}
9
+Summary:    __MKIT_PROJ_NAME__ - __MKIT_PROJ_TAGLINE__
10
+URL:        __MKIT_PROJ_VCS_BROWSER__
11
+License:    LGPLv2
12
+Source0:    %{name}-%{version}.tar.gz
13
+BuildArch:  noarch
14
+BuildRequires: jattool-tdk
15
+
16
+Requires: %shellfu_req
17
+Requires: %jat_req
18
+Requires: shellfu-bash-dist
19
+Requires: shellfu-bash-pxpath
20
+%description
21
+__SHELLFU_MODDESC__
22
+
23
+%prep
24
+%setup -q
25
+
26
+%build
27
+make %{?_smp_mflags} PREFIX=/usr
28
+
29
+%install
30
+%make_install PREFIX=/usr
31
+
32
+%files
33
+%dir %{_datadir}/%{name}
34
+%dir %{_datadir}/%{name}/builtins
35
+%dir %{_docdir}/%{name}
36
+%doc %{_docdir}/%{name}/README.md
37
+%{_datadir}/%{name}/builtins/3rdparty.mdef
38
+%{_datadir}/%{name}/builtins/error.mdef
39
+%{_datadir}/%{name}/builtins/failed.mdef
40
+%{_datadir}/%{name}/builtins/fixed.mdef
41
+%{_datadir}/%{name}/builtins/informational.mdef
42
+%{_datadir}/%{name}/builtins/needs_action.mdef
43
+%{_datadir}/%{name}/builtins/needs_inspection.mdef
44
+%{_datadir}/%{name}/builtins/not_applicable.mdef
45
+%{_datadir}/%{name}/builtins/pass.mdef
46
+%{sfincb}/%{sfmodn}.sh
47
+%{sfincb}/%{sfmodn}_fupath.sh
48
+%{sfincb}/%{sfmodn}_upath.sh
49
+
50
+%changelog
51
+
52
+# specfile built with MKit __MKIT_SELF_VERSION__

+ 10
- 0
src/builtins/3rdparty.mdef View File

@@ -0,0 +1,10 @@
1
+[preupgrade]
2
+author = Joe "Built-In" Example <joe@example.com>
3
+
4
+[MODULE]
5
+GROUP = 3rdparty
6
+NAME = a_custom_module
7
+CODE = solution_file "Solution protected by non-disclosure agreement, actually."
8
+CODE = exit_pass
9
+
10
+# vim: set filetype=ini:

+ 10
- 0
src/builtins/error.mdef View File

@@ -0,0 +1,10 @@
1
+[preupgrade]
2
+author = Joe "Built-In" Example <joe@example.com>
3
+
4
+[MODULE]
5
+GROUP = preupgrade_assistant_fupath__builtin
6
+NAME = error
7
+CODE = solution_file "No solution known, actually."
8
+CODE = exit_error
9
+
10
+# vim: set filetype=ini:

+ 11
- 0
src/builtins/failed.mdef View File

@@ -0,0 +1,11 @@
1
+[preupgrade]
2
+author = Joe "Built-In" Example <joe@example.com>
3
+
4
+[MODULE]
5
+GROUP = preupgrade_assistant_fupath__builtin
6
+NAME = failed
7
+CODE = solution_file "No solution possible, actually."
8
+CODE = log_extreme_risk "really extreme risk"
9
+CODE = exit_fail
10
+
11
+# vim: set filetype=ini:

+ 10
- 0
src/builtins/fixed.mdef View File

@@ -0,0 +1,10 @@
1
+[preupgrade]
2
+author = Joe "Built-In" Example <joe@example.com>
3
+
4
+[MODULE]
5
+GROUP = preupgrade_assistant_fupath__builtin
6
+NAME = fixed
7
+CODE = solution_file "Solution already prepared, actually."
8
+CODE = exit_fixed
9
+
10
+# vim: set filetype=ini:

+ 10
- 0
src/builtins/informational.mdef View File

@@ -0,0 +1,10 @@
1
+[preupgrade]
2
+author = Joe "Built-In" Example <joe@example.com>
3
+
4
+[MODULE]
5
+GROUP = preupgrade_assistant_fupath__builtin
6
+NAME = informational
7
+CODE = solution_file "Solution already done: informing you, actually."
8
+CODE = exit_informational
9
+
10
+# vim: set filetype=ini:

+ 11
- 0
src/builtins/needs_action.mdef View File

@@ -0,0 +1,11 @@
1
+[preupgrade]
2
+author = Joe "Built-In" Example <joe@example.com>
3
+
4
+[MODULE]
5
+GROUP = preupgrade_assistant_fupath__builtin
6
+NAME = needs_action
7
+CODE = solution_file "Solution too risky, actually."
8
+CODE = log_high_risk "quite high risk"
9
+CODE = exit_fail
10
+
11
+# vim: set filetype=ini:

+ 11
- 0
src/builtins/needs_inspection.mdef View File

@@ -0,0 +1,11 @@
1
+[preupgrade]
2
+author = Joe "Built-In" Example <joe@example.com>
3
+
4
+[MODULE]
5
+GROUP = preupgrade_assistant_fupath__builtin
6
+NAME = needs_inspection
7
+CODE = solution_file "Solution mildly risky, actually."
8
+CODE = log_medium_risk "some medium risk"
9
+CODE = exit_fail
10
+
11
+# vim: set filetype=ini:

+ 10
- 0
src/builtins/not_applicable.mdef View File

@@ -0,0 +1,10 @@
1
+[preupgrade]
2
+author = Joe "Built-In" Example <joe@example.com>
3
+
4
+[MODULE]
5
+GROUP = preupgrade_assistant_fupath__builtin
6
+NAME = not_applicable
7
+CODE = solution_file "Solution won't be even displayed, actually."
8
+CODE = exit_not_applicable
9
+
10
+# vim: set filetype=ini:

+ 10
- 0
src/builtins/pass.mdef View File

@@ -0,0 +1,10 @@
1
+[preupgrade]
2
+author = Joe "Built-In" Example <joe@example.com>
3
+
4
+[MODULE]
5
+GROUP = preupgrade_assistant_fupath__builtin
6
+NAME = pass
7
+CODE = solution_file "No solution needed, actually."
8
+CODE = exit_pass
9
+
10
+# vim: set filetype=ini:

+ 986
- 0
src/preupg.sh.skel View File

@@ -0,0 +1,986 @@
1
+#!/bin/bash
2
+
3
+#
4
+# preupgrade-assistant testing utilities
5
+#
6
+# This ASRT module contains various functions to support testing of
7
+# preupgrade-assistant and its modules.  Refer to specific functions
8
+# for details.
9
+#
10
+
11
+shellfu import dist
12
+shellfu import jat_dump
13
+shellfu import preupg_fupath
14
+shellfu import pxpath
15
+
16
+#
17
+# Default rule id (XCCDF) to parse data from
18
+#
19
+PREUPG__RULE=${PREUPG__RULE:-}
20
+
21
+#
22
+# Regex to filter rules (XCCDF ids) to only run by preupg__run1()
23
+#
24
+PREUPG__RULE_REGEX=${PREUPG__RULE_REGEX:-.}
25
+
26
+#
27
+# Upgrade path
28
+#
29
+# This can be one of following:
30
+#
31
+#  *  To test with packaged upgrade paths, set this to the module
32
+#     package suffix, e.g. el6toel7.
33
+#
34
+#  *  To test with own generated upgrade path, set this to path
35
+#     to 'all-xccdf.xml' in the root of the upgrade path tree.
36
+#
37
+#  *  You can also use '@BUILTIN' alias to test with quick&trivial
38
+#     upgrade path, e.g. '@pass' to test with an upgrade path that
39
+#     simply passes.  For details in built-in paths, see
40
+#     `library(preupgrade-assistant/fupath)`
41
+#
42
+PREUPG__UPATH=${PREUPG__UPATH:-el6toel7}
43
+
44
+#
45
+# Valid exit statuses from preupg (ES_EX syntax)
46
+#
47
+# preupg__run1() will raise test failure if exit status does not
48
+# match this expression.  Format is described in jat documentation.
49
+# (See `sfdoc jat`.)
50
+#
51
+PREUPG__VALID_ES=${PREUPG__VALID_ES:-0-2}
52
+
53
+# FIXME: ^^^ Holy mess; see http://post-office.corp.redhat.com/archives/rhel-inplaceupgrades/2016-September/msg00011.html
54
+
55
+#
56
+# Override what packages are considered as native
57
+#
58
+# See preupg__run1() for details.
59
+#
60
+PREUPG__DISTNATIVE=${PREUPG__DISTNATIVE:-}
61
+
62
+#
63
+# Strip control characters from preupg stdout
64
+#
65
+# When TESTOUT.log et al. are acccessed using browsers, the control
66
+# characters in preupg will make many browsers treat the file as
67
+# binary, i.e. offer download instead of opening it.
68
+#
69
+# Set this variable to 'false' to keep the output verbatim.
70
+#
71
+PREUPG__STRIPCTL=${PREUPG__STRIPCTL:-true}
72
+
73
+preupg__assert() {
74
+    #
75
+    # Assert value of rule (module) result property
76
+    #
77
+    # Usage:
78
+    #     preupg__assert [-r RULE] [-N] FLD VALUE [[-N] FLD VALUE]
79
+    #
80
+    # In order for assert to pass, FLD must match VALUE.  If -N is passed,
81
+    # the meaning of assert is reversed, i.e. assert will fail if condition
82
+    # is satisfied.  Passing multiple pairs of FLD and VALUE performs
83
+    # multiple independent asserts with the added value of better log
84
+    # readability.
85
+    #
86
+    # For numeric fields, VALUE is matched for numeric equality.  For string
87
+    # fields, VALUE is matched as Basic Regular Expression.
88
+    #
89
+    # FLD can be:
90
+    #
91
+    #     risk - risk
92
+    #     risk.slight - slight risk
93
+    #     risk.medium - medium risk
94
+    #     risk.high - high risk
95
+    #     risk.extreme - extreme risk
96
+    #     riskn - number of risks
97
+    #     riskn.slight - number of slight risks
98
+    #     riskn.medium - number of medium risks
99
+    #     riskn.high - number of high risks
100
+    #     riskn.extreme - number of extreme risks
101
+    #     msg - message
102
+    #     msg.debug - debug message
103
+    #     msg.info - info message
104
+    #     msg.warning - warning message
105
+    #     msg.error - error message
106
+    #     msgn - number of messages
107
+    #     msgn.debug - number of debug messages
108
+    #     msgn.info - number of info messages
109
+    #     msgn.warning - number of warning messages
110
+    #     msgn.error - number of error messages
111
+    #     solution - solution text
112
+    #     result - module result
113
+    #
114
+    # By default, rule $PREUPG__RULE is queried, but you can
115
+    # override that using -r argument.  (It's mandatory to use at least one
116
+    # of these methods.)
117
+    #
118
+    local code
119
+    local usage="usage: preupg__assert [-r RULE] [-N] FLD VALUE [[-N] FLD VALUE].."
120
+    local Rule=$PREUPG__RULE
121
+    local conds=()
122
+    local Ellipsis=false
123
+    local cond
124
+    while true; do case $1 in
125
+        -r|--rule) Rule=$2; shift 2 || { jat__log_error "$usage"; return 2; } ;;
126
+        *)  break ;;
127
+    esac done
128
+    test -n "$Rule"  || {
129
+        jat__log_error "which rule to assert?  set \$PREUPG__RULE or use -r|--rule argument"
130
+        return 2
131
+    }
132
+    while true; do case $1 in
133
+        "")
134
+            break
135
+            ;;
136
+        -N)
137
+            conds+=("neg:${2,,}:$3")
138
+            shift 3 || {
139
+                jat__log_error "$usage"
140
+                return 2
141
+            }
142
+            ;;
143
+        *)
144
+            conds+=("pos:${1,,}:$2")
145
+            shift 2 || {
146
+                jat__log_error "$usage"
147
+                return 2
148
+            }
149
+            ;;
150
+    esac done
151
+    case ${#conds[@]} in
152
+        0)
153
+            jat__log_error "$usage"
154
+            return 2
155
+            ;;
156
+        1)
157
+            __preupg__assert1 "${conds[0]}"
158
+            return $?
159
+            ;;
160
+        *)
161
+            jat__log_info "rule $Rule has:"
162
+            for cond in "${conds[@]}";
163
+            do
164
+                Ellipsis=true __preupg__assert1 "$cond"
165
+            done
166
+            ;;
167
+    esac
168
+}
169
+
170
+preupg__dump_node() {
171
+    #
172
+    # Dump node of $PREUPG__RULE
173
+    #
174
+    preupg__get_node \
175
+      | jat_dump__pipe "NODE-${PREUPG__RULE}"
176
+}
177
+
178
+preupg__get_fixtext() {
179
+    #
180
+    # Get solution text (fixtext) of rule id $PREUPG__RULE
181
+    #
182
+    __preupg__resultxpath \
183
+        "//ns0:Rule[@id='$PREUPG__RULE']/ns0:fixtext/text()"
184
+}
185
+
186
+preupg__get_node() {
187
+    #
188
+    # Get whole result node from rule $PREUPG__RULE
189
+    #
190
+    __preupg__resultxpath \
191
+        "//ns0:rule-result[@idref='$PREUPG__RULE']"
192
+}
193
+
194
+preupg__get_result() {
195
+    #
196
+    # Get 'result' field from rule $PREUPG__RULE
197
+    #
198
+    __preupg__resultxpath \
199
+        "//ns0:rule-result[@idref='$PREUPG__RULE']/ns0:result/text()"
200
+}
201
+
202
+preupg__get_risks() {
203
+    #
204
+    # Get risks of severity $1 or all
205
+    #
206
+    # 'preupg.risk.' prefix is removed.  If severity is given, get only those
207
+    # risks and also that part of prefix is removed.
208
+    #
209
+    # For example,
210
+    #
211
+    #     $ PREUPG__RULE=xccdf_blah
212
+    #     $ preupg__get_risks
213
+    #     HIGH: foo
214
+    #     MEDIUM: bar
215
+    #     MEDIUM: baz
216
+    #     $ preupg__get_risks HIGH
217
+    #     foo
218
+    #     $
219
+    #
220
+    local sev=${1^^}
221
+    local outfn=preupg__get_stderr
222
+    $__PREUPG__LOSCAP \
223
+     && outfn=preupg__get_stdout
224
+    case $sev in
225
+        "")
226
+            $outfn \
227
+              | grep -E '^preupg\.risk\.(SLIGHT|MEDIUM|HIGH|EXTREME): ' \
228
+              | cut -d. -f3-
229
+            ;;
230
+        SLIGHT|MEDIUM|HIGH|EXTREME)
231
+            $outfn \
232
+              | grep -E "^preupg\.risk\.$sev: " \
233
+              | cut -d. -f3-
234
+            ;;
235
+        *)
236
+            jat__log_error "unknown risk severity: $sev"
237
+            return 2
238
+            ;;
239
+    esac
240
+}
241
+
242
+preupg__get_messages() {
243
+    #
244
+    # Get log messages of severity $1 or all
245
+    #
246
+    # 'preupg.log.' prefix is removed.  If severity is given, get only those
247
+    # messages and also that part of prefix is removed.
248
+    #
249
+    # For example,
250
+    #
251
+    #     $ PREUPG__RULE=xccdf_blah
252
+    #     $ preupg__get_messages
253
+    #     INFO: hello
254
+    #     INFO: Joe
255
+    #     DEBUG: lalala lalalala
256
+    #     $ preupg__get_messages DEBUG
257
+    #     lalala lalalala
258
+    #     $
259
+    #
260
+    local sev=${1^^}
261
+    local outfn=preupg__get_stderr
262
+    $__PREUPG__LOSCAP \
263
+     && outfn=preupg__get_stdout
264
+    case $sev in
265
+        "")
266
+            $outfn \
267
+              | grep -E '^preupg\.log\.(ERROR|WARNING|INFO|DEBUG): ' \
268
+              | cut -d. -f3-
269
+            ;;
270
+        ERROR|WARNING|INFO|DEBUG)
271
+            $outfn \
272
+              | grep -E "^preupg\.log\.$sev: " \
273
+              | cut -d. -f3-
274
+            ;;
275
+        *)
276
+            jat__log_error "unknown log message severity: $sev"
277
+            return 2
278
+            ;;
279
+    esac
280
+}
281
+
282
+preupg__get_stdout() {
283
+    #
284
+    # Get stdout of rule $PREUPG__RULE (eg. for grepping risks)
285
+    #
286
+    __preupg__resultxpath \
287
+        "//ns0:rule-result[@idref='$PREUPG__RULE']/ns0:check/ns0:check-import[@import-name='stdout']/text()"
288
+}
289
+
290
+preupg__get_stderr() {
291
+    #
292
+    # Get stderr of rule $PREUPG__RULE (eg. for grepping risks)
293
+    #
294
+    preupg__haslim loscap
295
+    __preupg__resultxpath \
296
+        "//ns0:rule-result[@idref='$PREUPG__RULE']/ns0:check/ns0:check-import[@import-name='stderr']/text()"
297
+}
298
+
299
+preupg__collect_stderrs() {
300
+    #
301
+    # Collect stderrs of all rules, prefix by rule id
302
+    #
303
+    local ruleid
304
+    preupg__haslim loscap
305
+    __preupg__lsrules_xml \
306
+      | while read -r ruleid;
307
+        do
308
+            __preupg__resultxpath \
309
+                "//ns0:rule-result[@idref='$ruleid']/ns0:check/ns0:check-import[@import-name='stderr']/text()" \
310
+              | sed -e "s/^/$ruleid: /"
311
+        done
312
+}
313
+
314
+preupg__collect_stray() {
315
+    #
316
+    # Collect stray outputs (ie. not risks or log messages), prefix by rule id
317
+    #
318
+    local tmp
319
+    local ruleid
320
+    preupg__haslim loscap && {
321
+        __preupg__collect_stray_loscap
322
+        return $?
323
+    }
324
+    tmp=$(mktemp -td preupg__collect_stray.XXXXXXXX)
325
+    pushd "$tmp" >/dev/null
326
+        __preupg__lsrules_xml \
327
+          | while read -r ruleid;
328
+            do
329
+                __preupg__resultxpath \
330
+                    "//ns0:rule-result[@idref='$ruleid']/ns0:check/ns0:check-import[@import-name='stdout']/text()" \
331
+                    >"stdout"
332
+                __preupg__resultxpath \
333
+                    "//ns0:rule-result[@idref='$ruleid']/ns0:check/ns0:check-import[@import-name='stderr']/text()" \
334
+                    >"stderr"
335
+                test -s "stdout" && sed -e "s/^/$ruleid:stdout: /" "stdout"
336
+                test -s "stderr" || continue
337
+                <"stderr" grep -v -E \
338
+                    -e '^preupg\.log\.(ERROR|WARNING|INFO|DEBUG): ' \
339
+                    -e '^preupg\.risk\.(SLIGHT|MEDIUM|HIGH|EXTREME): ' \
340
+                    > "stderr.stray"
341
+                grep -q . "stderr.stray" || continue
342
+                sed -e "s/^/$ruleid:stderr: /" <"stderr.stray"
343
+            done
344
+    popd >/dev/null
345
+    rm -r "$tmp"
346
+}
347
+
348
+preupg__lsrules_ast() {
349
+    #
350
+    # List selected rules from last asssessment result
351
+    #
352
+    __preupg__lsrules_xml
353
+}
354
+
355
+preupg__rmresult() {
356
+    #
357
+    # Remove assessment results
358
+    #
359
+    # Keeps cache and logs; use preupg__Cleanup() to clean
360
+    # up after test.
361
+    #
362
+    jat__cmd rm -rf /root/preupgrade
363
+    jat__cmd rm -rf /root/preupgrade-results
364
+}
365
+
366
+preupg__Run1() {
367
+    #
368
+    # Create phase and just run preupg__run1 $@
369
+    #
370
+    # Wrapper around preupg__run1() with phase creation.
371
+    # Call this before starting case loop such as xcase__run(),
372
+    # where you would try out multiple cache-independent cases.
373
+    #
374
+    jat__pstarts "run preupg once"
375
+        preupg__run1 "$@"
376
+    jat__pend
377
+}
378
+
379
+preupg__Cleanup() {
380
+    #
381
+    # Create final cleanup phase (submit & full cleanup)
382
+    #
383
+    # If results (tarball) are found, jat__submit() them (tarball and
384
+    # html and xml). Finally clean up results, logs and cache.
385
+    #
386
+    # Pass -n to skip submitting of the results.
387
+    #
388
+    local submit=true
389
+    test "x$1" == "-n" && submit=false
390
+    jat__pstartc
391
+        # we assume that if tarball exists, html and xml both exist
392
+        # as well.
393
+        if $submit \
394
+            && test -n "$(preupg__get_latest_tar)";
395
+        then
396
+            jat__submit "/root/preupgrade/result.html" "result.html"
397
+            jat__submit "/root/preupgrade/result.xml" "result.xml"
398
+            jat__submit "$(preupg__get_latest_tar)"
399
+        fi
400
+        preupg__rmresult
401
+    jat__pend
402
+}
403
+
404
+preupg__run1() {
405
+    #
406
+    # Run preupg once without interaction; pass $@ down
407
+    #
408
+    # Runs preupg with --force argument (to suppress questions) and performs
409
+    # additional checks on assessment. Any arguments to this function are
410
+    # simply passed down to the preupg call (after any arguments needed
411
+    # for overrides, see below).
412
+    #
413
+    # Exit status is normally same as exit status from preupg, but statuses
414
+    # defined in $PREUPG__VALID_ES don't cause assert fail
415
+    # (these normally represent upgrade risk level so are considered "normal").
416
+    # However, if additional checks done by this routine fail, exit status
417
+    # is increased by 100.
418
+    #
419
+    # Several overrides can be specified via following global
420
+    # variables:
421
+    #
422
+    #  *  If $PREUPG__RULE_REGEX was specified, modules
423
+    #     are selected using that regular expression and passed down
424
+    #     using --select-rules parameter.
425
+    #
426
+    #  *  If $PREUPG__DISTNATIVE is specified, preupg config
427
+    #     is altered for this run to override what packages are treated
428
+    #     as native.  The variable may have following values:
429
+    #
430
+    #       *  `sign` - packages signed by vendor (default preupg behavior)
431
+    #       *  `all` - all installed packages
432
+    #       *  `-NAME1[,-NAME2,..]` - all currently installed packages
433
+    #          except NAME1, NAME2 and so on
434
+    #       *  `/path/to/list` - only packages listed in the file (names)
435
+    #
436
+    #  *  If $PREUPG__UPATH points to path to all-xccdf.xml,
437
+    #     or has form of built-in fake path (`@*`) custom upgrade path is
438
+    #     used. (see `$PREUPG__UPATH` for details`)
439
+    #
440
+    # Note that these overrides only affect the single run; i.e. runs
441
+    # outside this function work normally, and you can change mentioned
442
+    # variables between run.
443
+    #
444
+    jat__log_info "PREUPG__UPATH='$PREUPG__UPATH'"
445
+    jat__log_info "PREUPG__RULE_REGEX='$PREUPG__RULE_REGEX'"
446
+    jat__log_info "PREUPG__DISTNATIVE='$PREUPG__DISTNATIVE'"
447
+    local es=0          # exit status
448
+    local run1tmp       # our temporary dir
449
+    run1tmp="$(mktemp -d -t preupg__run1.XXXXXXXX)"
450
+    __preupg__mkfupath_builtin
451
+    __preupg__dno_enable
452
+    case "$PREUPG__RULE_REGEX" in
453
+        .|"")  __preupg__preupg "$@"
454
+            es=$?
455
+            ;;
456
+        *)  __preupg__preupg \
457
+                --select-rules "$(__preupg__lsrules_upath | paste -sd,)" \
458
+                "$@"
459
+            es=$?
460
+            ;;
461
+    esac
462
+    __preupg__dno_disable
463
+    rm -r "$run1tmp"
464
+    # Additional checks
465
+    if preupg__collect_stray | grep -q .;
466
+    then
467
+        jat__fail "stray module output found"
468
+        preupg__collect_stray \
469
+          | jat_dump__pipe -E STRAY_OUTPUT
470
+        es=$((100 + es))
471
+    fi
472
+    return $es
473
+}
474
+
475
+preupg__get_latest_tar() {
476
+    #
477
+    # Print path to latest tarball; false if there was none
478
+    #
479
+    test -d /root/preupgrade-results || {
480
+        warn "no result found; has preupg been run?"
481
+        return 3
482
+    }
483
+    find /root/preupgrade-results \
484
+        -name "preupg_results-*.tar.gz" \
485
+      | sort -n \
486
+      | tail -1 \
487
+      | grep .      # grep to normalize exit status
488
+}
489
+
490
+preupg__tar_extract() {
491
+    #
492
+    # Extract last tarball and print path to the extracted directory
493
+    #
494
+    local tarball_path
495
+    local dirname
496
+    tarball_path=$(preupg__get_latest_tar)
497
+    dirname=${tarball_path##*/}
498
+    dirname=${dirname%.tar.gz}
499
+    {
500
+        jat__cmd -h "tarball found" \
501
+            test -n "$tarball_path" \
502
+         || return 3
503
+        jat__cmd -h "tarball extracted" \
504
+            tar -xzf "$tarball_path" \
505
+         || return 3
506
+        jat__cmd -h "directory present" \
507
+            test -d "$dirname" \
508
+         || return 3
509
+    } >&2
510
+    echo "$dirname"
511
+}
512
+
513
+preupg__tar_list() {
514
+    #
515
+    # Print contents of latest tarball
516
+    #
517
+    local tarball_path
518
+    local dirname
519
+    tarball_path=$(preupg__get_latest_tar) || return 3
520
+    {
521
+        jat__cmd -h "tarball found" \
522
+            test -n "$tarball_path" \
523
+         || return 3
524
+        jat__cmd -h "tarball listable" \
525
+            tar -tzf "$tarball_path" \
526
+         || return 3
527
+    } >&2
528
+    tar -tzf "$tarball_path"
529
+}
530
+
531
+__preupg__shellfu_init__() {
532
+    #
533
+    # Inialization check hook (called by shellfu)
534
+    #
535
+    dist__test ver vlt '6.9' && {
536
+        jat__log_warning \
537
+            "=============================================================" \
538
+            " : Old buggy version of OpenSCAP is in use:                :" \
539
+            " :                                                         :" \
540
+            " :     $(rpm -q openscap)                     :" \
541
+            " :                                                         :" \
542
+            " : This means that capabilities of this test library will  :" \
543
+            " : be limited, because stderr from module scripts will be  :" \
544
+            " : always reported as empty, while its content will be     :" \
545
+            " : into stdout.                                            :" \
546
+            " :                                                         :" \
547
+            " : See https://bugzilla.redhat.com/show_bug.cgi?id=1309491 :" \
548
+            "============================================================="
549
+        __PREUPG__LOSCAP=true
550
+    }
551
+    case "$PREUPG__UPATH" in
552
+        el5toel7|el6toel7)  true ;;
553
+        */all-xccdf.xml)    true ;;
554
+        @*)                 true ;;
555
+        *)                  jat__log_error \
556
+                            "unknown upgrade path: $PREUPG__UPATH" ;;
557
+    esac
558
+}
559
+
560
+preupg__haslim() {
561
+    #
562
+    # True and emit warn test reader if limitation $1 is in place
563
+    #
564
+    # Usage:
565
+    #
566
+    #     preupg__haslim LIM [EFFECT]
567
+    #
568
+    # If limitation LIM is in place, print warning and exit with zero
569
+    # otherwise exit with one if LIM is not in place and 2 if LIM is not
570
+    # known.
571
+    #
572
+    # Warning will mention calling function and describe limitation in
573
+    # general; you can provide simple EFFECT (few words) to describe
574
+    # how the limitation affects the particular test context.
575
+    #
576
+    # Known LIMs are:
577
+    #
578
+    #  *  `loscap` - legacy OpenSCAP: module stderr is merged into its
579
+    #     stdout.
580
+    #
581
+    local limitation=$1
582
+    local effect=$2
583
+    local parent=${FUNCNAME[1]}
584
+    case $limitation in
585
+        loscap)     # legacy openscap
586
+            $__PREUPG__LOSCAP || return 1
587
+            test -n "$effect" || effect="see bz1309491"
588
+            jat__log_warning "$parent(): old openscap is in use; $effect"
589
+            return 0
590
+            ;;
591
+    esac
592
+    jat__log_error "invalid limitation: $limitation"
593
+    return 2
594
+}
595
+
596
+
597
+#          #                    there is something wrong with this world #
598
+# INTERNAL # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
599
+#          #            by crossing this line you are making it stronger #
600
+
601
+#
602
+# Have we touched preupg conf already?
603
+#
604
+__PREUPG__CFG_DIRTY=${__PREUPG__CFG_DIRTY:-false}
605
+
606
+
607
+#
608
+# True if we should work with legacy openscap
609
+#
610
+# Old openscap (pre openscap-1.2.13-2.el6) merges stderr into stdout so we need
611
+# to alter risk filtering.
612
+#
613
+__PREUPG__LOSCAP=false
614
+
615
+__preupg__preupg() {
616
+    #
617
+    # Run preupg with --force, maybe --contents and maybe other args
618
+    #
619
+    local args=()
620
+    local hints=()
621
+    local es=0
622
+    local valid_es=$PREUPG__VALID_ES
623
+    args+=(--force)
624
+    case $PREUPG__UPATH in
625
+        */*)
626
+            args+=(--contents "$PREUPG__UPATH")
627
+            hints+=(" (custom content set)")
628
+            ;;
629
+        @*)
630
+            args+=(--contents "$(<"$run1tmp/builtin_path")") \
631
+             || return 3
632
+            hints+=(" (built-in fake content set $PREUPG__UPATH)")
633
+            ;;
634
+    esac
635
+    test -n "$*" \
636
+     && args+=("$@") \
637
+     && hints+=(" ($*)")
638
+    jat__log_info "PWD='$PWD'"      # help to hunt for things like bz1380120
639
+    jat__cmd -h "Run preupgrade assistant${hints[*]}" \
640
+        -S "$valid_es" \
641
+        -o "$run1tmp/out" -e "$run1tmp/err" \
642
+        preupg "${args[@]}"
643
+    es=$?
644
+    case $PREUPG__STRIPCTL in
645
+        false)
646
+            <"$run1tmp/out" jat_dump__pipe -l 400 -b 30000 PREUPG_OUT
647
+            ;;
648
+        true)
649
+            <"$run1tmp/out" tr -dc '[:graph:]\n\t ' \
650
+              | jat_dump__pipe -l 400 -b 30000 PREUPG_OUT_STRIPPED
651
+            ;;
652
+    esac
653
+    < "$run1tmp/err" jat_dump__pipe -E PREUPG_ERR
654
+    return $es
655
+}
656
+
657
+__preupg__mkfupath_builtin() {
658
+    #
659
+    # Ad-hoc path using built-in preupg_fupath() template
660
+    #
661
+    # This whole process is heavily complicated by weird behavior of preupg
662
+    # and its tools':
663
+    #
664
+    #  *  You can't just come up with any name for an upgrade path; this
665
+    #     means the directory name is basically prescribed depending on
666
+    #     source (and destination) distro.
667
+    #
668
+    #  *  The build tool will only generate prescribed path (the above,
669
+    #     suffixed by '-results').
670
+    #
671
+    #  *  The same path *won't* work with preupg; you have to manually rename
672
+    #     it back to the "prescribed"
673
+    #
674
+    # In the end, `preupg_fupath()` has to use at least three
675
+    # different paths and has no way of avoiding path conflict.  Its API
676
+    # partially avoids the problem by making the name a mandatory (=explicit)
677
+    # argument and stating clearly in the docs that these paths would be
678
+    # removed before generation.
679
+    #
680
+    # The point of this function, though, is to be easy on user; this means
681
+    # we'll be implicit wherever we can, at the price of being relatively
682
+    # fragile.
683
+    #
684
+    # Hence the unfunny and frustrating checks below.
685
+    #
686
+    test "${PREUPG__UPATH:0:1}" = @ || return 0
687
+    local name
688
+    {
689
+        dist__test ver.x eq 5 && name=RHEL5_7
690
+        dist__test ver.x eq 6 && name=RHEL6_7
691
+        test -n "$name" || {
692
+            jat__log_error "could not choose fake upath name (this works only on RHEL5/RHEL6)"
693
+            return 3
694
+        }
695
+        test -e "$name" -o -e "$name-results" -o "$name-raw" || {
696
+            jat__log_error "these must not exist for '@BUILTIN' form to work: $name, $name-results $name-raw"
697
+            return 3
698
+        }
699
+        preupg_fupath "$name" "$PREUPG__UPATH"
700
+    } >&2   #FIXME: remove block andredirect after bz1171881
701
+    echo "$name/all-xccdf.xml" > "$run1tmp/builtin_path"
702
+}
703
+
704
+__preupg__mknatlist() {
705
+    #
706
+    # Make list of "native" packages to override and show the path
707
+    #
708
+    local ex        # single expression from PREUPG__DISTNATIVE
709
+    tr , '\n' <<<"$PREUPG__DISTNATIVE" \
710
+      | grep . \
711
+      | while read -r ex;
712
+        do
713
+            case "$ex" in
714
+                -*) echo "${ex:1}" >> "$run1tmp/dno_exclude" ;;
715
+                *)  jat__log_error "invalid expression in PREUPG__DISTNATIVE: $ex"
716
+                    echo /dev/null
717
+                    return 1 ;;
718
+            esac
719
+        done
720
+    rpm -qa --qf '%{N}\n' \
721
+      | sort \
722
+      | uniq \
723
+      | grep -vxFf "$run1tmp/dno_exclude" \
724
+      > "$run1tmp/dno_list"
725
+    echo "$run1tmp/dno_list"
726
+}
727
+
728
+__preupg__dno_enable() {
729
+    #
730
+    # Enable "dist_native" override, if need be
731
+    #
732
+    test -n "$PREUPG__DISTNATIVE" || return 0
733
+    jat__eval -h "enable devel_mode" \
734
+        "mkdir -p /var/cache/preupgrade; touch /var/cache/preupgrade/devel_mode"
735
+    __preupg__cfgbak
736
+    {
737
+        echo "[devel-mode]"
738
+        echo -n "dist_mode="
739
+        case "$PREUPG__DISTNATIVE" in
740
+            all|sign|*/*) echo "$PREUPG__DISTNATIVE" ;;
741
+            *)            __preupg__mknatlist        ;;
742
+        esac
743
+    } >> /etc/preupgrade-assistant.conf
744
+}
745
+
746
+__preupg__dno_disable() {
747
+    #
748
+    # Disable "dist_native" override, if need be
749
+    #
750
+    test -n "$PREUPG__DISTNATIVE" || return 0
751
+    jat__cmd -h "disable devel_mode" \
752
+        rm -f /var/cache/preupgrade/devel_mode
753
+    __preupg__cfgrest
754
+}
755
+
756
+__preupg__cfgbak() {
757
+    #
758
+    # Back up preupg conf
759
+    #
760
+    jat__filebackup -n "preupg__cfgbak" \
761
+      /etc/preupgrade-assistant.conf
762
+}
763
+
764
+__preupg__cfgrest() {
765
+    #
766
+    # Restore preupg conf, if needed
767
+    #
768
+    $__PREUPG__CFG_DIRTY || true
769
+    jat__log_info "config before restoring:"
770
+    jat_dump__file /etc/preupgrade-assistant.conf
771
+    jat__filerestore -n "preupg__cfgbak"
772
+}
773
+
774
+__preupg__assert_mkcode() {
775
+    #
776
+    # Make Bash code for generating field values
777
+    #
778
+    echo -n "PREUPG__RULE=$Rule "
779
+    case $Field in
780
+        risk)           echo "preupg__get_risks"                    ;;
781
+        risk.slight)    echo "preupg__get_risks SLIGHT"             ;;
782
+        risk.medium)    echo "preupg__get_risks MEDIUM"             ;;
783
+        risk.high)      echo "preupg__get_risks HIGH"               ;;
784
+        risk.extreme)   echo "preupg__get_risks EXTREME"            ;;
785
+        riskn)          echo "preupg__get_risks | wc -l"            ;;
786
+        riskn.slight)   echo "preupg__get_risks SLIGHT | wc -l"     ;;
787
+        riskn.medium)   echo "preupg__get_risks MEDIUM | wc -l"     ;;
788
+        riskn.high)     echo "preupg__get_risks HIGH | wc -l"       ;;
789
+        riskn.extreme)  echo "preupg__get_risks EXTREME | wc -l"    ;;
790
+        msg)            echo "preupg__get_messages"                 ;;
791
+        msg.debug)      echo "preupg__get_messages DEBUG"           ;;
792
+        msg.info)       echo "preupg__get_messages INFO"            ;;
793
+        msg.warning)    echo "preupg__get_messages WARNING"         ;;
794
+        msg.error)      echo "preupg__get_messages ERROR"           ;;
795
+        msgn)           echo "preupg__get_messages | wc -l"         ;;
796
+        msgn.debug)     echo "preupg__get_messages DEBUG | wc -l"   ;;
797
+        msgn.info)      echo "preupg__get_messages INFO | wc -l"    ;;
798
+        msgn.warning)   echo "preupg__get_messages WARNING | wc -l" ;;
799
+        msgn.error)     echo "preupg__get_messages ERROR | wc -l"   ;;
800
+        solution)       echo "preupg__get_fixtext"                  ;;
801
+        result)         echo "preupg__get_result"                   ;;
802
+        *)              jat__log_error "unsupported field: $Field"; return 2  ;;
803
+    esac
804
+}
805
+
806
+__preupg__assert_mkvalid_code() {
807
+    #
808
+    # Make Bash code, true if valid
809
+    #
810
+    local code
811
+    code=$(__preupg__assert_mkcode) || return $?
812
+    bash -n <<<"$code" && {
813
+        echo "$code"
814
+        return 0
815
+    }
816
+    jat__log_error "bug: bad assert code generated: '$code'"
817
+    return 3
818
+}
819
+
820
+__preupg__assert_mkhint() {
821
+    #
822
+    # Compose hint for assert
823
+    #
824
+    local fphrase   # English field phrase
825
+    local s         # 's' if $Value is plural, empty otherwise
826
+    local a='a'     # 'a' or 'an', based on what's proper
827
+    test "$Value" = 1 || s="s"
828
+    case $Field in
829
+        result)         fphrase="result"              ;;
830
+        risk|riskn)     fphrase="risk"                ;;
831
+        msg|msgn)       fphrase="message"             ;;
832
+        solution)       fphrase="solution text"       ;;
833
+        risk.*|riskn.*) fphrase="${Field#*.} risk"    ;;
834
+        msg.*|msgn.*)   fphrase="${Field#*.} message" ;;
835
+    esac
836
+    case ${Field#*.} in
837
+        error|extreme|info) a='an'  ;;
838
+    esac
839
+    case $Ellipsis in
840
+        false)  echo -n "rule $Rule has " ;;
841
+        true)   echo -n "   ... " ;;
842
+    esac
843
+    case $Mode:$Type in
844
+        pos:str)    echo "$a $fphrase matching '$Value'"  ;;
845
+        neg:str)    echo "no $fphrase matching '$Value'"  ;;
846
+        pos:int)    echo "exactly $Value $fphrase$s"      ;;
847
+        neg:int)    echo "other than $Value $fphrase$s"   ;;
848
+    esac
849
+}
850
+
851
+__preupg__assert1() {
852
+    #
853
+    # Perform one assertion with condition $1 with rule $Rule
854
+    #
855
+    # This does one iteration of preupg__assert
856
+    #
857
+    local Mode
858
+    local Field
859
+    local Value
860
+    local es=0
861
+    local code
862
+    local hint
863
+    local Type
864
+    local tmp=$1            # tmp='MODE:FIELD:VA:L:UE'
865
+    Mode=${tmp%%:*}         # 'MODE'
866
+    tmp=${tmp#$Mode:}       # tmp='FIELD:VA:L:UE'
867
+    Field=${tmp%%:*}        # 'FIELD'
868
+    Value=${tmp#$Field:}    # 'VA:L:UE'
869
+    Type=$(__preupg__assert_op4fld)       || return $?
870
+    code=$(__preupg__assert_mkvalid_code) || return $?
871
+    hint=$(__preupg__assert_mkhint)
872
+    case $Mode in
873
+        pos)    es=0 ;;
874
+        neg)    es=1 ;;
875
+    esac
876
+    case $Type in
877
+        int)    jat__eval -S $es -h "$hint" "test $(eval "$code") -eq $Value" ;;
878
+        str)    jat__eval -S $es -h "$hint" "$code | grep '$Value'"           ;;
879
+    esac
880
+}
881
+
882
+__preupg__collect_stray_loscap() {
883
+    #
884
+    # Legacy version of preupg__collect_stray()
885
+    #
886
+    local tmp
887
+    local ruleid
888
+    tmp=$(mktemp -td preupg__collect_stray.XXXXXXXX)
889
+    pushd "$tmp" >/dev/null
890
+        __preupg__lsrules_xml \
891
+          | while read -r ruleid;
892
+            do
893
+                __preupg__resultxpath \
894
+                    "//ns0:rule-result[@idref='$ruleid']/ns0:check/ns0:check-import[@import-name='stdout']/text()" \
895
+                    >"stdout"
896
+                test -s "stdout" || continue
897
+                <"stdout" grep -v -E \
898
+                    -e '^preupg\.log\.(ERROR|WARNING|INFO|DEBUG): ' \
899
+                    -e '^preupg\.risk\.(SLIGHT|MEDIUM|HIGH|EXTREME): ' \
900
+                    > "stdout.stray"
901
+                grep -q . "stdout.stray" || continue
902
+                sed -e "s/^/$ruleid:stdout: /" <"stdout.stray"
903
+            done
904
+    popd >/dev/null
905
+    rm -r "$tmp"
906
+}
907
+
908
+__preupg__assert_op4fld() {
909
+    #
910
+    # Print correct operator for field $Field
911
+    #
912
+    case $Field in
913
+        result|risk|risk.*|msg|msg.*|solution)  echo str ;;
914
+        riskn|riskn.*|msgn|msgn.*)              echo int ;;
915
+        *) jat__log_error "unsupported field: $Field"; return 2  ;;
916
+    esac
917
+}
918
+
919
+__preupg__lsrules_upath() {
920
+    #
921
+    # List preupg rule ids from upgrade path
922
+    #
923
+    local upname        # upgrade path name
924
+    case "$PREUPG__UPATH" in
925
+        el6toel7)           upname='RHEL6_7' ;;
926
+        el5toel7)           upname='RHEL5_7' ;;
927
+        @*)                 upname="$(basename "$(dirname "$(<"$run1tmp/builtin_path")")")" ;;
928
+        */all-xccdf.xml)    upname="$(basename "$(dirname "$PREUPG__UPATH")")" ;;
929
+        *) jat__log_error "unsupported upgrade path: $PREUPG__UPATH" ;;
930
+    esac
931
+    #FIXME: after bz1362708, use proper CLI --list-rules for both
932
+    case "$PREUPG__UPATH" in
933
+        @*)
934
+            cat "$(dirname "$(<"$run1tmp/builtin_path")")/list_rules"
935
+            ;;
936
+        */all-xccdf.xml)
937
+            cat "$(dirname "$PREUPG__UPATH")/list_rules"
938
+            ;;
939
+        *)
940
+            preupg --list-rules
941
+            ;;
942
+    esac \
943
+      | grep "$PREUPG__RULE_REGEX" \
944
+      | sed -e "s/^$upname://"
945
+}
946
+
947
+__preupg__lsrules_xml() {
948
+    #
949
+    # List preupg rule ids from result.xml
950
+    #
951
+    __preupg__resultxpath \
952
+        "//ns0:rule-result[./ns0:result/text() != 'notselected']/@idref"
953
+}
954
+
955
+__preupg__resultxpath() {
956
+    #
957
+    # Run XPath query $1 on result.xml inside tarball $2 or latest
958
+    #
959
+    # Take XPath query $1, run it on result.xml and print output.
960
+    #
961
+    # Notes: libxml2-python was, as finally turns out, the only usable
962
+    #        implementation available on RHEL5
963
+    #
964
+    local xpath=$1
965
+    local tarfile=$2
966
+    local inpath        # path inside tarfile
967
+    test -n "$xpath" || {
968
+        jat__log_error "empty XPath query"
969
+        return 2
970
+    }
971
+    test -n "$tarfile" || tarfile=$(preupg__get_latest_tar)
972
+    test -n "$tarfile" || {
973
+        jat__log_error "No tarfile found. Either run preupg or provide tarfile on command line"
974
+        return 2
975
+    }
976
+    inpath=${tarfile##*/}
977
+    inpath=${inpath%.tar.gz}
978
+    tar -zf "$tarfile" -O -x "$inpath/result.xml" \
979
+      | pxpath \
980
+        "$xpath" - \
981
+        "xhtml:http://www.w3.org/1999/xhtml" \
982
+        "html:http://www.w3.org/1999/xhtml" \
983
+        "ns0:http://checklists.nist.gov/xccdf/1.2"
984
+}
985
+
986
+#shellfu module-version=__MKIT_PROJ_VERSION__

+ 445
- 0
src/preupg_fupath.sh.skel View File

@@ -0,0 +1,445 @@
1
+#!/bin/bash
2
+
3
+shellfu import jat
4
+shellfu import pretty
5
+shellfu import jat_dump
6
+
7
+#
8
+# fake upgrade path generator
9
+#
10
+# This beakerlib module helps generate mock upgrade paths for purposes
11
+# of testing preupgrade-assistant.
12
+#
13
+#
14
+# =head1 HELLO WORLD
15
+#
16
+#     {
17
+#         echo '[preupgrade]'
18
+#         echo 'description = hello world module'
19
+#         echo '[MODULE]'
20
+#         echo 'GROUP = foo'
21
+#         echo 'NAME = bar'
22
+#         echo 'LANG = py'
23
+#         echo 'CODE = log_info('hello world')'
24
+#         echo 'CODE = exit_informational()'
25
+#     } > one.mdef
26
+#     preupg_fupath RHEL6_7 one.mdef
27
+#     preupg__upath=RHEL6_7/all-xccdf.xml
28
+#     preupg__run1
29
+#
30
+# would generate:
31
+#
32
+#     RHEL6_7
33
+#     └── foo
34
+#         └── bar
35
+#             ├── module.ini
36
+#             └── check
37
+#
38
+#
39
+# =head1 OVERVIEW
40
+#
41
+# The workflow is following:
42
+#
43
+#  1. Per each upgrade path module, generate a pseudo-INI
44
+#     file, defining properties and content of the module.
45
+#
46
+#  2. Call preupg_fupath() to generate the
47
+#     upgrade path for you, using standard tools under the
48
+#     hood.
49
+#
50
+#  3. Call preupg (or better, preupg__run1()
51
+#     from preupgrade-assistant/main) to use the upgrade path.
52
+#
53
+#
54
+# =head1 FORMAT
55
+#
56
+# A fuller example:
57
+#
58
+#      [preupgrade]
59
+#      content_description = test module bob
60
+#      content_title = test module bob
61
+#
62
+#      [MODULE]
63
+#      GROUP = system
64
+#      NAME = foo
65
+#      LANG = sh
66
+#      CODE = log_medium_risk foo
67
+#      CODE = exit_pass
68
+#
69
+#      [FILES]
70
+#      solution.txt = Some text
71
+#      solution.txt = Some more text
72
+#      myfile.txt = first line of an arbitrary file
73
+#      myfile.txt = second line of of an arbitrary file
74
+#
75
+#  *  Fields from "preupgrade" section are directly copied to
76
+#     used the actual module.ini.
77
+#
78
+#  *  MODULE section should contain GROUP, NAME and a multi-line
79
+#     CODE of the module.  GROUP and NAME define placement of
80
+#     the module in the tree, CODE will be appended to the
81
+#     auto-generated script.
82
+#
83
+#     LANG key is 'sh' for Bash (default) and 'py' for Python.
84
+#
85
+#  *  FILES section can be used to include any number of plain
86
+#     text files (such as a hook scripts or config files) inside
87
+#     the module.   Here key name is name of the file and key
88
+#     content is content of the file.
89
+#
90
+# Virtually any field may be omitted; the generator will try to
91
+# fill in as much as possible (even generate names from random
92
+# chars).
93
+#
94
+# FILES section may be used to fully overwrite any other files
95
+# (even module.ini file!).  This is useful to test "extreme" cases such
96
+# as empty or malformed module.ini file, while retaining feature of
97
+# auto-generation mentioned above.
98
+#
99
+#
100
+# =head2 Indentation
101
+#
102
+# Multi-line values (CODE and values from FILES section) are
103
+# read in a way that preserves indentation by removing as many
104
+# spaces from first column as possible without removing other
105
+# characters.  For example, following sections:
106
+#
107
+#     CODE = def blah():
108
+#     CODE =   pass
109
+#     CODE =
110
+#     CODE = for p in get_dist_native_list():
111
+#     CODE =   blah()
112
+#
113
+#     CODE =     def blah():
114
+#     CODE =       pass
115
+#     CODE =
116
+#     CODE =     for p in get_dist_native_list():
117
+#     CODE =       blah()
118
+#
119
+#     CODE =def blah():
120
+#     CODE =  pass
121
+#     CODE =
122
+#     CODE =for p in get_dist_native_list():
123
+#     CODE =  blah()
124
+#
125
+# would result in exactly the same code:
126
+#
127
+#     def blah():
128
+#       pass
129
+#
130
+#     for p in get_dist_native_list():
131
+#       blah()
132
+#
133
+# This is in order to enable generation of valid Python scripts
134
+# while enabling maximum readability of your test code.
135
+#
136
+
137
+
138
+preupg_fupath() {
139
+    #
140
+    # Create custom test upgrade path from pseudo-INI files
141
+    #
142
+    # Usage:
143
+    #     preupg_fupath UPATH [./FILE]...
144
+    #
145
+    # UPATH must be in form CCCN_N, where C is letter from alphabet,
146
+    # N is a decimal integer number and '_' is literally underscore.
147
+    #
148
+    # Note: folders UPATH, UPATH-raw and UPATH-results in current
149
+    #       folder will be silently deleted!
150
+    #
151
+    #
152
+    # If FILE argument starts with "at sign" (`@`), it will be interpreted
153
+    # as name of a built-in .mdef file included within this library; look
154
+    # into "builtins" subfolder; the alias can be constructed as path
155
+    # to .mdef file relative to that folder, with .mdef suffix stripped.
156
+    #
157
+    # For example,
158
+    #
159
+    #       preupg_fupath RHEL6_7 @pass @failed some/other.mdef
160
+    #
161
+    # will construct upgrade path named RHEL6_7 with three modules based on
162
+    # two built-in files and one custom file.
163
+    #
164
+    # To launch generated upgrade path, specify it to preupg using
165
+    # `-c` parameter pointing to file all-xccdf.xml under folder
166
+    # <UPATH>, for example:
167
+    #
168
+    #     preupg --force -c RHEL6_7/all-xccdf.xml
169
+    #
170
+    # Recommended practice, though, is to set preupg__upath
171
+    # to the path as above and use preupg__run1:
172
+    #
173
+    #     shellfu import preupg
174
+    #     ...
175
+    #     preupg_fupath RHEL6_7 foo.mdef bar.mdef
176
+    #     preupg__upath=RHEL6_7/all-xccdf.xml
177
+    #     preupg__run1
178
+    #
179
+    # which will enable lot of additional checks.
180
+    #
181
+
182
+    local UPName=$1; shift      # upgrade path name
183
+    local MdefFile              # each Mdef file
184
+    local Adding=false          # true: we're adding into existing upath (iteration 2+)
185
+    local b_file=""             # built-in .mdef file
186
+    local MdefFileNick          # Shorter .mdef File reference (usable if built-in)
187
+    local Tmp                   # our temp dir
188
+    Tmp=$(mktemp -dt preupg_fupath.XXXXXXXX)
189
+    jat__cmd rm -rf "$UPName" "$UPName-raw" "$UPName-results"
190
+    for MdefFile in "$@";
191
+    do
192
+        MdefFileNick=$MdefFile
193
+        test "${MdefFile:0:1}" == @ && {
194
+            b_file=$(_preupg_fupath__builtin "$MdefFile") || return 2
195
+        jat__log_info "using built-in .mdef file: $MdefFile=${b_file#$_PREUPG_FUPATH__HOMEDIR/}"
196
+            MdefFile=$b_file
197
+        }
198
+        _preupg_fupath__mdef2module
199
+        Adding=true
200
+    done
201
+    _preupg_fupath__cook_tree "$UPName"
202
+    rm -r "$Tmp"
203
+}
204
+
205
+#          #                 don't jump around too much beyond this line #
206
+# INTERNAL # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
207
+#          #                                        it's not a safe path #
208
+
209
+#
210
+# Library data dir (set during build)
211
+#
212
+_PREUPG_FUPATH__HOMEDIR=__SHELLFU_MODHOME__
213
+
214
+_preupg_fupath__builtin() {
215
+    #
216
+    # Show path of built-in .mdef file (if exists, else fail)
217
+    #
218
+    local b_file=$_PREUPG_FUPATH__HOMEDIR/builtins/${1:1}.mdef
219
+    test -f "$b_file" || {
220
+        jat__log_error "no such built-in: $b_file"
221
+        return 2
222
+    }
223
+    echo "$b_file"
224
+}
225
+
226
+_preupg_fupath__cook_tree() {
227
+    #
228
+    # Create proper compose from raw tree
229
+    #
230
+    local tree=$1
231
+    jat__cmd -h "build upgrade path" \
232
+        preupg-xccdf-compose "$tree"
233
+    jat__eval -h "put upgrade path in place" \
234
+        "mv '$tree' '$tree-raw' && mv '$tree-results' '$tree'"
235
+    find "$tree-raw" "$tree" | jat_dump__pipe -D FOREST
236
+}
237
+
238
+_preupg_fupath__draw_token() {
239
+    #
240
+    # Get a unique token
241
+    #
242
+    head -c 100 /dev/urandom | md5sum | head -c 5
243
+}
244
+
245
+_preupg_fupath__mdef2module() {
246
+    #
247
+    # Process single .mdef
248
+    #
249
+    local m_afile           # additional file
250
+    local m_code_body       # module code body (after auto-header)
251
+    local m_description     # module description
252
+    local m_srcmaj=6        # source OS version         #FIXME: don't hard-code this
253
+    local m_dstmaj=7        # destination OS version    #FIXME: don't hard-code this
254
+    local m_group           # module group name
255
+    local m_name            # module name
256
+    local m_lang            # module language ('sh' for Bash or 'py' for Python)
257
+    local m_title           # module title
258
+    local newmod_path       # new module's subpath (derived from other parts)
259
+
260
+    # Read starting values from $MdefFile or make them up
261
+    #
262
+    jat_dump__file -D "$MdefFile"
263
+    m_group=$(_preupg_fupath__ini 1value "MODULE:GROUP")
264
+    m_name=$(_preupg_fupath__ini 1value "MODULE:NAME")
265
+    m_lang=$(_preupg_fupath__ini 1value "MODULE:LANG")
266
+    m_code_body=$(_preupg_fupath__ini values "MODULE:CODE")
267
+    m_title=$(_preupg_fupath__ini 1value "preupgrade:content_title")
268
+    m_description=$(_preupg_fupath__ini 1value "preupgrade:content_description")
269
+    test -n "$m_group"              || m_group="group_$(_preupg_fupath__draw_token)"
270
+    test -n "$m_name"               || m_name="module_$(_preupg_fupath__draw_token)"
271
+    test -n "$m_lang"               || m_lang="sh"
272
+    test -n "$m_code_body"          || m_code_body="exit_pass"
273
+    test -n "$m_title"              || m_title="Mock module named $m_name"
274
+    test -n "$m_description"        || m_description="This is just a testing module named $m_name"
275
+    debug -v m_group m_name m_lang m_code_body m_title m_description
276
+
277
+    # create new module (most fields will be overwritten)
278
+    #
279
+    {
280
+        echo "$UPName"              # upgrade path name (also relative path)
281
+        $Adding && echo y           # we need to confirm if we want to add into existing
282
+        $Adding || echo "$m_srcmaj"   # source OS version
283
+        $Adding || echo "$m_dstmaj"   # destination OS version
284
+        echo "$m_group"             # module group
285
+        echo "$m_name"              # module name
286
+        echo "$m_lang"              # module language
287
+        echo "$m_title"             # module title
288
+        echo "$m_description"       # module description
289
+    } >"$Tmp/answers"
290
+    jat_dump__file -D "$Tmp/answers"
291
+    jat__eval -h "create module: $m_name in group $m_group from $MdefFileNick" \
292
+        "preupg-content-creator <$Tmp/answers"
293
+    newmod_path="$UPName/$m_group/$m_name"
294
+
295
+    # add arbitrary values from $MdefFile
296
+    #
297
+    local extra_keys
298
+    extra_keys=$(
299
+    for key in $(_preupg_fupath__ini lskeys "preupgrade");
300
+        do
301
+            value=$(_preupg_fupath__ini 1value "preupgrade:$key")
302
+            grep "^$key *=" "$newmod_path/module.ini" && continue
303
+            test -n "$value" && echo "$key = $value"
304
+        done
305
+    )
306
+    debug -v extra_keys
307
+    echo "$extra_keys" >> "$newmod_path/module.ini"
308
+
309
+    # append CODE to module script
310
+    echo "$m_code_body" >> "$newmod_path/check"
311
+
312
+    # dump to keep context clear
313
+    #
314
+    jat_dump__file -D \
315
+        "$newmod_path/module.ini" \
316
+        "$newmod_path/check"
317
+
318
+    # add any arbitrary files stored in FILES section
319
+    #
320
+    for m_afile in $(_preupg_fupath__ini lskeys FILES);
321
+    do
322
+        test -n "$m_code_body" \
323
+         && test "$m_afile" == "check" \
324
+         && jat__log_warning "overwriting CODE by file from FILES section: $m_afile"
325
+        mkdir -p "$(dirname "$newmod_path/$m_afile")"
326
+        _preupg_fupath__ini values "FILES:$m_afile" \
327
+          > "$newmod_path/$m_afile"
328
+    done
329
+
330
+    debug -c find "$UPName"
331
+}
332
+
333
+_preupg_fupath__ini() {
334
+    #
335
+    # do ini operation
336
+    #
337
+    local op=$1
338
+    local arg=$2
339
+    local fn
340
+    local flt=_preupg_fupath__ini_cat
341
+    case $op in
342
+        lskeys) fn=_preupg_fupath__ini_lskeys   ;;
343
+        sec)    fn=_preupg_fupath__ini_grepsec  ;;
344
+        values) fn=_preupg_fupath__ini_greppath
345
+            flt=_preupg_fupath__ini_unind   ;;
346
+        1value) fn=_preupg_fupath__ini_greppath
347
+            flt=_preupg_fupath__ini_strip   ;;
348
+        *)      jat__log_error "incorrect use of \`_preupg_fupath__ini()\`"
349
+    esac
350
+    <"$MdefFile" $fn "$arg" | $flt
351
+}
352
+
353
+_preupg_fupath__ini_strip() {
354
+    #
355
+    # Strip a simple value
356
+    #
357
+    head -1 | sed 's/^ *//; s/ *$//'
358
+}
359
+
360
+_preupg_fupath__ini_unind() {
361
+    #
362
+    # Unindent multi-line value
363
+    #
364
+    local remove=0
365
+    local tmp
366
+    tmp=$(mktemp -dt _preupg_fupath__ini_unind.XXXXXXXX)
367
+    cat >"$tmp/body"
368
+    grep . "$tmp/body" | sed 's/[^ ].*$//' > "$tmp/air"
369
+    remove=$(sort "$tmp/air" | head -1 | wc -c)
370
+    ((remove--))    # newline
371
+    case $remove in
372
+        0)  cat "$tmp/body" ;;
373
+        *)  colrm 1 "$remove" < "$tmp/body" ;;
374
+    esac
375
+    rm -rf "$tmp"
376
+}
377
+
378
+_preupg_fupath__ini_cat() {
379
+    #
380
+    # A no-op for text stream
381
+    #
382
+    while IFS= read -r line;
383
+    do
384
+        printf -- "%s\n" "$line"
385
+    done
386
+}
387
+
388
+_preupg_fupath__ini_grepkey() {
389
+    #
390
+    # Read key from a section
391
+    #
392
+    local wnt=$1
393
+    grep -v '\s*#' \
394
+      | sed -e 's/ *=/=/;' \
395
+      | grep -e "^$wnt=" \
396
+      | cut -d= -f2-
397
+}
398
+
399
+_preupg_fupath__ini_greppath() {
400
+    #
401
+    # Read key from the right section
402
+    #
403
+    # E.g. `files:share:my/lib.sh` should read
404
+    #
405
+    #     [files:share]
406
+    #         my/lib.sh   = proj/my/lib.sh
407
+    #
408
+    local wnt="$1"
409
+    local wntkey="${wnt##*:}"
410
+    local wntsec="${wnt%:$wntkey}"
411
+    _preupg_fupath__ini_grepsec "$wntsec" \
412
+        | _preupg_fupath__ini_grepkey "$wntkey"
413
+}
414
+
415
+_preupg_fupath__ini_grepsec() {
416
+    #
417
+    # Read one INI section
418
+    #
419
+    local wnt="$1"
420
+    local ok=false
421
+    grep -v '\s*#' \
422
+      | while IFS= read -r line;
423
+        do
424
+            case "$line" in
425
+                \[$wnt\]) ok=true;  continue ;;
426
+                \[*\])    ok=false; continue ;;
427
+            esac
428
+            $ok || continue
429
+            printf -- "%s\n" "$line"
430
+        done \
431
+      | sed -e 's/ *=/=/;'
432
+}
433
+
434
+_preupg_fupath__ini_lskeys() {
435
+    #
436
+    # List keys from a section
437
+    #
438
+    local sct="$1"
439
+    _preupg_fupath__ini_grepsec "$sct" \
440
+      | cut -d= -f1 \
441
+      | sort \
442
+      | uniq
443
+}
444
+
445
+#shellfu module-version=__MKIT_PROJ_VERSION__

+ 194
- 0
src/preupg_upath.sh.skel View File

@@ -0,0 +1,194 @@
1
+#!/bin/bash
2
+
3
+shellfu import jat
4
+shellfu import pretty
5
+
6
+#
7
+# upgrade path utilities
8
+#
9
+
10
+preupg_upath__find() {
11
+    #
12
+    # Find module according to criteria
13
+    #
14
+    # Look into installed upgrade path modules and print all ids or ids
15
+    # selected by a condition.
16
+    #
17
+    #     preupg_upath__find [-FIELD RE].. [-print FIELD[:FIELD]..]
18
+    #
19
+    # Where FIELD is one of supported fields and RE is basic regular expression
20
+    # to be matched against that field.  List of all modules found on the
21
+    # system is collected; then each module is checked against all conditions.
22
+    # If it matches all conditions, its short id is printed, unless `-print`
23
+    # is provided, in which case the argument that follows is interpreted as
24
+    # colon-separated list of fields that should be printed.  Multiple fields
25
+    # on output are separated by colon.
26
+    #
27
+    # List of supported conditions:
28
+    #
29
+    #  *  `id` - short id,
30
+    #  *  `xid` - long "xccdf_preupg_rule_" id,
31
+    #  *  `relpath` - relative path from upgrade path root
32
+    #  *  `path` - absolute path
33
+    #  *  `name` - only the name part (directory name)
34
+    #  *  `group` - "group" part of the id,
35
+    #  *  `upath` - upgrade path names.
36
+    #
37
+    local Conds=()
38
+    local cond_name
39
+    local cond_arg
40
+    local dir
41
+    local usage="usage: preupg_upath__find [-FIELD RE].."
42
+    while true; do case $1 in
43
+        -*)
44
+            cond_name=${1:1}
45
+            cond_arg=$2
46
+            shift 2 || {
47
+                jat__log_error "$usage"
48
+                return 2
49
+            }
50
+            Conds+=("$cond_name:$cond_arg")
51
+            ;;
52
+        "")
53
+            break
54
+            ;;
55
+        *)
56
+            shift 2 || {
57
+                jat__log_error "$usage"
58
+                return 2
59
+            }
60
+    esac done
61
+    __preupg_upath__find_dirs \
62
+      | while read -r dir;
63
+        do
64
+            __preupg_upath__find_ckconds "$dir"
65
+        done
66
+}
67
+
68
+
69
+#          #                                     your brain upgrade path #
70
+# INTERNAL # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
71
+#          #                                    does not cross this line #
72
+
73
+__preupg_upath__find_dirs() {
74
+    #
75
+    # List all paths to module directories
76
+    #
77
+    local path
78
+    rpm -qal "preupgrade-assistant-el6toel*" \
79
+      | grep -v '/usr/share/preupgrade/[[:alnum:]]\+/common' \
80
+      | while read -r path;
81
+        do
82
+            test -d "$path"             || continue
83
+            test -f "$path/group.xml"   || continue
84
+            test -f "$path/check"       || continue
85
+            echo "$path"
86
+        done
87
+}
88
+
89
+__preupg_upath__find_ckconds() {
90
+    #
91
+    # Check all condition pairs
92
+    #
93
+    local mpath=$1
94
+    local cond
95
+    local cond_name
96
+    local cond_arg
97
+    local ok=true
98
+    local fields=upath:id
99
+    local field
100
+    for cond in "${Conds[@]}";
101
+    do
102
+        cond_name=${cond%%:*}
103
+        cond_arg=${cond#*:}
104
+        case $cond_name in
105
+            id|xid|group|name|path|relpath|upath)
106
+                __preupg_upath__find_getfield "$cond_name" "$mpath" \
107
+                  | grep -q "$cond_arg" \
108
+                 || ok=false
109
+                ;;
110
+            print)
111
+                fields=$cond_arg
112
+                ;;
113
+            *)
114
+                jat__log_error "unknown condition: $cond"
115
+                return 2
116
+                ;;
117
+        esac
118
+    done
119
+    $ok || return 1
120
+    __preupg_upath__find_fmt "$fields" "$mpath"
121
+}
122
+
123
+__preupg_upath__find_fmt() {
124
+    #
125
+    # Format meta data of module $2 according to field list $1
126
+    #
127
+    local fields=$1
128
+    local mpath=$2
129
+    local field
130
+    for field in ${fields//:/ };
131
+    do
132
+        __preupg_upath__find_getfield "$field" "$mpath"
133
+    done \
134
+      | paste -sd:
135
+}
136
+
137
+__preupg_upath__find_getfield() {
138
+    #
139
+    # Get field $1 from module at path $1
140
+    #
141
+    local field=$1
142
+    local mpath=$2
143
+    local getfield=__preupg_upath__find_getfield
144
+    case $field in
145
+        id)
146
+            $getfield relpath "$mpath" \
147
+              | sed 's:/:_:g'
148
+            ;;
149
+        xid)
150
+            echo -n "xccdf_preupg_rule_"
151
+            echo -n "$($getfield id "$mpath")"
152
+            echo -n "_check"
153
+            ;;
154
+        name)
155
+            echo "${mpath##*/}"
156
+            ;;
157
+        group)
158
+            $getfield relpath "$mpath" \
159
+              | sed 's:/[^/]*$::; s:/:_:g'
160
+            ;;
161
+        upath)
162
+            cut -d/ -f5 <<<"${mpath}" \
163
+              | __preupg_upath__find_upath_old2new
164
+            ;;
165
+        relpath)
166
+            cut -d/ -f6- <<<"${mpath}"
167
+            ;;
168
+        path)
169
+            echo "$mpath"
170
+            ;;
171
+        *)
172
+            jat__log_error "unknown field: $field"
173
+            return 2
174
+            ;;
175
+    esac
176
+}
177
+
178
+__preupg_upath__find_upath_old2new() {
179
+    #
180
+    # Convert from old style upgrade path name to new
181
+    #
182
+    # Usage: echo el6toel7 | __preupg_upath__find_upath_old2new
183
+    #
184
+    local oupath
185
+    while read -r oupath;
186
+    do
187
+        case $oupath in
188
+            RHEL?_?) echo "el${oupath:4:1}toel${oupath:6}" ;;
189
+            *) jat__log_error "unknown old-style upgrade path name: $oupath" ;;
190
+        esac
191
+    done
192
+}
193
+
194
+#shellfu module-version=__MKIT_PROJ_VERSION__

+ 290
- 0
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
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() {