source: BLFS/xsl/scripts.xsl@ 96d7e44

ablfs-more legacy trunk
Last change on this file since 96d7e44 was 96d7e44, checked in by Pierre Labastie <pierre@…>, 5 years ago

BLFS/xsl: move the template for replaceable tags out of the main stylesheet,
and allow replacing some hostname/domainname replaceable tags

  • Property mode set to 100644
File size: 34.7 KB
Line 
1<?xml version="1.0"?>
2
3<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 xmlns:exsl="http://exslt.org/common"
5 extension-element-prefixes="exsl"
6 version="1.0">
7
8<!-- $Id$ -->
9
10<!-- XSLT stylesheet to create shell scripts from "linear build" BLFS books. -->
11
12<!-- parameters and global variables -->
13 <!-- Check whether the book is sysv or systemd -->
14 <xsl:variable name="rev">
15 <xsl:choose>
16 <xsl:when test="//bookinfo/title/phrase[@revision='systemd']">
17 systemd
18 </xsl:when>
19 <xsl:otherwise>
20 sysv
21 </xsl:otherwise>
22 </xsl:choose>
23 </xsl:variable>
24
25 <!-- Wrap "root" commands inside a wrapper function, allowing
26 "porg style" package management -->
27 <xsl:param name="wrap-install" select="'n'"/>
28
29 <!-- list of packages needing stats -->
30 <xsl:param name="list-stat" select="''"/>
31
32 <!-- Remove libtool .la files -->
33 <xsl:param name="del-la-files" select="'y'"/>
34
35 <!-- Build as user (y) or as root (n)? -->
36 <xsl:param name="sudo" select="'y'"/>
37
38<!-- simple instructions for removing .la files. -->
39<!-- We'll use the rule that any text output begins with a linefeed if needed
40 so that we do not need to output one at the end-->
41 <xsl:variable name="la-files-instr">
42
43for libdir in /lib /usr/lib $(find /opt -name lib); do
44 find $libdir -name \*.la \
45 ! -path \*ImageMagick\* \
46 -delete
47done</xsl:variable>
48
49 <xsl:variable name="list-stat-norm"
50 select="concat(' ', normalize-space($list-stat),' ')"/>
51
52<!-- To be able to use the single quote in tests -->
53 <xsl:variable name="APOS">'</xsl:variable>
54
55<!-- end parameters and global variables -->
56
57<!-- include the template for processing screen children of
58 role="install" sect2 -->
59 <xsl:include href="process-install.xsl"/>
60
61<!-- include the template for replaceable tags -->
62 <xsl:include href="process-replaceable.xsl"/>
63
64<!--=================== Begin processing ========================-->
65
66 <xsl:template match="/">
67 <xsl:apply-templates select="//sect1[@id != 'bootscripts' and
68 @id != 'systemd-units']"/>
69 </xsl:template>
70
71<!--=================== Master chunks code ======================-->
72
73 <xsl:template match="sect1">
74
75 <!-- Are stat requested for this page? -->
76 <xsl:variable name="want-stats"
77 select="contains($list-stat-norm,
78 concat(' ',@id,' '))"/>
79
80 <!-- The file names -->
81 <xsl:variable name="filename" select="@id"/>
82
83 <!-- The build order -->
84 <xsl:variable name="position" select="position()"/>
85 <xsl:variable name="order">
86 <xsl:choose>
87 <xsl:when test="string-length($position) = 1">
88 <xsl:text>00</xsl:text>
89 <xsl:value-of select="$position"/>
90 </xsl:when>
91 <xsl:when test="string-length($position) = 2">
92 <xsl:text>0</xsl:text>
93 <xsl:value-of select="$position"/>
94 </xsl:when>
95 <xsl:otherwise>
96 <xsl:value-of select="$position"/>
97 </xsl:otherwise>
98 </xsl:choose>
99 </xsl:variable>
100
101 <!-- Depuration code -->
102 <xsl:message>
103 <xsl:text>SCRIPT is </xsl:text>
104 <xsl:value-of select="concat($order,'-z-',$filename)"/>
105 <xsl:text>&#xA; FTPDIR is </xsl:text>
106 <xsl:value-of select="$filename"/>
107 <xsl:text>&#xA;&#xA;</xsl:text>
108 </xsl:message>
109
110 <!-- Creating the scripts -->
111 <exsl:document href="{$order}-z-{$filename}" method="text">
112 <xsl:text>#!/bin/bash
113set -e
114unset MAKELEVEL
115</xsl:text>
116<!-- Unsetting MAKELEVEL is needed for some packages which assume that
117 their top level Makefile is at level zero -->
118 <xsl:choose>
119 <!-- Package page -->
120 <xsl:when test="sect2[@role='package']">
121 <!-- We build in a subdirectory, whose name may be needed
122 if using package management (see envars.conf), so
123 "export" it -->
124 <xsl:text>
125export JH_PKG_DIR=</xsl:text>
126 <xsl:value-of select="$filename"/>
127 <xsl:text>
128SRC_DIR=${JH_SRC_ARCHIVE}${JH_SRC_SUBDIRS:+/${JH_PKG_DIR}}
129BUILD_DIR=${JH_BUILD_ROOT}${JH_BUILD_SUBDIRS:+/${JH_PKG_DIR}}
130mkdir -p $SRC_DIR
131mkdir -p $BUILD_DIR
132</xsl:text>
133
134<!-- If stats are requested, include some definitions and intitializations -->
135 <xsl:if test="$want-stats">
136 <xsl:text>
137INFOLOG=$(pwd)/info-${JH_PKG_DIR}
138TESTLOG=$(pwd)/test-${JH_PKG_DIR}
139unset MAKEFLAGS
140#MAKEFLAGS=-j4
141echo MAKEFLAGS: $MAKEFLAGS > $INFOLOG
142: > $TESTLOG
143PKG_DEST=${BUILD_DIR}/dest
144rm -rf $PKG_DEST
145</xsl:text>
146 </xsl:if>
147 <!-- Download code and build commands -->
148 <xsl:apply-templates select="sect2">
149 <xsl:with-param name="want-stats" select="$want-stats"/>
150 </xsl:apply-templates>
151 <!-- Clean-up -->
152 <xsl:text>
153
154cd $BUILD_DIR
155[[ -n "$JH_KEEP_FILES" ]] || </xsl:text>
156 <!-- In some case, some files in the build tree are owned
157 by root -->
158 <xsl:if test="$sudo='y'">
159 <xsl:text>sudo </xsl:text>
160 </xsl:if>
161 <xsl:text>rm -rf $JH_UNPACKDIR unpacked
162</xsl:text>
163 </xsl:when>
164 <!-- Non-package page -->
165 <xsl:otherwise>
166 <xsl:apply-templates select=".//screen" mode="not-pack"/>
167 </xsl:otherwise>
168 </xsl:choose>
169 <xsl:text>
170exit
171</xsl:text><!-- include a \n at the end of document-->
172 </exsl:document>
173 </xsl:template>
174
175<!--======================= Sub-sections code =======================-->
176
177 <xsl:template match="sect2">
178 <xsl:param name="want-stats" select="false"/>
179 <xsl:choose>
180
181 <xsl:when test="@role = 'package'">
182 <xsl:text>
183cd $SRC_DIR</xsl:text>
184 <!-- Download information is in bridgehead tags -->
185 <xsl:apply-templates select="bridgehead[@renderas='sect3']"/>
186 </xsl:when><!-- @role="package" -->
187
188 <xsl:when test="@role = 'qt4-prefix' or @role = 'qt5-prefix'">
189 <xsl:apply-templates select=".//screen[./userinput]"/>
190 </xsl:when>
191
192 <xsl:when test="@role = 'installation'">
193 <xsl:text>
194cd $BUILD_DIR
195find . -maxdepth 1 -mindepth 1 -type d | xargs </xsl:text>
196 <xsl:if test="$sudo='y'">
197 <xsl:text>sudo </xsl:text>
198 </xsl:if>
199 <xsl:text>rm -rf
200</xsl:text>
201 <!-- If stats are requested, insert the start size -->
202 <xsl:if test="$want-stats">
203 <xsl:text>
204echo Start Size: $(sudo du -skx --exclude home /) >> $INFOLOG
205</xsl:text>
206 </xsl:if>
207
208 <xsl:text>
209case $PACKAGE in
210 *.tar.gz|*.tar.bz2|*.tar.xz|*.tgz|*.tar.lzma)
211 tar -xvf $SRC_DIR/$PACKAGE &gt; unpacked
212 JH_UNPACKDIR=`grep '[^./]\+' unpacked | head -n1 | sed 's@^\./@@;s@/.*@@'`
213 ;;
214 *.tar.lz)
215 bsdtar -xvf $SRC_DIR/$PACKAGE 2&gt; unpacked
216 JH_UNPACKDIR=`head -n1 unpacked | cut -d" " -f2 | sed 's@^\./@@;s@/.*@@'`
217 ;;
218 *.zip)
219 zipinfo -1 $SRC_DIR/$PACKAGE &gt; unpacked
220 JH_UNPACKDIR="$(sed 's@/.*@@' unpacked | uniq )"
221 if test $(wc -w &lt;&lt;&lt; $JH_UNPACKDIR) -eq 1; then
222 unzip $SRC_DIR/$PACKAGE
223 else
224 JH_UNPACKDIR=${PACKAGE%.zip}
225 unzip -d $JH_UNPACKDIR $SRC_DIR/$PACKAGE
226 fi
227 ;;
228 *)
229 JH_UNPACKDIR=$JH_PKG_DIR-build
230 mkdir $JH_UNPACKDIR
231 cp $SRC_DIR/$PACKAGE $JH_UNPACKDIR
232 ADDITIONAL="$(find . -mindepth 1 -maxdepth 1 -type l)"
233 if [ -n "$ADDITIONAL" ]; then
234 cp $ADDITIONAL $JH_UNPACKDIR
235 fi
236 ;;
237esac
238export JH_UNPACKDIR
239cd $JH_UNPACKDIR
240</xsl:text>
241 <!-- If stats are requested, insert the start time -->
242 <xsl:if test="$want-stats">
243 <xsl:text>
244echo Start Time: ${SECONDS} >> $INFOLOG
245</xsl:text>
246 </xsl:if>
247
248 <xsl:call-template name="process-install">
249 <xsl:with-param
250 name="instruction-tree"
251 select=".//screen[not(@role = 'nodump') and ./userinput] |
252 .//para/command[contains(text(),'check') or
253 contains(text(),'test')]"/>
254 <xsl:with-param name="want-stats" select="$want-stats"/>
255 <xsl:with-param name="root-seen" select="boolean(0)"/>
256 <xsl:with-param name="install-seen" select="boolean(0)"/>
257 <xsl:with-param name="test-seen" select="boolean(0)"/>
258 <xsl:with-param name="doc-seen" select="boolean(0)"/>
259 </xsl:call-template>
260 <xsl:text>
261</xsl:text>
262 <xsl:if test="$sudo = 'y'">
263 <xsl:text>sudo /sbin/</xsl:text>
264 </xsl:if>
265 <xsl:text>ldconfig</xsl:text>
266 </xsl:when><!-- @role="installation" -->
267
268 <xsl:when test="@role = 'configuration'">
269 <xsl:text>&#xA;</xsl:text>
270 <xsl:apply-templates mode="config"
271 select=".//screen[not(@role = 'nodump') and ./userinput]"/>
272 </xsl:when><!-- @role="configuration" -->
273
274 </xsl:choose>
275 </xsl:template>
276
277<!--==================== Download code =======================-->
278
279 <!-- template for extracting the filename from an url in the form:
280 proto://internet.name/dir1/.../dirn/filename?condition.
281 Needed, because substring-after(...,'/') returns only the
282 substring after the first '/'. -->
283 <xsl:template name="package_name">
284 <xsl:param name="url" select="foo"/>
285 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
286 <xsl:choose>
287 <xsl:when test="contains($sub-url,'/')">
288 <xsl:call-template name="package_name">
289 <xsl:with-param name="url" select="$sub-url"/>
290 </xsl:call-template>
291 </xsl:when>
292 <xsl:otherwise>
293 <xsl:choose>
294 <xsl:when test="contains($sub-url,'?')">
295 <xsl:value-of select="substring-before($sub-url,'?')"/>
296 </xsl:when>
297 <xsl:otherwise>
298 <xsl:value-of select="$sub-url"/>
299 </xsl:otherwise>
300 </xsl:choose>
301 </xsl:otherwise>
302 </xsl:choose>
303 </xsl:template>
304
305 <!-- Generates the code to download a package, an additional package or
306 a patch. -->
307 <xsl:template name="download-file">
308 <xsl:param name="httpurl" select="''"/>
309 <xsl:param name="ftpurl" select="''"/>
310 <xsl:param name="md5" select="''"/>
311 <xsl:param name="varname" select="''"/>
312 <xsl:variable name="package">
313 <xsl:call-template name="package_name">
314 <xsl:with-param name="url">
315 <xsl:choose>
316 <xsl:when test="string-length($httpurl) &gt; 10">
317 <xsl:value-of select="$httpurl"/>
318 </xsl:when>
319 <xsl:otherwise>
320 <xsl:value-of select="$ftpurl"/>
321 </xsl:otherwise>
322 </xsl:choose>
323 </xsl:with-param>
324 </xsl:call-template>
325 </xsl:variable>
326 <xsl:variable name="first_letter"
327 select="translate(substring($package,1,1),
328 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
329 'abcdefghijklmnopqrstuvwxyz')"/>
330 <xsl:text>&#xA;</xsl:text>
331 <xsl:value-of select="$varname"/>
332 <xsl:text>=</xsl:text>
333 <xsl:value-of select="$package"/>
334 <xsl:text>&#xA;if [[ ! -f $</xsl:text>
335 <xsl:value-of select="$varname"/>
336 <xsl:text> ]] ; then
337 if [[ -f $JH_SRC_ARCHIVE/$</xsl:text>
338 <xsl:value-of select="$varname"/>
339 <xsl:text> ]] ; then&#xA;</xsl:text>
340 <xsl:text> cp $JH_SRC_ARCHIVE/$</xsl:text>
341 <xsl:value-of select="$varname"/>
342 <xsl:text> $</xsl:text>
343 <xsl:value-of select="$varname"/>
344 <xsl:text>
345 else&#xA;</xsl:text>
346 <!-- Download from upstream http -->
347 <xsl:if test="string-length($httpurl) &gt; 10">
348 <xsl:text> wget -T 30 -t 5 </xsl:text>
349 <xsl:value-of select="$httpurl"/>
350 <xsl:text> ||&#xA;</xsl:text>
351 </xsl:if>
352 <!-- Download from upstream ftp -->
353 <xsl:if test="string-length($ftpurl) &gt; 10">
354 <xsl:text> wget -T 30 -t 5 </xsl:text>
355 <xsl:value-of select="$ftpurl"/>
356 <xsl:text> ||&#xA;</xsl:text>
357 </xsl:if>
358 <!-- The FTP_SERVER mirror as a last resort -->
359 <xsl:text> wget -T 30 -t 5 ${JH_FTP_SERVER}svn/</xsl:text>
360 <xsl:value-of select="$first_letter"/>
361 <xsl:text>/$</xsl:text>
362 <xsl:value-of select="$varname"/>
363 <xsl:text>
364 fi
365fi</xsl:text>
366 <xsl:if test="string-length($md5) &gt; 10">
367 <xsl:text>
368echo "</xsl:text>
369 <xsl:value-of select="$md5"/>
370 <xsl:text>&#x20;&#x20;$</xsl:text>
371 <xsl:value-of select="$varname"/>
372 <xsl:text>" | md5sum -c -</xsl:text>
373 </xsl:if>
374<!-- link additional packages into $BUILD_DIR, because they are supposed to
375 be there-->
376 <xsl:if test="string($varname) != 'PACKAGE'">
377 <xsl:text>
378[[ "$SRC_DIR" != "$BUILD_DIR" ]] &amp;&amp; ln -sf $SRC_DIR/$</xsl:text>
379 <xsl:value-of select="$varname"/>
380 <xsl:text> $BUILD_DIR</xsl:text>
381 </xsl:if>
382 <xsl:text>&#xA;</xsl:text>
383 </xsl:template>
384
385 <!-- Extract the MD5 sum information -->
386 <xsl:template match="para" mode="md5">
387 <xsl:choose>
388 <xsl:when test="contains(substring-after(string(),'sum: '),'&#xA;')">
389 <xsl:value-of select="substring-before(substring-after(string(),'sum: '),'&#xA;')"/>
390 </xsl:when>
391 <xsl:otherwise>
392 <xsl:value-of select="substring-after(string(),'sum: ')"/>
393 </xsl:otherwise>
394 </xsl:choose>
395 </xsl:template>
396
397 <!-- We have several templates itemizedlist, depending on whether we
398 expect the package information, or additional package(s) or patch(es)
399 information. Select the appropriate mode here. -->
400 <xsl:template match="bridgehead">
401 <xsl:choose>
402 <!-- Special case for Openjdk -->
403 <xsl:when test="contains(string(),'Source Package Information')">
404 <xsl:apply-templates
405 select="following-sibling::itemizedlist[1]//simplelist">
406 <xsl:with-param name="varname" select="'PACKAGE'"/>
407 </xsl:apply-templates>
408 <xsl:apply-templates select="following-sibling::itemizedlist
409 [preceding-sibling::bridgehead[1]=current()
410 and position() &gt;1]//simplelist">
411 <xsl:with-param name="varname" select="'PACKAGE1'"/>
412 </xsl:apply-templates>
413 </xsl:when>
414 <!-- Package information -->
415 <xsl:when test="contains(string(),'Package Information')">
416 <xsl:apply-templates select="following-sibling::itemizedlist
417 [preceding-sibling::bridgehead[1]=current()]"
418 mode="package"/>
419 </xsl:when>
420 <!-- Additional package information -->
421 <!-- special case for llvm -->
422 <xsl:when test="contains(string(),'Optional Download')">
423 <xsl:apply-templates select="following-sibling::itemizedlist"
424 mode="additional"/>
425 </xsl:when>
426 <!-- All other additional packages have "Additional" -->
427 <xsl:when test="contains(string(),'Additional')">
428 <xsl:apply-templates select="following-sibling::itemizedlist"
429 mode="additional"/>
430 </xsl:when>
431 <!-- Do not do anything if the dev has created another type of
432 bridgehead. -->
433 <xsl:otherwise/>
434 </xsl:choose>
435 </xsl:template>
436
437 <!-- Call the download code template with appropriate parameters -->
438 <xsl:template match="itemizedlist" mode="package">
439 <xsl:call-template name="download-file">
440 <xsl:with-param name="httpurl">
441 <xsl:value-of select="./listitem[1]/para/ulink/@url"/>
442 </xsl:with-param>
443 <xsl:with-param name="ftpurl">
444 <xsl:value-of select="./listitem/para[contains(string(),'FTP')]/ulink/@url"/>
445 </xsl:with-param>
446 <xsl:with-param name="md5">
447 <xsl:apply-templates select="./listitem/para[contains(string(),'MD5')]"
448 mode="md5"/>
449 </xsl:with-param>
450 <xsl:with-param name="varname" select="'PACKAGE'"/>
451 </xsl:call-template>
452 </xsl:template>
453
454 <xsl:template match="itemizedlist" mode="additional">
455 <!-- The normal layout is "one listitem"<->"one url", but some devs
456 find amusing to have FTP and/or MD5sum listitems, or to
457 enclose the download information inside a simplelist tag... -->
458 <xsl:for-each select="listitem[.//ulink]">
459 <xsl:choose>
460 <!-- hopefully, there was a HTTP line before -->
461 <xsl:when test="contains(string(./para),'FTP')"/>
462 <xsl:when test=".//simplelist">
463 <xsl:apply-templates select=".//simplelist">
464 <xsl:with-param name="varname" select="'PACKAGE1'"/>
465 </xsl:apply-templates>
466 </xsl:when>
467 <xsl:otherwise>
468 <xsl:call-template name="download-file">
469 <xsl:with-param name="httpurl">
470 <xsl:value-of select="./para/ulink/@url"/>
471 </xsl:with-param>
472 <xsl:with-param name="ftpurl">
473 <xsl:value-of
474 select="following-sibling::listitem[1]/
475 para[contains(string(),'FTP')]/ulink/@url"/>
476 </xsl:with-param>
477 <xsl:with-param name="md5">
478 <xsl:apply-templates
479 select="following-sibling::listitem[position()&lt;3]/
480 para[contains(string(),'MD5')]"
481 mode="md5"/>
482 </xsl:with-param>
483 <xsl:with-param name="varname">
484 <xsl:choose>
485 <xsl:when test="contains(./para/ulink/@url,'.patch')">
486 <xsl:text>PATCH</xsl:text>
487 </xsl:when>
488 <xsl:otherwise>
489 <xsl:text>PACKAGE1</xsl:text>
490 </xsl:otherwise>
491 </xsl:choose>
492 </xsl:with-param>
493 </xsl:call-template>
494 </xsl:otherwise>
495 </xsl:choose>
496 </xsl:for-each>
497 </xsl:template>
498
499 <!-- the simplelist case. Hopefully, the layout is one member for
500 url, one for md5 and others for various information, that we do not
501 use -->
502 <xsl:template match="simplelist">
503 <xsl:param name="varname" select="'PACKAGE1'"/>
504 <xsl:call-template name="download-file">
505 <xsl:with-param name="httpurl" select=".//ulink/@url"/>
506 <xsl:with-param name="md5">
507 <xsl:value-of select="substring-after(member[contains(string(),'MD5')],'sum: ')"/>
508 </xsl:with-param>
509 <xsl:with-param name="varname" select="$varname"/>
510 </xsl:call-template>
511 </xsl:template>
512
513<!--====================== Non package code =========================-->
514
515 <xsl:template match="screen" mode="not-pack">
516 <xsl:choose>
517 <xsl:when test="@role='nodump'"/>
518 <xsl:when test="ancestor::sect1[@id='postlfs-config-vimrc']">
519 <xsl:text>
520cat > ~/.vimrc &lt;&lt;EOF
521</xsl:text>
522 <xsl:apply-templates/>
523 <xsl:text>
524EOF
525</xsl:text>
526 </xsl:when>
527 <xsl:otherwise>
528 <xsl:apply-templates select="." mode="config"/>
529 </xsl:otherwise>
530 </xsl:choose>
531 </xsl:template>
532<!--======================== Commands code ==========================-->
533<!-- Code for installation instructions is in gen-install.xsl -->
534
535 <xsl:template match="screen">
536 <xsl:choose>
537<!-- instructions run as root (configuration mainly) -->
538 <xsl:when test="@role = 'root'">
539<!-- templates begin/end-root are in gen-install.xsl -->
540 <xsl:if test="not(preceding-sibling::screen[1][@role='root'])">
541 <xsl:call-template name="begin-root"/>
542 </xsl:if>
543 <xsl:apply-templates mode="root"/>
544 <xsl:if test="not(following-sibling::screen[1][@role='root'])">
545 <xsl:call-template name="end-root"/>
546 </xsl:if>
547 </xsl:when>
548<!-- then all the instructions run as user -->
549 <xsl:otherwise>
550 <xsl:apply-templates select="userinput"/>
551 </xsl:otherwise>
552 </xsl:choose>
553 </xsl:template>
554
555<!-- Templates for bootscripts/units installation -->
556 <xsl:template name="set-bootpkg-dir">
557 <xsl:param name="bootpkg" select="'bootscripts'"/>
558 <xsl:param name="url" select="''"/>
559 <xsl:text>
560BOOTPKG_DIR=blfs-</xsl:text>
561 <xsl:copy-of select="$bootpkg"/>
562 <xsl:text>
563
564BOOTSRC_DIR=${JH_SRC_ARCHIVE}${JH_SRC_SUBDIRS:+/${BOOTPKG_DIR}}
565BOOTBUILD_DIR=${JH_BUILD_ROOT}${JH_BUILD_SUBDIRS:+/${BOOTPKG_DIR}}
566mkdir -p $BOOTSRC_DIR
567mkdir -p $BOOTBUILD_DIR
568
569pushd $BOOTSRC_DIR
570URL=</xsl:text>
571 <xsl:value-of select="$url"/>
572 <xsl:text>
573BOOTPACKG=$(basename $URL)
574if [[ ! -f $BOOTPACKG ]] ; then
575 if [[ -f $JH_SRC_ARCHIVE/$BOOTPACKG ]] ; then
576 cp $JH_SRC_ARCHIVE/$BOOTPACKG $BOOTPACKG
577 else
578 wget -T 30 -t 5 $URL
579 fi
580 rm -f $BOOTBUILD_DIR/unpacked
581fi
582
583cd $BOOTBUILD_DIR
584if [[ -e unpacked ]] ; then
585 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
586 if ! [[ -d $BOOTUNPACKDIR ]]; then
587 tar -xvf $BOOTSRC_DIR/$BOOTPACKG > unpacked
588 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
589 fi
590else
591 tar -xvf $BOOTSRC_DIR/$BOOTPACKG > unpacked
592 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
593fi
594cd $BOOTUNPACKDIR</xsl:text>
595 </xsl:template>
596
597 <xsl:template match="screen" mode="config">
598 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
599<!-- if the preceding "screen" tag is role="root", and we are role="root"
600 the end-root has not been called. So do it -->
601 <xsl:if
602 test="preceding-sibling::screen[1][@role='root'] and @role='root'">
603 <xsl:call-template name="end-root"/>
604 </xsl:if>
605 <xsl:call-template name="set-bootpkg-dir">
606 <xsl:with-param name="bootpkg" select="'bootscripts'"/>
607 <xsl:with-param name="url"
608 select="id('bootscripts')//itemizedlist//ulink/@url"/>
609 </xsl:call-template>
610<!-- if the preceding "screen" tag is role="root", and we are role="root"
611 the begin-root will not be called. So do it -->
612 <xsl:if
613 test="preceding-sibling::screen[1][@role='root'] and @role='root'">
614 <xsl:call-template name="begin-root"/>
615 </xsl:if>
616 </xsl:if>
617 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='systemd-units']">
618<!-- if the preceding "screen" tag is role="root", and we are role="root"
619 the end-root has not been called. So do it -->
620 <xsl:if
621 test="preceding-sibling::screen[1][@role='root'] and @role='root'">
622 <xsl:call-template name="end-root"/>
623 </xsl:if>
624 <xsl:call-template name="set-bootpkg-dir">
625 <xsl:with-param name="bootpkg" select="'systemd-units'"/>
626 <xsl:with-param name="url"
627 select="id('systemd-units')//itemizedlist//ulink/@url"/>
628 </xsl:call-template>
629<!-- if the preceding "screen" tag is role="root", and we are role="root"
630 the begin-root will not be called. So do it -->
631 <xsl:if
632 test="preceding-sibling::screen[1][@role='root'] and @role='root'">
633 <xsl:call-template name="begin-root"/>
634 </xsl:if>
635 </xsl:if>
636 <xsl:apply-templates select='.'/>
637 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts' or
638 @linkend='systemd-units']">
639<!-- if the next "screen" tag is role="root", and we are role="root"
640 the end-root has not been called. So do it -->
641 <xsl:if
642 test="following-sibling::screen[1][@role='root'] and @role='root'">
643 <xsl:call-template name="end-root"/>
644 </xsl:if>
645 <xsl:text>
646popd</xsl:text>
647<!-- if the next "screen" tag is role="root", and we are role="root"
648 the begin-root will not be called. So do it -->
649 <xsl:if
650 test="following-sibling::screen[1][@role='root'] and @role='root'">
651 <xsl:call-template name="begin-root"/>
652 </xsl:if>
653 </xsl:if>
654 </xsl:template>
655
656 <xsl:template match="command" mode="installation">
657 <xsl:param name="want-stats" select="false"/>
658 <xsl:variable name="ns" select="normalize-space(string())"/>
659 <xsl:variable name="first"
660 select="not(
661 boolean(
662 preceding-sibling::command[contains(text(),'check') or
663 contains(text(),'test')]))"/>
664 <xsl:variable name="last"
665 select="not(
666 boolean(
667 following-sibling::command[contains(text(),'check') or
668 contains(text(),'test')]))"/>
669 <xsl:choose>
670 <xsl:when test="$want-stats">
671 <xsl:if test="$first">
672 <xsl:text>
673
674echo Time after make: ${SECONDS} >> $INFOLOG
675echo Size after make: $(sudo du -skx --exclude home /) >> $INFOLOG
676echo Time before test: ${SECONDS} >> $INFOLOG
677
678</xsl:text>
679 </xsl:if>
680 </xsl:when>
681 <xsl:otherwise>
682 <xsl:text>
683#</xsl:text>
684 </xsl:otherwise>
685 </xsl:choose>
686 <xsl:choose>
687 <xsl:when test="contains($ns,'make')">
688 <xsl:value-of select="substring-before($ns,'make ')"/>
689 <xsl:text>make </xsl:text>
690 <xsl:if test="not(contains($ns,'-k'))">
691 <xsl:text>-k </xsl:text>
692 </xsl:if>
693 <xsl:value-of select="substring-after($ns,'make ')"/>
694 </xsl:when>
695 <xsl:otherwise>
696 <xsl:copy-of select="$ns"/>
697 </xsl:otherwise>
698 </xsl:choose>
699 <xsl:if test="$want-stats">
700 <xsl:text> &gt;&gt; $TESTLOG 2&gt;&amp;1</xsl:text>
701 </xsl:if>
702 <xsl:text> || true</xsl:text>
703 <xsl:if test="$want-stats">
704 <xsl:text>
705
706echo Time after test: ${SECONDS} >> $INFOLOG
707echo Size after test: $(sudo du -skx --exclude home /) >> $INFOLOG
708echo Time before install: ${SECONDS} >> $INFOLOG
709</xsl:text>
710 </xsl:if>
711 </xsl:template>
712
713 <xsl:template match="userinput|command">
714 <xsl:text>
715</xsl:text>
716 <xsl:apply-templates/>
717 </xsl:template>
718
719 <xsl:template match="userinput" mode="root">
720 <xsl:text>
721</xsl:text>
722 <xsl:apply-templates mode="root"/>
723 </xsl:template>
724
725 <xsl:template match="text()">
726 <xsl:call-template name="remove-ampersand">
727 <xsl:with-param name="out-string" select="string()"/>
728 </xsl:call-template>
729 </xsl:template>
730
731 <xsl:template match="text()" mode="root">
732 <xsl:call-template name="output-root">
733 <xsl:with-param name="out-string" select="string()"/>
734 </xsl:call-template>
735 </xsl:template>
736
737 <xsl:template name="output-root">
738 <xsl:param name="out-string" select="''"/>
739 <xsl:choose>
740 <xsl:when test="contains($out-string,'$') and $sudo = 'y'">
741 <xsl:call-template name="output-root">
742 <xsl:with-param name="out-string"
743 select="substring-before($out-string,'$')"/>
744 </xsl:call-template>
745 <xsl:text>\$</xsl:text>
746 <xsl:call-template name="output-root">
747 <xsl:with-param name="out-string"
748 select="substring-after($out-string,'$')"/>
749 </xsl:call-template>
750 </xsl:when>
751 <xsl:when test="contains($out-string,'`') and $sudo = 'y'">
752 <xsl:call-template name="output-root">
753 <xsl:with-param name="out-string"
754 select="substring-before($out-string,'`')"/>
755 </xsl:call-template>
756 <xsl:text>\`</xsl:text>
757 <xsl:call-template name="output-root">
758 <xsl:with-param name="out-string"
759 select="substring-after($out-string,'`')"/>
760 </xsl:call-template>
761 </xsl:when>
762 <xsl:when test="contains($out-string,'\') and $sudo = 'y'">
763 <xsl:call-template name="output-root">
764 <xsl:with-param name="out-string"
765 select="substring-before($out-string,'\')"/>
766 </xsl:call-template>
767 <xsl:text>\\</xsl:text>
768 <xsl:call-template name="output-root">
769 <xsl:with-param name="out-string"
770 select="substring-after($out-string,'\')"/>
771 </xsl:call-template>
772 </xsl:when>
773 <xsl:otherwise>
774 <xsl:call-template name="remove-ampersand">
775 <xsl:with-param name="out-string" select="$out-string"/>
776 </xsl:call-template>
777<!-- <xsl:value-of select="$out-string"/> -->
778 </xsl:otherwise>
779 </xsl:choose>
780 </xsl:template>
781
782 <xsl:template name="output-destdir">
783 <xsl:apply-templates
784 select="userinput|following-sibling::screen[@role='root']/userinput"
785 mode="destdir"/>
786 <xsl:text>
787
788echo Time after install: ${SECONDS} >> $INFOLOG
789echo Size after install: $(sudo du -skx --exclude home /) >> $INFOLOG
790</xsl:text>
791 </xsl:template>
792
793 <xsl:template match="userinput" mode="destdir">
794 <xsl:text>
795</xsl:text>
796 <xsl:choose>
797 <xsl:when test="./literal">
798 <xsl:call-template name="outputpkgdest">
799 <xsl:with-param name="outputstring" select="text()[1]"/>
800 </xsl:call-template>
801 <xsl:apply-templates select="literal"/>
802 <xsl:call-template name="outputpkgdest">
803 <xsl:with-param name="outputstring" select="text()[2]"/>
804 </xsl:call-template>
805 </xsl:when>
806 <xsl:otherwise>
807 <xsl:call-template name="outputpkgdest">
808 <xsl:with-param name="outputstring" select="string()"/>
809 </xsl:call-template>
810 </xsl:otherwise>
811 </xsl:choose>
812 </xsl:template>
813
814 <xsl:template name="outputpkgdest">
815 <xsl:param name="outputstring" select="'foo'"/>
816 <xsl:choose>
817 <xsl:when test="contains($outputstring,'make ')">
818 <xsl:choose>
819 <xsl:when test="not(starts-with($outputstring,'make'))">
820 <xsl:call-template name="outputpkgdest">
821 <xsl:with-param name="outputstring"
822 select="substring-before($outputstring,'make')"/>
823 </xsl:call-template>
824 <xsl:call-template name="outputpkgdest">
825 <xsl:with-param
826 name="outputstring"
827 select="substring-after($outputstring,
828 substring-before($outputstring,'make'))"/>
829 </xsl:call-template>
830 </xsl:when>
831 <xsl:otherwise>
832 <xsl:text>
833make DESTDIR=$PKG_DEST</xsl:text>
834 <xsl:call-template name="outputpkgdest">
835 <xsl:with-param
836 name="outputstring"
837 select="substring-after($outputstring,'make')"/>
838 </xsl:call-template>
839 </xsl:otherwise>
840 </xsl:choose>
841 </xsl:when>
842 <xsl:when test="contains($outputstring,'ninja install')">
843 <xsl:choose>
844 <xsl:when test="not(starts-with($outputstring,'ninja install'))">
845 <xsl:call-template name="outputpkgdest">
846 <xsl:with-param name="outputstring"
847 select="substring-before($outputstring,'ninja install')"/>
848 </xsl:call-template>
849 <xsl:call-template name="outputpkgdest">
850 <xsl:with-param
851 name="outputstring"
852 select="substring-after($outputstring,
853 substring-before($outputstring,'ninja install'))"/>
854 </xsl:call-template>
855 </xsl:when>
856 <xsl:otherwise>
857 <xsl:text>
858DESTDIR=$PKG_DEST ninja</xsl:text>
859 <xsl:call-template name="outputpkgdest">
860 <xsl:with-param
861 name="outputstring"
862 select="substring-after($outputstring,'ninja')"/>
863 </xsl:call-template>
864 </xsl:otherwise>
865 </xsl:choose>
866 </xsl:when>
867 <xsl:otherwise> <!-- no make nor ninja in this string -->
868 <xsl:choose>
869 <xsl:when test="contains($outputstring,'&gt;/') and
870 not(contains(substring-before($outputstring,'&gt;/'),' /'))">
871 <xsl:call-template name="remove-ampersand">
872 <xsl:with-param name="out-string"
873 select="substring-before($outputstring,'&gt;/')"/>
874 </xsl:call-template>
875<!-- <xsl:value-of select="substring-before($outputstring,'&gt;/')"/>-->
876 <xsl:text>&gt;$PKG_DEST/</xsl:text>
877 <xsl:call-template name="outputpkgdest">
878 <xsl:with-param name="outputstring" select="substring-after($outputstring,'&gt;/')"/>
879 </xsl:call-template>
880 </xsl:when>
881 <xsl:when test="contains($outputstring,' /')">
882 <xsl:call-template name="remove-ampersand">
883 <xsl:with-param name="out-string"
884 select="substring-before($outputstring,' /')"/>
885 </xsl:call-template>
886<!-- <xsl:value-of select="substring-before($outputstring,' /')"/>-->
887 <xsl:text> $PKG_DEST/</xsl:text>
888 <xsl:call-template name="outputpkgdest">
889 <xsl:with-param name="outputstring" select="substring-after($outputstring,' /')"/>
890 </xsl:call-template>
891 </xsl:when>
892 <xsl:otherwise>
893 <xsl:call-template name="remove-ampersand">
894 <xsl:with-param name="out-string" select="$outputstring"/>
895 </xsl:call-template>
896<!-- <xsl:value-of select="$outputstring"/>-->
897 </xsl:otherwise>
898 </xsl:choose>
899 </xsl:otherwise>
900 </xsl:choose>
901 </xsl:template>
902
903 <xsl:template name="remove-ampersand">
904 <xsl:param name="out-string" select="''"/>
905 <xsl:choose>
906 <xsl:when test="contains($out-string,'&amp;&amp;&#xA;')">
907 <xsl:variable name="instruction-before">
908 <xsl:call-template name="last-line">
909 <xsl:with-param
910 name="instructions"
911 select="substring-before($out-string,'&amp;&amp;&#xA;')"/>
912 </xsl:call-template>
913 </xsl:variable>
914 <xsl:call-template name="remove-end-space">
915 <xsl:with-param
916 name="instructions"
917 select="substring-before($out-string,'&amp;&amp;&#xA;')"/>
918 </xsl:call-template>
919 <xsl:if test="contains($instruction-before,' ]') or
920 contains($instruction-before,'test ') or
921 contains($instruction-before,'pgrep -l')">
922 <xsl:text> &amp;&amp;</xsl:text>
923 </xsl:if>
924 <xsl:text>
925</xsl:text>
926 <xsl:call-template name="remove-ampersand">
927 <xsl:with-param name="out-string"
928 select="substring-after($out-string,
929 '&amp;&amp;&#xA;')"/>
930 </xsl:call-template>
931 </xsl:when>
932 <xsl:otherwise>
933 <xsl:copy-of select="$out-string"/>
934 </xsl:otherwise>
935 </xsl:choose>
936 </xsl:template>
937
938 <xsl:template name="last-line">
939 <xsl:param name="instructions" select="''"/>
940 <xsl:choose>
941 <xsl:when test="contains($instructions,'&#xA;')">
942 <xsl:call-template name="last-line">
943 <xsl:with-param
944 name="instructions"
945 select="substring-after($instructions,'&#xA;')"/>
946 </xsl:call-template>
947 </xsl:when>
948 <xsl:otherwise>
949 <xsl:copy-of select="normalize-space($instructions)"/>
950 </xsl:otherwise>
951 </xsl:choose>
952 </xsl:template>
953
954 <xsl:template name="remove-end-space">
955 <xsl:param name="instructions" select="''"/>
956 <xsl:choose>
957 <xsl:when
958 test="substring($instructions,string-length($instructions))=' '">
959 <xsl:call-template name="remove-end-space">
960 <xsl:with-param
961 name="instructions"
962 select="substring($instructions,
963 1,
964 string-length($instructions)-1)"/>
965 </xsl:call-template>
966 </xsl:when>
967 <xsl:otherwise>
968 <xsl:copy-of select="$instructions"/>
969 </xsl:otherwise>
970 </xsl:choose>
971 </xsl:template>
972
973</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.