source: BLFS/xsl/scripts.xsl@ 63fc514

ablfs
Last change on this file since 63fc514 was 63fc514, checked in by Pierre Labastie <pierre@…>, 13 years ago

Initial modificaiton of BLFS tools

  • Property mode set to 100644
File size: 17.1 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'] and not(@id = 'xorg7-app' or
60 @id = 'xorg7-data' or @id = 'xorg7-driver' or
61 @id = 'xorg7-font' or @id = 'xorg7-lib' or
62 @id = 'xorg7-proto' or @id = 'xorg7-util')">
63 <!-- Variables -->
64 <!-- These three lines could be important if SRC_ARCHIVE,
65 FTP_SERVER and SRCDIR were not set in the environment.
66 But they are not tested for length or anything later,
67 so not needed
68 <xsl:text>SRC_ARCHIVE=$SRC_ARCHIVE&#xA;</xsl:text>
69 <xsl:text>FTP_SERVER=$FTP_SERVER&#xA;</xsl:text>
70 <xsl:text>SRC_DIR=$SRC_DIR&#xA;&#xA;</xsl:text>-->
71 <xsl:text>&#xA;PKG_DIR=</xsl:text>
72 <xsl:value-of select="$filename"/>
73 <xsl:text>&#xA;</xsl:text>
74 <!-- Download code and build commands -->
75 <xsl:apply-templates select="sect2"/>
76 <!-- Clean-up -->
77 <!-- xorg7-server used to require mesalib tree being present.
78 That is no more true
79 <xsl:if test="not(@id='mesalib')"> -->
80 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
81 <xsl:text>rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
82 <!-- Same reason as preceding comment
83 </xsl:if>
84 <xsl:if test="@id='xorg7-server'">
85 <xsl:text>cd $SRC_DIR/MesaLib
86UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
87rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
88 </xsl:if> -->
89 </xsl:when>
90 <!-- Xorg7 pseudo-packages -->
91 <xsl:when test="contains(@id,'xorg7') and not(@id = 'xorg7-server')">
92 <xsl:text># Useless SRC_DIR=$SRC_DIR
93
94cd $SRC_DIR
95mkdir -p xc
96cd xc&#xA;</xsl:text>
97 <xsl:apply-templates select="sect2" mode="xorg7"/>
98 </xsl:when>
99 <!-- Non-package page -->
100 <xsl:otherwise>
101 <xsl:apply-templates select=".//screen"/>
102 </xsl:otherwise>
103 </xsl:choose>
104 <xsl:text>exit</xsl:text>
105 </exsl:document>
106 </xsl:if>
107 </xsl:template>
108
109<!--======================= Sub-sections code =======================-->
110
111 <xsl:template match="sect2">
112 <xsl:choose>
113 <xsl:when test="@role = 'package'">
114 <xsl:text>mkdir -p $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
115 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
116 <xsl:apply-templates select="bridgehead[@renderas='sect3']"/>
117 <xsl:text>&#xA;</xsl:text>
118 </xsl:when>
119 <xsl:when test="@role = 'installation'">
120 <xsl:text>
121if [[ -e unpacked ]] ; then
122 UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
123 [[ -n $UNPACKDIR ]] &amp;&amp; [[ -d $UNPACKDIR ]] &amp;&amp; rm -rf $UNPACKDIR
124fi
125tar -xvf $PACKAGE > unpacked
126UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
127cd $UNPACKDIR&#xA;</xsl:text>
128 <xsl:apply-templates select=".//screen | .//para/command"/>
129 <xsl:if test="$sudo = 'y'">
130 <xsl:text>sudo /sbin/</xsl:text>
131 </xsl:if>
132 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
133 </xsl:when>
134 <xsl:when test="@role = 'configuration'">
135 <xsl:apply-templates select=".//screen" mode="config"/>
136 </xsl:when>
137 </xsl:choose>
138 </xsl:template>
139
140 <xsl:template match="sect2" mode="xorg7">
141 <xsl:choose>
142 <xsl:when test="@role = 'package'">
143 <xsl:apply-templates select="itemizedlist/listitem/para" mode="xorg7"/>
144 </xsl:when>
145 <xsl:when test="not(@role)">
146<!-- Useless <xsl:text>SRC_ARCHIVE=$SRC_ARCHIVE
147FTP_SERVER=$FTP_SERVER&#xA;</xsl:text> -->
148 <xsl:apply-templates select=".//screen" mode="sect-ver"/>
149 <xsl:text>mkdir -p ${section}&#xA;cd ${section}&#xA;</xsl:text>
150 <xsl:apply-templates select="../sect2[@role='package']/itemizedlist/listitem/para" mode="xorg7-patch"/>
151 <xsl:text>for line in $(grep -v '^#' ../${sect_ver}.wget) ; do
152 if [[ ! -f ${line} ]] ; then
153 if [[ -f $SRC_ARCHIVE/Xorg/${section}/${line} ]] ; then
154 cp $SRC_ARCHIVE/Xorg/${section}/${line} ${line}
155 elif [[ -f $SRC_ARCHIVE/Xorg/${line} ]] ; then
156 cp $SRC_ARCHIVE/Xorg/${line} ${line}
157 elif [[ -f $SRC_ARCHIVE/${section}/${line} ]] ; then
158 cp $SRC_ARCHIVE/${section}/${line} ${line}
159 elif [[ -f $SRC_ARCHIVE/${line} ]] ; then
160 cp $SRC_ARCHIVE/${line} ${line}
161 else
162 wget -T 30 -t 5 ${FTP_X_SERVER}pub/individual/${section}/${line} || \
163 wget -T 30 -t 5 http://xorg.freedesktop.org/releases/individual/${section}/${line}
164 fi
165 fi
166done
167md5sum -c ../${sect_ver}.md5
168cp ../${sect_ver}.wget ../${sect_ver}.wget.orig
169cp ../${sect_ver}.md5 ../${sect_ver}.md5.orig&#xA;</xsl:text>
170 </xsl:when>
171 <xsl:when test="@role = 'installation'">
172 <xsl:text>for package in $(grep -v '^#' ../${sect_ver}.wget) ; do
173 packagedir=$(echo $package | sed 's/.tar.bz2//')
174 tar -xf ${package}
175 cd ${packagedir}&#xA;</xsl:text>
176 <xsl:apply-templates select=".//screen | .//para/command"/>
177 <xsl:text> cd ..
178 rm -rf ${packagedir}
179 sed -i "/${package}/d" ../${sect_ver}.wget
180 sed -i "/${package}/d" ../${sect_ver}.md5
181done
182mv ../${sect_ver}.wget.orig ../${sect_ver}.wget
183mv ../${sect_ver}.md5.orig ../${sect_ver}.md5&#xA;</xsl:text>
184 <xsl:if test="$sudo = 'y'">
185 <xsl:text>sudo /sbin/</xsl:text>
186 </xsl:if>
187 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
188 </xsl:when>
189 <xsl:when test="@role = 'configuration'">
190 <xsl:apply-templates select=".//screen"/>
191 <xsl:text>&#xA;</xsl:text>
192 </xsl:when>
193 </xsl:choose>
194 </xsl:template>
195
196<!--==================== Download code =======================-->
197
198 <xsl:template name="package_name">
199 <xsl:param name="url" select="foo"/>
200 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
201 <xsl:choose>
202 <xsl:when test="contains($sub-url,'/')">
203 <xsl:call-template name="package_name">
204 <xsl:with-param name="url" select="$sub-url"/>
205 </xsl:call-template>
206 </xsl:when>
207 <xsl:otherwise>
208 <xsl:choose>
209 <xsl:when test="contains($sub-url,'?')">
210 <xsl:value-of select="substring-before($sub-url,'?')"/>
211 </xsl:when>
212<!-- Should never happen
213 <xsl:when test="contains($sub-url,'.patch')"/> -->
214 <xsl:otherwise>
215 <xsl:value-of select="$sub-url"/>
216 </xsl:otherwise>
217 </xsl:choose>
218 </xsl:otherwise>
219 </xsl:choose>
220 </xsl:template>
221
222 <xsl:template match="bridgehead">
223 <xsl:choose>
224 <xsl:when test="string()='Package Information'">
225 <xsl:variable name="url">
226 <xsl:choose>
227 <xsl:when
228 test="string-length(
229 following-sibling::itemizedlist[1]/listitem[1]/para/ulink/@url)
230 &gt; 10">
231 <xsl:value-of select=
232 "following-sibling::itemizedlist[1]/listitem[1]/para/ulink/@url"/>
233 </xsl:when>
234 <xsl:otherwise>
235 <xsl:value-of select=
236 "following-sibling::itemizedlist[1]/listitem[2]/para/ulink/@url"/>
237 </xsl:otherwise>
238 </xsl:choose>
239 </xsl:variable>
240 <xsl:variable name="package">
241 <xsl:call-template name="package_name">
242 <xsl:with-param name="url" select="$url"/>
243 </xsl:call-template>
244 </xsl:variable>
245 <xsl:variable
246 name="first_letter"
247 select="translate(substring($package,1,1),
248 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
249 'abcdefghijklmnopqrstuvwxyz')"/>
250 <xsl:text>PACKAGE=</xsl:text>
251 <xsl:value-of select="$package"/>
252 <xsl:text>&#xA;if [[ ! -f $PACKAGE ]] ; then&#xA;</xsl:text>
253 <!-- SRC_ARCHIVE may have subdirectories or not -->
254 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$PACKAGE ]] ; then&#xA;</xsl:text>
255 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$PACKAGE $PACKAGE&#xA;</xsl:text>
256 <xsl:text> elif [[ -f $SRC_ARCHIVE/$PACKAGE ]] ; then&#xA;</xsl:text>
257 <xsl:text> cp $SRC_ARCHIVE/$PACKAGE $PACKAGE&#xA; else&#xA;</xsl:text>
258 <!-- The FTP_SERVER mirror -->
259 <xsl:text> wget -T 30 -t 5 ${FTP_SERVER}svn/</xsl:text>
260 <xsl:value-of select="$first_letter"/>
261 <xsl:text>/$PACKAGE</xsl:text>
262 <xsl:apply-templates
263 select="following-sibling::itemizedlist[1]/listitem/para"
264 mode="package"/>
265 </xsl:when>
266 <xsl:when test="string()='Additional Downloads'">
267 <xsl:apply-templates
268 select="following-sibling::itemizedlist[1]/listitem/para"
269 mode="additional"/>
270 </xsl:when>
271 <xsl:otherwise/>
272 </xsl:choose>
273 </xsl:template>
274
275 <xsl:template match="para" mode="package">
276 <xsl:choose>
277 <xsl:when test="contains(string(),'HTTP')">
278 <!-- Upstream HTTP URL -->
279 <xsl:if test="string-length(ulink/@url) &gt; '10'">
280 <xsl:text> || \&#xA; wget -T 30 -t 5 </xsl:text>
281 <xsl:choose>
282 <xsl:when test="contains(ulink/@url,'?')">
283 <xsl:value-of select="substring-before(ulink/@url,'?')"/>
284 </xsl:when>
285 <xsl:otherwise>
286 <xsl:value-of select="ulink/@url"/>
287 </xsl:otherwise>
288 </xsl:choose>
289 <xsl:if test="not(contains(string(parent::listitem/following-sibling::listitem[1]/para),'FTP'))">
290 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
291 </xsl:if>
292 </xsl:if>
293 </xsl:when>
294 <xsl:when test="contains(string(),'FTP')">
295 <!-- Upstream FTP URL -->
296 <xsl:if test="string-length(ulink/@url) &gt; '10'">
297 <xsl:text> || \&#xA; wget -T 30 -t 5 </xsl:text>
298 <xsl:value-of select="ulink/@url"/>
299 </xsl:if>
300 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
301 </xsl:when>
302 <xsl:when test="contains(string(),'MD5')">
303 <xsl:text>echo "</xsl:text>
304 <xsl:value-of select="substring-after(string(),'sum: ')"/>
305 <xsl:text>&#x20;&#x20;$PACKAGE" | md5sum -c -&#xA;</xsl:text>
306 </xsl:when>
307 </xsl:choose>
308 </xsl:template>
309
310 <xsl:template match="para" mode="additional">
311 <xsl:choose>
312 <xsl:when test="contains(string(ulink/@url),'.patch')">
313 <xsl:text>wget -T 30 -t 5 </xsl:text>
314 <xsl:value-of select="ulink/@url"/>
315 <xsl:text>&#xA;</xsl:text>
316 </xsl:when>
317 <xsl:when test="ulink">
318 <xsl:if test="string-length(ulink/@url) &gt; '10'">
319 <xsl:variable name="package">
320 <xsl:call-template name="package_name">
321 <xsl:with-param name="url" select="ulink/@url"/>
322 </xsl:call-template>
323 </xsl:variable>
324 <xsl:variable
325 name="first_letter"
326 select="translate(substring($package,1,1),
327 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
328 'abcdefghijklmnopqrstuvwxyz')"/>
329 <xsl:text>PACKAGE1=</xsl:text>
330 <xsl:value-of select="$package"/>
331 <xsl:text>&#xA;if [[ ! -f $PACKAGE1 ]] ; then&#xA;</xsl:text>
332 <!-- SRC_ARCHIVE may have subdirectories or not -->
333 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$PACKAGE1 ]] ; then&#xA;</xsl:text>
334 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$PACKAGE1 $PACKAGE1&#xA;</xsl:text>
335 <xsl:text> elif [[ -f $SRC_ARCHIVE/$PACKAGE1 ]] ; then&#xA;</xsl:text>
336 <xsl:text> cp $SRC_ARCHIVE/$PACKAGE1 $PACKAGE1&#xA; else&#xA;</xsl:text>
337 <!-- The FTP_SERVER mirror -->
338 <xsl:text> wget -T 30 -t 5 ${FTP_SERVER}blfs/svn/</xsl:text>
339 <xsl:value-of select="$first_letter"/>
340 <xsl:text>/$PACKAGE1</xsl:text>
341 <xsl:text> || \&#xA; wget -T 30 -t 5 </xsl:text>
342 <xsl:value-of select="ulink/@url"/>
343 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
344 </xsl:if>
345 </xsl:when>
346 <xsl:when test="contains(string(),'MD5')">
347 <xsl:text>echo "</xsl:text>
348 <xsl:value-of select="substring-after(string(),'sum: ')"/>
349 <xsl:text>&#x20;&#x20;$PACKAGE1" | md5sum -c -&#xA;</xsl:text>
350 </xsl:when>
351 </xsl:choose>
352 </xsl:template>
353
354 <xsl:template match="itemizedlist/listitem/para" mode="xorg7">
355 <xsl:if test="contains(string(ulink/@url),'.md5') or
356 contains(string(ulink/@url),'.wget')">
357 <xsl:text>wget -T 30 -t 5 </xsl:text>
358 <xsl:value-of select="ulink/@url"/>
359 <xsl:text>&#xA;</xsl:text>
360 </xsl:if>
361 </xsl:template>
362
363 <xsl:template match="itemizedlist/listitem/para" mode="xorg7-patch">
364 <xsl:if test="contains(string(ulink/@url),'.patch')">
365 <xsl:text>wget -T 30 -t 5 </xsl:text>
366 <xsl:value-of select="ulink/@url"/>
367 <xsl:text>&#xA;</xsl:text>
368 </xsl:if>
369 </xsl:template>
370
371<!--======================== Commands code ==========================-->
372
373 <xsl:template match="screen">
374 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
375 <xsl:if test="@role = 'root' and $sudo = 'y'">
376 <xsl:text>sudo sh -c '</xsl:text>
377 </xsl:if>
378 <xsl:apply-templates select="userinput"/>
379 <xsl:if test="@role = 'root' and $sudo = 'y'">
380 <xsl:text>'</xsl:text>
381 </xsl:if>
382 <xsl:text>&#xA;</xsl:text>
383 </xsl:if>
384 </xsl:template>
385
386 <xsl:template match="screen" mode="config">
387 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
388 <xsl:text>[[ ! -d $SRC_DIR/blfs-bootscripts ]] &amp;&amp; mkdir $SRC_DIR/blfs-bootscripts
389pushd $SRC_DIR/blfs-bootscripts
390URL=</xsl:text>
391 <xsl:value-of select="id('bootscripts')//itemizedlist//ulink/@url"/><xsl:text>
392BOOTPACKG=$(basename $URL)
393[[ ! -f "$BOOTPACKG" ]] &amp;&amp; { wget -T 30 -t 5 $URL; rm -f unpacked; }
394if [[ -e unpacked ]] ; then
395 UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
396 if ! [[ -d $UNPACKDIR ]]; then
397 rm unpacked
398 tar -xvf $BOOTPACKG > unpacked
399 UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
400 fi
401else
402 tar -xvf $BOOTPACKG > unpacked
403 UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
404fi
405cd $UNPACKDIR
406</xsl:text>
407 </xsl:if>
408 <xsl:apply-templates select='.'/>
409 <xsl:if test="preceding-sibling::para[1]/xref[@linkend='bootscripts']">
410 <xsl:text>
411popd</xsl:text>
412 </xsl:if>
413 <xsl:text>&#xA;</xsl:text>
414 </xsl:template>
415
416 <xsl:template match="screen" mode="sect-ver">
417 <xsl:text>section=</xsl:text>
418 <xsl:value-of select="substring-before(substring-after(string(),'mkdir '),' &amp;')"/>
419 <xsl:text>&#xA;sect_ver=</xsl:text>
420 <xsl:value-of select="substring-before(substring-after(string(),'-c ../'),'.md5')"/>
421 <xsl:text>&#xA;</xsl:text>
422 </xsl:template>
423
424 <xsl:template match="para/command">
425 <xsl:if test="(contains(string(),'test') or
426 contains(string(),'check'))">
427 <xsl:text>#</xsl:text>
428 <xsl:value-of select="substring-before(string(),'make')"/>
429 <xsl:text>make -k</xsl:text>
430 <xsl:value-of select="substring-after(string(),'make')"/>
431 <xsl:text> || true&#xA;</xsl:text>
432 </xsl:if>
433 </xsl:template>
434
435 <xsl:template match="userinput">
436 <xsl:apply-templates/>
437 </xsl:template>
438
439 <xsl:template match="replaceable">
440<!-- Not needed anymore
441 <xsl:choose>
442 <xsl:when test="ancestor::sect1[@id='xorg7-server']">
443 <xsl:text>$SRC_DIR/MesaLib</xsl:text>
444 </xsl:when>
445 <xsl:otherwise> -->
446 <xsl:text>**EDITME</xsl:text>
447 <xsl:apply-templates/>
448 <xsl:text>EDITME**</xsl:text>
449<!-- </xsl:otherwise>
450 </xsl:choose> -->
451 </xsl:template>
452
453</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.