source: BLFS/xsl/scripts.xsl@ fbdd1a8

2.4 ablfs-more legacy trunk
Last change on this file since fbdd1a8 was 6eaae5e, checked in by Pierre Labastie <pierre@…>, 8 years ago

Fix Ed tarball unpacking

  • Property mode set to 100644
File size: 19.3 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: scripts.xsl 34 2012-02-21 16:05:09Z labastie $ -->
9
10<!-- XSLT stylesheet to create shell scripts from "linear build" BLFS books. -->
11
12 <!-- Build as user (y) or as root (n)? -->
13 <xsl:param name="sudo" select="'y'"/>
14
15 <xsl:template match="/">
16 <xsl:apply-templates select="//sect1"/>
17 </xsl:template>
18
19<!--=================== Master chunks code ======================-->
20
21 <xsl:template match="sect1">
22
23 <xsl:if test="@id != 'bootscripts'">
24 <!-- The file names -->
25 <xsl:variable name="filename" select="@id"/>
26
27 <!-- The build order -->
28 <xsl:variable name="position" select="position()"/>
29 <xsl:variable name="order">
30 <xsl:choose>
31 <xsl:when test="string-length($position) = 1">
32 <xsl:text>00</xsl:text>
33 <xsl:value-of select="$position"/>
34 </xsl:when>
35 <xsl:when test="string-length($position) = 2">
36 <xsl:text>0</xsl:text>
37 <xsl:value-of select="$position"/>
38 </xsl:when>
39 <xsl:otherwise>
40 <xsl:value-of select="$position"/>
41 </xsl:otherwise>
42 </xsl:choose>
43 </xsl:variable>
44
45 <!-- Depuration code -->
46 <xsl:message>
47 <xsl:text>SCRIPT is </xsl:text>
48 <xsl:value-of select="concat($order,'-z-',$filename)"/>
49 <xsl:text>&#xA; FTPDIR is </xsl:text>
50 <xsl:value-of select="$filename"/>
51 <xsl:text>&#xA;&#xA;</xsl:text>
52 </xsl:message>
53
54 <!-- Creating the scripts -->
55 <exsl:document href="{$order}-z-{$filename}" method="text">
56 <xsl:text>#!/bin/bash&#xA;set -e&#xA;&#xA;</xsl:text>
57 <xsl:choose>
58 <!-- Package page -->
59 <xsl:when test="sect2[@role='package']">
60 <!-- We build in a subdirectory -->
61 <xsl:text>PKG_DIR=</xsl:text>
62 <xsl:value-of select="$filename"/>
63 <xsl:text>&#xA;</xsl:text>
64 <!-- Download code and build commands -->
65 <xsl:apply-templates select="sect2"/>
66 <!-- Clean-up -->
67 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
68 <!-- In some case, some files in the build tree are owned
69 by root -->
70 <xsl:if test="$sudo='y'">
71 <xsl:text>sudo </xsl:text>
72 </xsl:if>
73 <xsl:text>rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
74 </xsl:when>
75 <!-- Non-package page -->
76 <xsl:otherwise>
77 <xsl:apply-templates select=".//screen"/>
78 </xsl:otherwise>
79 </xsl:choose>
80 <xsl:text>exit</xsl:text>
81 </exsl:document>
82 </xsl:if>
83 </xsl:template>
84
85<!--======================= Sub-sections code =======================-->
86
87 <xsl:template match="sect2">
88 <xsl:choose>
89 <xsl:when test="@role = 'package'">
90 <xsl:text>mkdir -p $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
91 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
92 <!-- Download information is in bridgehead tags -->
93 <xsl:apply-templates select="bridgehead[@renderas='sect3']"/>
94 <xsl:text>&#xA;</xsl:text>
95 </xsl:when>
96 <xsl:when test="@role = 'qt4-prefix' or @role = 'qt5-prefix'">
97 <xsl:apply-templates select=".//screen"/>
98 </xsl:when>
99 <xsl:when test="@role = 'installation'">
100 <xsl:text>
101find . -maxdepth 1 -mindepth 1 -type d | xargs </xsl:text>
102 <xsl:if test="$sudo='y'">
103 <xsl:text>sudo </xsl:text>
104 </xsl:if>
105 <xsl:text>rm -rf
106case $PACKAGE in
107 *.tar.gz|*.tar.bz2|*.tar.xz|*.tgz|*.tar.lzma)
108 tar -xvf $PACKAGE &gt; unpacked
109 UNPACKDIR=`grep '[^./]\+' unpacked | head -n1 | sed 's@^\./@@;s@/.*@@'`
110 ;;
111 *.tar.lz)
112 bsdtar -xvf $PACKAGE 2&gt; unpacked
113 UNPACKDIR=`head -n1 unpacked | cut -d" " -f2 | sed 's@^\./@@;s@/.*@@'`
114 ;;
115 *.zip)
116 zipinfo -1 $PACKAGE &gt; unpacked
117 UNPACKDIR="$(sed 's@/.*@@' unpacked | uniq )"
118 if test $(wc -w &lt;&lt;&lt; $UNPACKDIR) -eq 1; then
119 unzip $PACKAGE
120 else
121 UNPACKDIR=${PACKAGE%.zip}
122 unzip -d $UNPACKDIR $PACKAGE
123 fi
124 ;;
125 *)
126 UNPACKDIR=$PKG_DIR-build
127 mkdir $UNPACKDIR
128 cp $PACKAGE $UNPACKDIR
129 ;;
130esac
131cd $UNPACKDIR&#xA;
132</xsl:text>
133 <xsl:apply-templates select=".//screen | .//para/command"/>
134 <xsl:if test="$sudo = 'y'">
135 <xsl:text>sudo /sbin/</xsl:text>
136 </xsl:if>
137 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
138 </xsl:when>
139 <xsl:when test="@role = 'configuration'">
140 <xsl:apply-templates select=".//screen" mode="config"/>
141 </xsl:when>
142 </xsl:choose>
143 </xsl:template>
144
145<!--==================== Download code =======================-->
146
147 <!-- template for extracting the filename from an url in the form:
148 proto://internet.name/dir1/.../dirn/filename?condition.
149 Needed, because substring-after(...,'/') returns only the
150 substring after the first '/'. -->
151 <xsl:template name="package_name">
152 <xsl:param name="url" select="foo"/>
153 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
154 <xsl:choose>
155 <xsl:when test="contains($sub-url,'/')">
156 <xsl:call-template name="package_name">
157 <xsl:with-param name="url" select="$sub-url"/>
158 </xsl:call-template>
159 </xsl:when>
160 <xsl:otherwise>
161 <xsl:choose>
162 <xsl:when test="contains($sub-url,'?')">
163 <xsl:value-of select="substring-before($sub-url,'?')"/>
164 </xsl:when>
165 <xsl:otherwise>
166 <xsl:value-of select="$sub-url"/>
167 </xsl:otherwise>
168 </xsl:choose>
169 </xsl:otherwise>
170 </xsl:choose>
171 </xsl:template>
172
173 <!-- Generates the code to download a package, an additional package or
174 a patch. -->
175 <xsl:template name="download-file">
176 <xsl:param name="httpurl" select="''"/>
177 <xsl:param name="ftpurl" select="''"/>
178 <xsl:param name="md5" select="''"/>
179 <xsl:param name="varname" select="''"/>
180 <xsl:variable name="package">
181 <xsl:call-template name="package_name">
182 <xsl:with-param name="url">
183 <xsl:choose>
184 <xsl:when test="string-length($httpurl) &gt; 10">
185 <xsl:value-of select="$httpurl"/>
186 </xsl:when>
187 <xsl:otherwise>
188 <xsl:value-of select="$ftpurl"/>
189 </xsl:otherwise>
190 </xsl:choose>
191 </xsl:with-param>
192 </xsl:call-template>
193 </xsl:variable>
194 <xsl:variable name="first_letter"
195 select="translate(substring($package,1,1),
196 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
197 'abcdefghijklmnopqrstuvwxyz')"/>
198 <xsl:text>&#xA;</xsl:text>
199 <xsl:value-of select="$varname"/>
200 <xsl:text>=</xsl:text>
201 <xsl:value-of select="$package"/>
202 <xsl:text>&#xA;if [[ ! -f $</xsl:text>
203 <xsl:value-of select="$varname"/>
204 <xsl:text> ]] ; then&#xA;</xsl:text>
205 <!-- SRC_ARCHIVE may have subdirectories or not -->
206 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$</xsl:text>
207 <xsl:value-of select="$varname"/>
208 <xsl:text> ]] ; then&#xA;</xsl:text>
209 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$</xsl:text>
210 <xsl:value-of select="$varname"/>
211 <xsl:text> $</xsl:text>
212 <xsl:value-of select="$varname"/>
213 <xsl:text>&#xA;</xsl:text>
214 <xsl:text> elif [[ -f $SRC_ARCHIVE/$</xsl:text>
215 <xsl:value-of select="$varname"/>
216 <xsl:text> ]] ; then&#xA;</xsl:text>
217 <xsl:text> cp $SRC_ARCHIVE/$</xsl:text>
218 <xsl:value-of select="$varname"/>
219 <xsl:text> $</xsl:text>
220 <xsl:value-of select="$varname"/>
221 <xsl:text>&#xA; else&#xA;</xsl:text>
222 <!-- Download from upstream http -->
223 <xsl:if test="string-length($httpurl) &gt; 10">
224 <xsl:text> wget -T 30 -t 5 </xsl:text>
225 <xsl:value-of select="$httpurl"/>
226 <xsl:text> ||&#xA;</xsl:text>
227 </xsl:if>
228 <!-- Download from upstream ftp -->
229 <xsl:if test="string-length($ftpurl) &gt; 10">
230 <xsl:text> wget -T 30 -t 5 </xsl:text>
231 <xsl:value-of select="$ftpurl"/>
232 <xsl:text> ||&#xA;</xsl:text>
233 </xsl:if>
234 <!-- The FTP_SERVER mirror as a last resort -->
235 <xsl:text> wget -T 30 -t 5 ${FTP_SERVER}svn/</xsl:text>
236 <xsl:value-of select="$first_letter"/>
237 <xsl:text>/$</xsl:text>
238 <xsl:value-of select="$varname"/>
239 <xsl:text>
240 cp $</xsl:text>
241 <xsl:value-of select="$varname"/>
242 <xsl:text> $SRC_ARCHIVE
243 fi
244fi
245</xsl:text>
246 <xsl:if test="string-length($md5) &gt; 10">
247 <xsl:text>echo "</xsl:text>
248 <xsl:value-of select="$md5"/>
249 <xsl:text>&#x20;&#x20;$</xsl:text>
250 <xsl:value-of select="$varname"/>
251 <xsl:text>" | md5sum -c -
252</xsl:text>
253 </xsl:if>
254 </xsl:template>
255
256 <!-- Extract the MD5 sum information -->
257 <xsl:template match="para" mode="md5">
258 <xsl:choose>
259 <xsl:when test="contains(substring-after(string(),'sum: '),'&#xA;')">
260 <xsl:value-of select="substring-before(substring-after(string(),'sum: '),'&#xA;')"/>
261 </xsl:when>
262 <xsl:otherwise>
263 <xsl:value-of select="substring-after(string(),'sum: ')"/>
264 </xsl:otherwise>
265 </xsl:choose>
266 </xsl:template>
267
268 <!-- We have several templates itemizedlist, depending on whether we
269 expect the package information, or additional package(s) or patch(es)
270 information. Select the appropriate mode here. -->
271 <xsl:template match="bridgehead">
272 <xsl:choose>
273 <!-- Special case for Openjdk -->
274 <xsl:when test="contains(string(),'Source Package Information')">
275 <xsl:apply-templates
276 select="following-sibling::itemizedlist[1]//simplelist">
277 <xsl:with-param name="varname" select="'PACKAGE'"/>
278 </xsl:apply-templates>
279 <xsl:apply-templates select="following-sibling::itemizedlist
280 [preceding-sibling::bridgehead[1]=current()
281 and position() &gt;1]//simplelist">
282 <xsl:with-param name="varname" select="'PACKAGE1'"/>
283 </xsl:apply-templates>
284 </xsl:when>
285 <!-- Package information -->
286 <xsl:when test="contains(string(),'Package Information')">
287 <xsl:apply-templates select="following-sibling::itemizedlist
288 [preceding-sibling::bridgehead[1]=current()]"
289 mode="package"/>
290 </xsl:when>
291 <!-- Additional package information -->
292 <!-- special case for llvm -->
293 <xsl:when test="contains(string(),'Optional Download')">
294 <xsl:apply-templates select="following-sibling::itemizedlist"
295 mode="additional"/>
296 </xsl:when>
297 <!-- All other additional packages have "Additional" -->
298 <xsl:when test="contains(string(),'Additional')">
299 <xsl:apply-templates select="following-sibling::itemizedlist"
300 mode="additional"/>
301 </xsl:when>
302 <!-- Do not do anything if the dev has created another type of
303 bridgehead. -->
304 <xsl:otherwise/>
305 </xsl:choose>
306 </xsl:template>
307
308 <!-- Call the download code template with appropriate parameters -->
309 <xsl:template match="itemizedlist" mode="package">
310 <xsl:call-template name="download-file">
311 <xsl:with-param name="httpurl">
312 <xsl:value-of select="./listitem[1]/para/ulink/@url"/>
313 </xsl:with-param>
314 <xsl:with-param name="ftpurl">
315 <xsl:value-of select="./listitem/para[contains(string(),'FTP')]/ulink/@url"/>
316 </xsl:with-param>
317 <xsl:with-param name="md5">
318 <xsl:apply-templates select="./listitem/para[contains(string(),'MD5')]"
319 mode="md5"/>
320 </xsl:with-param>
321 <xsl:with-param name="varname" select="'PACKAGE'"/>
322 </xsl:call-template>
323 </xsl:template>
324
325 <xsl:template match="itemizedlist" mode="additional">
326 <!-- The normal layout is "one listitem"<->"one url", but some devs
327 find amusing to have FTP and/or MD5sum listitems, or to
328 enclose the download information inside a simplelist tag... -->
329 <xsl:for-each select="listitem[.//ulink]">
330 <xsl:choose>
331 <!-- hopefully, there was a HTTP line before -->
332 <xsl:when test="contains(string(./para),'FTP')"/>
333 <xsl:when test=".//simplelist">
334 <xsl:apply-templates select=".//simplelist">
335 <xsl:with-param name="varname" select="'PACKAGE1'"/>
336 </xsl:apply-templates>
337 </xsl:when>
338 <xsl:otherwise>
339 <xsl:call-template name="download-file">
340 <xsl:with-param name="httpurl">
341 <xsl:value-of select="./para/ulink/@url"/>
342 </xsl:with-param>
343 <xsl:with-param name="ftpurl">
344 <xsl:value-of
345 select="following-sibling::listitem[1]/
346 para[contains(string(),'FTP')]/ulink/@url"/>
347 </xsl:with-param>
348 <xsl:with-param name="md5">
349 <xsl:apply-templates
350 select="following-sibling::listitem[position()&lt;3]/
351 para[contains(string(),'MD5')]"
352 mode="md5"/>
353 </xsl:with-param>
354 <xsl:with-param name="varname">
355 <xsl:choose>
356 <xsl:when test="contains(./para/ulink/@url,'.patch')">
357 <xsl:text>PATCH</xsl:text>
358 </xsl:when>
359 <xsl:otherwise>
360 <xsl:text>PACKAGE1</xsl:text>
361 </xsl:otherwise>
362 </xsl:choose>
363 </xsl:with-param>
364 </xsl:call-template>
365 </xsl:otherwise>
366 </xsl:choose>
367 </xsl:for-each>
368 </xsl:template>
369
370 <!-- the simplelist case. Hopefully, the layout is one member for
371 url, one for md5 and others for various information, that we do not
372 use -->
373 <xsl:template match="simplelist">
374 <xsl:param name="varname" select="'PACKAGE1'"/>
375 <xsl:call-template name="download-file">
376 <xsl:with-param name="httpurl" select=".//ulink/@url"/>
377 <xsl:with-param name="md5">
378 <xsl:value-of select="substring-after(member[contains(string(),'MD5')],'sum: ')"/>
379 </xsl:with-param>
380 <xsl:with-param name="varname" select="$varname"/>
381 </xsl:call-template>
382 </xsl:template>
383<!--======================== Commands code ==========================-->
384
385 <xsl:template match="screen">
386 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
387 <xsl:choose>
388 <xsl:when test="@role = 'root'">
389 <xsl:if test="$sudo = 'y'">
390 <xsl:text>sudo -E sh &lt;&lt; ROOT_EOF&#xA;</xsl:text>
391 </xsl:if>
392 <xsl:apply-templates mode="root"/>
393 <xsl:if test="$sudo = 'y'">
394 <xsl:text>&#xA;ROOT_EOF</xsl:text>
395 </xsl:if>
396 </xsl:when>
397 <xsl:otherwise>
398 <xsl:apply-templates select="userinput"/>
399 </xsl:otherwise>
400 </xsl:choose>
401 <xsl:text>&#xA;</xsl:text>
402 </xsl:if>
403 </xsl:template>
404
405 <xsl:template match="screen" mode="config">
406 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
407 <xsl:text>[[ ! -d $SRC_DIR/blfs-bootscripts ]] &amp;&amp; mkdir $SRC_DIR/blfs-bootscripts
408pushd $SRC_DIR/blfs-bootscripts
409URL=</xsl:text>
410 <xsl:value-of select="id('bootscripts')//itemizedlist//ulink/@url"/><xsl:text>
411BOOTPACKG=$(basename $URL)
412if [[ ! -f $BOOTPACKG ]] ; then
413 if [[ -f $SRC_ARCHIVE/$PKG_DIR/$BOOTPACKG ]] ; then
414 cp $SRC_ARCHIVE/$PKG_DIR/$BOOTPACKG $BOOTPACKG
415 elif [[ -f $SRC_ARCHIVE/$BOOTPACKG ]] ; then
416 cp $SRC_ARCHIVE/$BOOTPACKG $BOOTPACKG
417 else
418 wget -T 30 -t 5 $URL
419 cp $BOOTPACKG $SRC_ARCHIVE
420 fi
421 rm -f unpacked
422fi
423
424if [[ -e unpacked ]] ; then
425 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
426 if ! [[ -d $BOOTUNPACKDIR ]]; then
427 rm unpacked
428 tar -xvf $BOOTPACKG > unpacked
429 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
430 fi
431else
432 tar -xvf $BOOTPACKG > unpacked
433 BOOTUNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
434fi
435cd $BOOTUNPACKDIR
436</xsl:text>
437 </xsl:if>
438 <xsl:apply-templates select='.'/>
439 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
440 <xsl:text>
441popd</xsl:text>
442 </xsl:if>
443 <xsl:text>&#xA;</xsl:text>
444 </xsl:template>
445
446 <xsl:template match="para/command">
447 <xsl:variable name="ns" select="normalize-space(string())"/>
448 <xsl:if test="(contains($ns,'test') or
449 contains($ns,'check'))">
450 <xsl:text>#</xsl:text>
451 <xsl:value-of select="substring-before($ns,'make ')"/>
452 <xsl:text>make </xsl:text>
453 <xsl:if test="not(contains($ns,'-k'))">
454 <xsl:text>-k </xsl:text>
455 </xsl:if>
456 <xsl:value-of select="substring-after($ns,'make ')"/>
457 <xsl:text> || true&#xA;</xsl:text>
458 </xsl:if>
459 </xsl:template>
460
461 <xsl:template match="userinput">
462 <xsl:apply-templates/>
463 </xsl:template>
464
465 <xsl:template match="text()" mode="root">
466 <xsl:call-template name="output-root">
467 <xsl:with-param name="out-string" select="string()"/>
468 </xsl:call-template>
469 </xsl:template>
470
471 <xsl:template name="output-root">
472 <xsl:param name="out-string" select="''"/>
473 <xsl:choose>
474 <xsl:when test="contains($out-string,'make ')">
475 <xsl:call-template name="output-root">
476 <xsl:with-param name="out-string"
477 select="substring-before($out-string,'make ')"/>
478 </xsl:call-template>
479 <xsl:text>make -j1 </xsl:text>
480 <xsl:call-template name="output-root">
481 <xsl:with-param name="out-string"
482 select="substring-after($out-string,'make ')"/>
483 </xsl:call-template>
484 </xsl:when>
485 <xsl:when test="contains($out-string,'$') and $sudo = 'y'">
486 <xsl:call-template name="output-root">
487 <xsl:with-param name="out-string"
488 select="substring-before($out-string,'$')"/>
489 </xsl:call-template>
490 <xsl:text>\$</xsl:text>
491 <xsl:call-template name="output-root">
492 <xsl:with-param name="out-string"
493 select="substring-after($out-string,'$')"/>
494 </xsl:call-template>
495 </xsl:when>
496 <xsl:when test="contains($out-string,'`') and $sudo = 'y'">
497 <xsl:call-template name="output-root">
498 <xsl:with-param name="out-string"
499 select="substring-before($out-string,'`')"/>
500 </xsl:call-template>
501 <xsl:text>\`</xsl:text>
502 <xsl:call-template name="output-root">
503 <xsl:with-param name="out-string"
504 select="substring-after($out-string,'`')"/>
505 </xsl:call-template>
506 </xsl:when>
507 <xsl:when test="contains($out-string,'\') and $sudo = 'y'">
508 <xsl:call-template name="output-root">
509 <xsl:with-param name="out-string"
510 select="substring-before($out-string,'\')"/>
511 </xsl:call-template>
512 <xsl:text>\\</xsl:text>
513 <xsl:call-template name="output-root">
514 <xsl:with-param name="out-string"
515 select="substring-after($out-string,'\')"/>
516 </xsl:call-template>
517 </xsl:when>
518 <xsl:otherwise>
519 <xsl:value-of select="$out-string"/>
520 </xsl:otherwise>
521 </xsl:choose>
522 </xsl:template>
523
524 <xsl:template match="replaceable">
525 <xsl:text>**EDITME</xsl:text>
526 <xsl:apply-templates/>
527 <xsl:text>EDITME**</xsl:text>
528 </xsl:template>
529
530 <xsl:template match="replaceable" mode="root">
531 <xsl:text>**EDITME</xsl:text>
532 <xsl:apply-templates/>
533 <xsl:text>EDITME**</xsl:text>
534 </xsl:template>
535
536</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.