source: BLFS/libs/scripts.xsl@ e47edcf

2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since e47edcf was efef736, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

BLFS: Bug fix.

  • Property mode set to 100644
File size: 17.8 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 <!-- 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 <xsl:if test="(count(descendant::screen/userinput) &gt; 0 and
23 count(descendant::screen/userinput) &gt;
24 count(descendant::screen[@role='nodump'])) and
25 @id != 'locale-issues' and @id != 'xorg7' and
26 @id != 'x-setup'">
27
28 <!-- The file names -->
29 <xsl:variable name="filename" select="@id"/>
30
31 <!-- Package name (use "Download FTP" by default. If empty, use "Download HTTP" -->
32 <xsl:variable name="package">
33 <xsl:choose>
34 <xsl:when
35 test="string-length(sect2[@role='package']/itemizedlist/listitem[2]/para/ulink/@url)
36 &gt; '10'">
37 <xsl:call-template name="package_name">
38 <xsl:with-param name="url"
39 select="sect2[@role='package']/itemizedlist/listitem[2]/para/ulink/@url"/>
40 </xsl:call-template>
41 </xsl:when>
42 <xsl:otherwise>
43 <xsl:call-template name="package_name">
44 <xsl:with-param name="url"
45 select="sect2[@role='package']/itemizedlist/listitem[1]/para/ulink/@url"/>
46 </xsl:call-template>
47 </xsl:otherwise>
48 </xsl:choose>
49 </xsl:variable>
50
51 <!-- FTP dir name -->
52 <xsl:variable name="ftpdir">
53 <xsl:call-template name="ftp_dir">
54 <xsl:with-param name="package" select="$package"/>
55 </xsl:call-template>
56 </xsl:variable>
57
58 <!-- The build order -->
59 <xsl:variable name="position" select="position()"/>
60 <xsl:variable name="order">
61 <xsl:choose>
62 <xsl:when test="string-length($position) = 1">
63 <xsl:text>00</xsl:text>
64 <xsl:value-of select="$position"/>
65 </xsl:when>
66 <xsl:when test="string-length($position) = 2">
67 <xsl:text>0</xsl:text>
68 <xsl:value-of select="$position"/>
69 </xsl:when>
70 <xsl:otherwise>
71 <xsl:value-of select="$position"/>
72 </xsl:otherwise>
73 </xsl:choose>
74 </xsl:variable>
75
76 <!-- Depuration code -->
77 <xsl:message>
78 <xsl:text>SCRIPT is </xsl:text>
79 <xsl:value-of select="concat($order,'-',$filename)"/>
80 <xsl:text>&#xA; PACKAGE is </xsl:text>
81 <xsl:value-of select="$package"/>
82 <xsl:text>&#xA; FTPDIR is </xsl:text>
83 <xsl:value-of select="$ftpdir"/>
84 <xsl:text>&#xA;&#xA;</xsl:text>
85 </xsl:message>
86
87 <!-- Creating the scripts -->
88 <exsl:document href="{$order}-z-{$filename}" method="text">
89 <xsl:text>#!/bin/bash&#xA;set -e&#xA;&#xA;</xsl:text>
90 <xsl:choose>
91 <!-- Package page -->
92 <xsl:when test="sect2[@role='package'] and not(@id = 'xorg7-app' or
93 @id = 'xorg7-data' or @id = 'xorg7-driver' or
94 @id = 'xorg7-font' or @id = 'xorg7-lib' or
95 @id = 'xorg7-proto' or @id = 'xorg7-util')">
96 <!-- Variables -->
97 <xsl:text>SRC_ARCHIVE=$SRC_ARCHIVE&#xA;</xsl:text>
98 <xsl:text>FTP_SERVER=$FTP_SERVER&#xA;&#xA;PACKAGE=</xsl:text>
99 <xsl:value-of select="$package"/>
100 <xsl:text>&#xA;PKG_DIR=</xsl:text>
101 <xsl:value-of select="$ftpdir"/>
102 <xsl:text>&#xA;SRC_DIR=$SRC_DIR&#xA;&#xA;</xsl:text>
103 <!-- Download code and build commands -->
104 <xsl:apply-templates select="sect2">
105 <xsl:with-param name="package" select="$package"/>
106 <xsl:with-param name="ftpdir" select="$ftpdir"/>
107 </xsl:apply-templates>
108 <!-- Clean-up -->
109 <xsl:if test="not(@id='mesalib')">
110 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
111 <xsl:text>rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
112 </xsl:if>
113 <xsl:if test="@id='xorg7-server'">
114 <xsl:text>cd $SRC_DIR/MesaLib
115UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
116rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
117 </xsl:if>
118 </xsl:when>
119 <!-- Xorg7 pseudo-packages -->
120 <xsl:when test="contains(@id,'xorg7') and not(@id = 'xorg7-server')">
121 <xsl:text>SRC_DIR=$SRC_DIR
122
123cd $SRC_DIR
124mkdir -p xc
125cd xc&#xA;</xsl:text>
126 <xsl:apply-templates select="sect2" mode="xorg7"/>
127 </xsl:when>
128 <!-- Non-package page -->
129 <xsl:otherwise>
130 <xsl:apply-templates select=".//screen"/>
131 </xsl:otherwise>
132 </xsl:choose>
133 <xsl:text>exit</xsl:text>
134 </exsl:document>
135
136 </xsl:if>
137 </xsl:template>
138
139<!--======================= Sub-sections code =======================-->
140
141 <xsl:template match="sect2">
142 <xsl:param name="package" select="foo"/>
143 <xsl:param name="ftpdir" select="foo"/>
144 <xsl:choose>
145 <xsl:when test="@role = 'package'">
146 <xsl:text>mkdir -p $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
147 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
148 <xsl:apply-templates select="itemizedlist/listitem/para">
149 <xsl:with-param name="package" select="$package"/>
150 <xsl:with-param name="ftpdir" select="$ftpdir"/>
151 </xsl:apply-templates>
152 <xsl:text>&#xA;</xsl:text>
153 </xsl:when>
154 <xsl:when test="@role = 'installation'">
155 <xsl:text>
156if [[ -e unpacked ]] ; then
157 UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
158 [[ -n $UNPACKDIR ]] &amp;&amp; [[ -d $UNPACKDIR ]] &amp;&amp; rm -rf $UNPACKDIR
159fi
160tar -xvf $PACKAGE > unpacked
161UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
162cd $UNPACKDIR&#xA;</xsl:text>
163 <xsl:apply-templates select=".//screen | .//para/command"/>
164 <xsl:if test="$sudo = 'y'">
165 <xsl:text>sudo /sbin/</xsl:text>
166 </xsl:if>
167 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
168 </xsl:when>
169 <xsl:when test="@role = 'configuration'">
170 <xsl:apply-templates select=".//screen"/>
171 <xsl:text>&#xA;</xsl:text>
172 </xsl:when>
173 </xsl:choose>
174 </xsl:template>
175
176 <xsl:template match="sect2" mode="xorg7">
177 <xsl:choose>
178 <xsl:when test="@role = 'package'">
179 <xsl:apply-templates select="itemizedlist/listitem/para" mode="xorg7"/>
180 </xsl:when>
181 <xsl:when test="not(@role)">
182 <xsl:text>SRC_ARCHIVE=$SRC_ARCHIVE
183FTP_SERVER=$FTP_SERVER&#xA;</xsl:text>
184 <xsl:apply-templates select=".//screen" mode="sect-ver"/>
185 <xsl:text>mkdir -p ${section}&#xA;cd ${section}&#xA;</xsl:text>
186 <xsl:apply-templates select="../sect2[@role='package']/itemizedlist/listitem/para" mode="xorg7-patch"/>
187 <xsl:text>for line in $(grep -v '^#' ../${sect_ver}.wget) ; do
188 if [[ ! -f ${line} ]] ; then
189 if [[ -f $SRC_ARCHIVE/Xorg/${section}/${line} ]] ; then
190 cp $SRC_ARCHIVE/Xorg/${section}/${line} ${line}
191 elif [[ -f $SRC_ARCHIVE/Xorg/${line} ]] ; then
192 cp $SRC_ARCHIVE/Xorg/${line} ${line}
193 elif [[ -f $SRC_ARCHIVE/${section}/${line} ]] ; then
194 cp $SRC_ARCHIVE/${section}/${line} ${line}
195 elif [[ -f $SRC_ARCHIVE/${line} ]] ; then
196 cp $SRC_ARCHIVE/${line} ${line}
197 else
198 wget ${FTP_SERVER}conglomeration/Xorg/${line} || \
199 wget http://xorg.freedesktop.org/releases/individual/${section}/${line}
200 fi
201 fi
202done
203md5sum -c ../${sect_ver}.md5
204cp ../${sect_ver}.wget ../${sect_ver}.wget.orig
205cp ../${sect_ver}.md5 ../${sect_ver}.md5.orig&#xA;</xsl:text>
206 </xsl:when>
207 <xsl:when test="@role = 'installation'">
208 <xsl:text>for package in $(grep -v '^#' ../${sect_ver}.wget) ; do
209 packagedir=$(echo $package | sed 's/.tar.bz2//')
210 tar -xf ${package}
211 cd ${packagedir}&#xA;</xsl:text>
212 <xsl:apply-templates select=".//screen | .//para/command"/>
213 <xsl:text> cd ..
214 rm -rf ${packagedir}
215 sed -i "/${package}/d" ../${sect_ver}.wget
216 sed -i "/${package}/d" ../${sect_ver}.md5
217done
218mv ../${sect_ver}.wget.orig ../${sect_ver}.wget
219mv ../${sect_ver}.md5.orig ../${sect_ver}.md5&#xA;</xsl:text>
220 <xsl:if test="$sudo = 'y'">
221 <xsl:text>sudo /sbin/</xsl:text>
222 </xsl:if>
223 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
224 </xsl:when>
225 <xsl:when test="@role = 'configuration'">
226 <xsl:apply-templates select=".//screen"/>
227 <xsl:text>&#xA;</xsl:text>
228 </xsl:when>
229 </xsl:choose>
230 </xsl:template>
231
232<!--==================== Download code =======================-->
233
234 <xsl:template name="package_name">
235 <xsl:param name="url" select="foo"/>
236 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
237 <xsl:choose>
238 <xsl:when test="contains($sub-url,'/')">
239 <xsl:call-template name="package_name">
240 <xsl:with-param name="url" select="$sub-url"/>
241 </xsl:call-template>
242 </xsl:when>
243 <xsl:otherwise>
244 <xsl:choose>
245 <xsl:when test="contains($sub-url,'?')">
246 <xsl:value-of select="substring-before($sub-url,'?')"/>
247 </xsl:when>
248 <xsl:when test="contains($sub-url,'.patch')"/>
249 <xsl:otherwise>
250 <xsl:value-of select="$sub-url"/>
251 </xsl:otherwise>
252 </xsl:choose>
253 </xsl:otherwise>
254 </xsl:choose>
255 </xsl:template>
256
257 <xsl:template name="ftp_dir">
258 <xsl:param name="package" select="foo"/>
259 <!-- A lot of hardcoded dir names. Not full revised yet. -->
260 <xsl:choose>
261 <!-- cdparanoia -->
262 <xsl:when test="contains($package, '-III')">
263 <xsl:text>cdparanoia</xsl:text>
264 </xsl:when>
265 <!-- DobBook 3.1 -->
266 <xsl:when test="contains($package, 'docbk31')">
267 <xsl:text>docbk</xsl:text>
268 </xsl:when>
269 <!-- gc -->
270 <xsl:when test="contains($package, 'gc6')">
271 <xsl:text>gc</xsl:text>
272 </xsl:when>
273 <!-- ISO-codes -->
274 <xsl:when test="contains($package, 'iso-codes')">
275 <xsl:text>iso-codes</xsl:text>
276 </xsl:when>
277 <!-- JPEG -->
278 <xsl:when test="contains($package, 'jpegsrc')">
279 <xsl:text>jpeg</xsl:text>
280 </xsl:when>
281 <!-- lynx -->
282 <xsl:when test="contains($package, 'lynx')">
283 <xsl:text>lynx</xsl:text>
284 </xsl:when>
285 <!-- ntp -->
286 <xsl:when test="contains($package, 'ntp')">
287 <xsl:text>ntp</xsl:text>
288 </xsl:when>
289 <!-- OpenLDAP -->
290 <xsl:when test="contains($package, 'openldap')">
291 <xsl:text>openldap</xsl:text>
292 </xsl:when>
293 <!-- Open Office -->
294 <xsl:when test="contains($package, 'OOo')">
295 <xsl:text>OOo</xsl:text>
296 </xsl:when>
297 <!-- pine -->
298 <xsl:when test="contains($package, 'pine')">
299 <xsl:text>pine</xsl:text>
300 </xsl:when>
301 <!-- portmap -->
302 <xsl:when test="contains($package, 'portmap')">
303 <xsl:text>portmap</xsl:text>
304 </xsl:when>
305 <!-- psutils -->
306 <xsl:when test="contains($package, 'psutils')">
307 <xsl:text>psutils</xsl:text>
308 </xsl:when>
309 <!-- qpopper -->
310 <xsl:when test="contains($package, 'qpopper')">
311 <xsl:text>qpopper</xsl:text>
312 </xsl:when>
313 <!-- QT -->
314 <xsl:when test="contains($package, 'qt-x')">
315 <xsl:text>qt-x11-free</xsl:text>
316 </xsl:when>
317 <!-- sendmail -->
318 <xsl:when test="contains($package, 'sendmail')">
319 <xsl:text>sendmail</xsl:text>
320 </xsl:when>
321 <!-- Slib -->
322 <xsl:when test="contains($package, 'slib')">
323 <xsl:text>slib</xsl:text>
324 </xsl:when>
325 <!-- TCL -->
326 <xsl:when test="contains($package, 'tcl')">
327 <xsl:text>tcl</xsl:text>
328 </xsl:when>
329 <!-- tcpwrappers -->
330 <xsl:when test="contains($package, 'tcp_wrappers')">
331 <xsl:text>tcp_wrappers</xsl:text>
332 </xsl:when>
333 <!-- TeTeX -->
334 <xsl:when test="contains($package, 'tetex')">
335 <xsl:text>tetex</xsl:text>
336 </xsl:when>
337 <!-- Tidy -->
338 <xsl:when test="contains($package, 'tidy')">
339 <xsl:text>tidy</xsl:text>
340 </xsl:when>
341 <!-- Tk -->
342 <xsl:when test="contains($package, 'tk8')">
343 <xsl:text>tk</xsl:text>
344 </xsl:when>
345 <!-- unzip -->
346 <xsl:when test="contains($package, 'unzip')">
347 <xsl:text>unzip</xsl:text>
348 </xsl:when>
349 <!-- wireless_tools -->
350 <xsl:when test="contains($package, 'wireless_tools')">
351 <xsl:text>wireless_tools</xsl:text>
352 </xsl:when>
353 <!-- whois -->
354 <xsl:when test="contains($package, 'whois')">
355 <xsl:text>whois</xsl:text>
356 </xsl:when>
357 <!-- XOrg -->
358 <xsl:when test="contains($package, 'X11R6')">
359 <xsl:text>Xorg</xsl:text>
360 </xsl:when>
361 <!-- zip -->
362 <xsl:when test="contains($package, 'zip2')">
363 <xsl:text>zip</xsl:text>
364 </xsl:when>
365 <!-- General rule -->
366 <xsl:otherwise>
367 <xsl:variable name="cut"
368 select="translate(substring-after($package, '-'), '0123456789', '0000000000')"/>
369 <xsl:variable name="package2">
370 <xsl:value-of select="substring-before($package, '-')"/>
371 <xsl:text>-</xsl:text>
372 <xsl:value-of select="$cut"/>
373 </xsl:variable>
374 <xsl:value-of select="substring-before($package2, '-0')"/>
375 </xsl:otherwise>
376 </xsl:choose>
377 </xsl:template>
378
379 <xsl:template match="itemizedlist/listitem/para">
380 <xsl:param name="package" select="foo"/>
381 <xsl:param name="ftpdir" select="foo"/>
382 <xsl:choose>
383 <!-- This depend on all package pages having both "Download HTTP" and "Download FTP" lines -->
384 <xsl:when test="contains(string(),'HTTP')">
385 <xsl:text>if [[ ! -f $PACKAGE ]] ; then&#xA;</xsl:text>
386 <!-- SRC_ARCHIVE may have subdirectories or not -->
387 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$PACKAGE ]] ; then&#xA;</xsl:text>
388 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$PACKAGE $PACKAGE&#xA;</xsl:text>
389 <xsl:text> elif [[ -f $SRC_ARCHIVE/$PACKAGE ]] ; then&#xA;</xsl:text>
390 <xsl:text> cp $SRC_ARCHIVE/$PACKAGE $PACKAGE&#xA; else&#xA;</xsl:text>
391 <!-- The FTP_SERVER mirror -->
392 <xsl:text> wget ${FTP_SERVER}conglomeration/$PKG_DIR/$PACKAGE</xsl:text>
393 <!-- Upstream HTTP URL -->
394 <xsl:if test="string-length(ulink/@url) &gt; '10'">
395 <xsl:text> || \&#xA; wget </xsl:text>
396 <xsl:choose>
397 <xsl:when test="contains(ulink/@url,'?')">
398 <xsl:value-of select="substring-before(ulink/@url,'?')"/>
399 </xsl:when>
400 <xsl:otherwise>
401 <xsl:value-of select="ulink/@url"/>
402 </xsl:otherwise>
403 </xsl:choose>
404 </xsl:if>
405 </xsl:when>
406 <xsl:when test="contains(string(),'FTP')">
407 <!-- Upstream FTP URL -->
408 <xsl:if test="string-length(ulink/@url) &gt; '10'">
409 <xsl:text> || \&#xA; wget </xsl:text>
410 <xsl:value-of select="ulink/@url"/>
411 </xsl:if>
412 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
413 </xsl:when>
414 <xsl:when test="contains(string(),'MD5')">
415 <xsl:text>echo "</xsl:text>
416 <xsl:value-of select="substring-after(string(),'sum: ')"/>
417 <xsl:text>&#x20;&#x20;$PACKAGE" | md5sum -c -&#xA;</xsl:text>
418 </xsl:when>
419 <!-- Patches -->
420 <xsl:when test="contains(string(ulink/@url),'.patch')">
421 <xsl:text>wget </xsl:text>
422 <xsl:value-of select="ulink/@url"/>
423 <xsl:text>&#xA;</xsl:text>
424 </xsl:when>
425 </xsl:choose>
426 </xsl:template>
427
428 <xsl:template match="itemizedlist/listitem/para" mode="xorg7">
429 <xsl:if test="contains(string(ulink/@url),'.md5') or
430 contains(string(ulink/@url),'.wget')">
431 <xsl:text>wget </xsl:text>
432 <xsl:value-of select="ulink/@url"/>
433 <xsl:text>&#xA;</xsl:text>
434 </xsl:if>
435 </xsl:template>
436
437 <xsl:template match="itemizedlist/listitem/para" mode="xorg7-patch">
438 <xsl:if test="contains(string(ulink/@url),'.patch')">
439 <xsl:text>wget </xsl:text>
440 <xsl:value-of select="ulink/@url"/>
441 <xsl:text>&#xA;</xsl:text>
442 </xsl:if>
443 </xsl:template>
444
445<!--======================== Commands code ==========================-->
446
447 <xsl:template match="screen">
448 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
449 <xsl:if test="@role = 'root' and $sudo = 'y'">
450 <xsl:text>sudo sh -c '</xsl:text>
451 </xsl:if>
452 <xsl:apply-templates select="userinput"/>
453 <xsl:if test="@role = 'root' and $sudo = 'y'">
454 <xsl:text>'</xsl:text>
455 </xsl:if>
456 <xsl:text>&#xA;</xsl:text>
457 </xsl:if>
458 </xsl:template>
459
460 <xsl:template match="screen" mode="sect-ver">
461 <xsl:text>section=</xsl:text>
462 <xsl:value-of select="substring-before(substring-after(string(),'mkdir '),' &amp;')"/>
463 <xsl:text>&#xA;sect_ver=</xsl:text>
464 <xsl:value-of select="substring-before(substring-after(string(),'-c ../'),'.md5')"/>
465 <xsl:text>&#xA;</xsl:text>
466 </xsl:template>
467
468 <xsl:template match="para/command">
469 <xsl:if test="(contains(string(),'test') or
470 contains(string(),'check'))">
471 <xsl:text>#</xsl:text>
472 <xsl:value-of select="substring-before(string(),'make')"/>
473 <xsl:text>make -k</xsl:text>
474 <xsl:value-of select="substring-after(string(),'make')"/>
475 <xsl:text> || true&#xA;</xsl:text>
476 </xsl:if>
477 </xsl:template>
478
479 <xsl:template match="userinput">
480 <xsl:apply-templates/>
481 </xsl:template>
482
483 <xsl:template match="replaceable">
484 <xsl:choose>
485 <xsl:when test="ancestor::sect1[@id='xorg7-server']">
486 <xsl:text>$SRC_DIR/MesaLib</xsl:text>
487 </xsl:when>
488 <xsl:otherwise>
489 <xsl:text>**EDITME</xsl:text>
490 <xsl:apply-templates/>
491 <xsl:text>EDITME**</xsl:text>
492 </xsl:otherwise>
493 </xsl:choose>
494 </xsl:template>
495
496</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.