source: BLFS/libs/scripts.xsl@ ba72197

experimental
Last change on this file since ba72197 was 7b08c36, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Generating scripts names from ID values instead from HTML pages names.

  • Property mode set to 100644
File size: 15.3 KB
RevLine 
[8aba69a]1<?xml version="1.0"?>
[d6be7ea]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
[3d888ef]10<!-- XSLT stylesheet to create shell scripts from "linear build" BLFS books. -->
[d6be7ea]11
[00f4966]12 <!-- Build as user (y) or as root (n)? -->
13 <xsl:param name="sudo" select="y"/>
14
[d6be7ea]15 <xsl:template match="/">
16 <xsl:apply-templates select="//sect1"/>
17 </xsl:template>
18
19<!--=================== Master chunks code ======================-->
20
21 <xsl:template match="sect1">
[e5612bb]22 <xsl:if test="(count(descendant::screen/userinput) &gt; 0 and
[d6be7ea]23 count(descendant::screen/userinput) &gt;
[e5612bb]24 count(descendant::screen[@role='nodump'])) and
25 @id != 'locale-issues' and @id != 'xorg7' and
26 @id != 'x-setup'">
[3d888ef]27
[d6be7ea]28 <!-- The file names -->
[7b08c36]29 <xsl:variable name="filename" select="@id"/>
[3d888ef]30
[a4ccd54]31 <!-- Package name (use "Download FTP" by default. If empty, use "Download HTTP" -->
[3d888ef]32 <xsl:param name="package">
[a4ccd54]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>
[3d888ef]49 </xsl:param>
50
51 <!-- FTP dir name -->
52 <xsl:param name="ftpdir">
53 <xsl:call-template name="ftp_dir">
54 <xsl:with-param name="package" select="$package"/>
55 </xsl:call-template>
56 </xsl:param>
57
[d6be7ea]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>
[3d888ef]75
[37ac06a]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
[3d888ef]87 <!-- Creating the scripts -->
[d0d9e90]88 <exsl:document href="{$order}-z-{$filename}" method="text">
[d6be7ea]89 <xsl:text>#!/bin/sh&#xA;set -e&#xA;&#xA;</xsl:text>
[838b61a]90 <xsl:choose>
[d3d90e7]91 <!-- Package page -->
[e5612bb]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')">
[d3d90e7]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"/>
[2fedf49]102 <xsl:text>&#xA;SRC_DIR=$SRC_DIR&#xA;&#xA;</xsl:text>
[d3d90e7]103 <!-- Download code and build commands -->
[838b61a]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>
[d3d90e7]108 <!-- Clean-up -->
[2fedf49]109 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
[d0d9e90]110 <xsl:text>rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
[838b61a]111 </xsl:when>
[e5612bb]112 <!-- Xorg7 pseudo-packages -->
113 <xsl:when test="contains(@id,'xorg7') and not(@id = 'xorg7-server')">
114 <xsl:text>SRC_DIR=$SRC_DIR
115
116cd $SRC_DIR
117mkdir -p xc
118cd xc&#xA;</xsl:text>
119 <xsl:apply-templates select="sect2" mode="xorg7"/>
120 </xsl:when>
[d3d90e7]121 <!-- Non-package page -->
[838b61a]122 <xsl:otherwise>
123 <xsl:apply-templates select=".//screen"/>
124 </xsl:otherwise>
125 </xsl:choose>
[d6be7ea]126 <xsl:text>exit</xsl:text>
127 </exsl:document>
[3d888ef]128
[d6be7ea]129 </xsl:if>
130 </xsl:template>
131
132<!--======================= Sub-sections code =======================-->
133
134 <xsl:template match="sect2">
135 <xsl:param name="package" select="foo"/>
136 <xsl:param name="ftpdir" select="foo"/>
137 <xsl:choose>
138 <xsl:when test="@role = 'package'">
[2fedf49]139 <xsl:text>mkdir -p $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
140 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
[d6be7ea]141 <xsl:apply-templates select="itemizedlist/listitem/para">
142 <xsl:with-param name="package" select="$package"/>
143 <xsl:with-param name="ftpdir" select="$ftpdir"/>
144 </xsl:apply-templates>
145 <xsl:text>&#xA;</xsl:text>
146 </xsl:when>
147 <xsl:when test="@role = 'installation'">
[d0d9e90]148 <xsl:text>
149if [[ -e unpacked ]] ; then
150 UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
151 rm -rf $UNPACKDIR
152fi
153tar -xvf $PACKAGE > unpacked
154UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`
[59f096b]155cd $UNPACKDIR&#xA;</xsl:text>
[d6be7ea]156 <xsl:apply-templates select=".//screen | .//para/command"/>
[9d158f9]157 <xsl:if test="$sudo = 'y'">
158 <xsl:text>sudo </xsl:text>
159 </xsl:if>
160 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
[d6be7ea]161 </xsl:when>
162 <xsl:when test="@role = 'configuration'">
163 <xsl:apply-templates select=".//screen"/>
164 <xsl:text>&#xA;</xsl:text>
165 </xsl:when>
166 </xsl:choose>
167 </xsl:template>
168
[e5612bb]169 <xsl:template match="sect2" mode="xorg7">
170 <xsl:choose>
171 <xsl:when test="@role = 'package'"/>
172 <xsl:when test="not(@role)">
173 <xsl:apply-templates select=".//screen"/>
174 <xsl:apply-templates select="../sect2[@role='package']/itemizedlist/listitem/para"
175 mode="xorg7"/>
176 <xsl:text>WGET_LST=</xsl:text>
177 <xsl:apply-templates select=".//screen" mode="wget_lst"/>
178 <xsl:text>&#xA;</xsl:text>
179 </xsl:when>
180 <xsl:when test="@role = 'installation'">
181 <xsl:text>for package in $(cat $WGET_LST) ; do
182 packagedir=$(echo $package | sed 's/.tar.bz2//')
183 tar -xf $package
184 cd $packagedir&#xA;</xsl:text>
185 <xsl:apply-templates select=".//screen | .//para/command"/>
186 <xsl:text> cd ..
187 rm -rf $packagedir
188done&#xA;</xsl:text>
189 <xsl:if test="$sudo = 'y'">
190 <xsl:text>sudo </xsl:text>
191 </xsl:if>
192 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
193 </xsl:when>
194 </xsl:choose>
195 </xsl:template>
196
[d6be7ea]197<!--==================== Download code =======================-->
198
[3d888ef]199 <xsl:template name="package_name">
200 <xsl:param name="url" select="foo"/>
201 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
202 <xsl:choose>
203 <xsl:when test="contains($sub-url,'/')">
204 <xsl:call-template name="package_name">
205 <xsl:with-param name="url" select="$sub-url"/>
206 </xsl:call-template>
207 </xsl:when>
208 <xsl:otherwise>
209 <xsl:choose>
210 <xsl:when test="contains($sub-url,'?')">
211 <xsl:value-of select="substring-before($sub-url,'?')"/>
212 </xsl:when>
[07eac51]213 <xsl:when test="contains($sub-url,'.patch')"/>
[3d888ef]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 name="ftp_dir">
223 <xsl:param name="package" select="foo"/>
[edf7e4c]224 <!-- A lot of hardcoded dir names. Not full revised yet. -->
[37ac06a]225 <xsl:choose>
226 <!-- cdparanoia -->
227 <xsl:when test="contains($package, '-III')">
228 <xsl:text>cdparanoia</xsl:text>
[edf7e4c]229 </xsl:when>
230 <!-- DobBook 3.1 -->
231 <xsl:when test="contains($package, 'docbk31')">
232 <xsl:text>docbk</xsl:text>
233 </xsl:when>
234 <!-- gc -->
235 <xsl:when test="contains($package, 'gc6')">
236 <xsl:text>gc</xsl:text>
237 </xsl:when>
238 <!-- ISO-codes -->
239 <xsl:when test="contains($package, 'iso-codes')">
240 <xsl:text>iso-codes</xsl:text>
241 </xsl:when>
242 <!-- JPEG -->
243 <xsl:when test="contains($package, 'jpegsrc')">
244 <xsl:text>jpeg</xsl:text>
245 </xsl:when>
246 <!-- lynx -->
247 <xsl:when test="contains($package, 'lynx')">
248 <xsl:text>lynx</xsl:text>
249 </xsl:when>
250 <!-- ntp -->
251 <xsl:when test="contains($package, 'ntp')">
252 <xsl:text>ntp</xsl:text>
253 </xsl:when>
254 <!-- OpenLDAP -->
255 <xsl:when test="contains($package, 'openldap')">
256 <xsl:text>openldap</xsl:text>
[37ac06a]257 </xsl:when>
258 <!-- Open Office -->
259 <xsl:when test="contains($package, 'OOo')">
260 <xsl:text>OOo</xsl:text>
261 </xsl:when>
[edf7e4c]262 <!-- pine -->
263 <xsl:when test="contains($package, 'pine')">
264 <xsl:text>pine</xsl:text>
[a4ccd54]265 </xsl:when>
266 <!-- portmap -->
267 <xsl:when test="contains($package, 'portmap')">
268 <xsl:text>portmap</xsl:text>
[edf7e4c]269 </xsl:when>
270 <!-- psutils -->
271 <xsl:when test="contains($package, 'psutils')">
272 <xsl:text>psutils</xsl:text>
[a4ccd54]273 </xsl:when>
274 <!-- qpopper -->
275 <xsl:when test="contains($package, 'qpopper')">
276 <xsl:text>qpopper</xsl:text>
[8aba69a]277 </xsl:when>
278 <!-- QT -->
279 <xsl:when test="contains($package, 'qt-x')">
280 <xsl:text>qt-x11-free</xsl:text>
[edf7e4c]281 </xsl:when>
282 <!-- sendmail -->
283 <xsl:when test="contains($package, 'sendmail')">
284 <xsl:text>sendmail</xsl:text>
285 </xsl:when>
286 <!-- Slib -->
287 <xsl:when test="contains($package, 'slib')">
288 <xsl:text>slib</xsl:text>
289 </xsl:when>
290 <!-- TCL -->
291 <xsl:when test="contains($package, 'tcl')">
292 <xsl:text>tcl</xsl:text>
293 </xsl:when>
294 <!-- tcpwrappers -->
295 <xsl:when test="contains($package, 'tcp_wrappers')">
296 <xsl:text>tcp_wrappers</xsl:text>
297 </xsl:when>
298 <!-- TeTeX -->
299 <xsl:when test="contains($package, 'tetex')">
300 <xsl:text>tetex</xsl:text>
301 </xsl:when>
302 <!-- Tidy -->
303 <xsl:when test="contains($package, 'tidy')">
304 <xsl:text>tidy</xsl:text>
305 </xsl:when>
306 <!-- Tk -->
[8aba69a]307 <xsl:when test="contains($package, 'tk8')">
[edf7e4c]308 <xsl:text>tk</xsl:text>
309 </xsl:when>
310 <!-- unzip -->
311 <xsl:when test="contains($package, 'unzip')">
312 <xsl:text>unzip</xsl:text>
313 </xsl:when>
314 <!-- wireless_tools -->
315 <xsl:when test="contains($package, 'wireless_tools')">
316 <xsl:text>wireless_tools</xsl:text>
317 </xsl:when>
318 <!-- whois -->
319 <xsl:when test="contains($package, 'whois')">
320 <xsl:text>whois</xsl:text>
[37ac06a]321 </xsl:when>
322 <!-- XOrg -->
323 <xsl:when test="contains($package, 'X11R6')">
[edf7e4c]324 <xsl:text>Xorg</xsl:text>
325 </xsl:when>
326 <!-- zip -->
327 <xsl:when test="contains($package, 'zip2')">
328 <xsl:text>zip</xsl:text>
[37ac06a]329 </xsl:when>
330 <!-- General rule -->
331 <xsl:otherwise>
332 <xsl:variable name="cut"
333 select="translate(substring-after($package, '-'), '0123456789', '0000000000')"/>
334 <xsl:variable name="package2">
335 <xsl:value-of select="substring-before($package, '-')"/>
336 <xsl:text>-</xsl:text>
337 <xsl:value-of select="$cut"/>
338 </xsl:variable>
339 <xsl:value-of select="substring-before($package2, '-0')"/>
340 </xsl:otherwise>
341 </xsl:choose>
[3d888ef]342 </xsl:template>
343
[d6be7ea]344 <xsl:template match="itemizedlist/listitem/para">
345 <xsl:param name="package" select="foo"/>
346 <xsl:param name="ftpdir" select="foo"/>
347 <xsl:choose>
[d3d90e7]348 <!-- This depend on all package pages having both "Download HTTP" and "Download FTP" lines -->
[d6be7ea]349 <xsl:when test="contains(string(),'HTTP')">
[d3d90e7]350 <xsl:text>if [[ ! -f $PACKAGE ]] ; then&#xA;</xsl:text>
[6e4e0dd]351 <!-- SRC_ARCHIVE may have subdirectories or not -->
[d3d90e7]352 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$PACKAGE ]] ; then&#xA;</xsl:text>
353 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$PACKAGE $PACKAGE&#xA;</xsl:text>
354 <xsl:text> elif [[ -f $SRC_ARCHIVE/$PACKAGE ]] ; then&#xA;</xsl:text>
355 <xsl:text> cp $SRC_ARCHIVE/$PACKAGE $PACKAGE&#xA; else&#xA;</xsl:text>
[d6be7ea]356 <!-- The FTP_SERVER mirror -->
[d0d9e90]357 <xsl:text> wget ${FTP_SERVER}conglomeration/$PKG_DIR/$PACKAGE</xsl:text>
[d6be7ea]358 <!-- Upstream HTTP URL -->
[40d4ca7]359 <xsl:if test="string-length(ulink/@url) &gt; '10' and
360 not(contains(string(ulink/@url),'sourceforge'))">
361 <xsl:text> || \&#xA; wget </xsl:text>
[a4ccd54]362 <xsl:value-of select="ulink/@url"/>
363 </xsl:if>
[d6be7ea]364 </xsl:when>
365 <xsl:when test="contains(string(),'FTP')">
366 <!-- Upstream FTP URL -->
[a4ccd54]367 <xsl:if test="string-length(ulink/@url) &gt; '10'">
[40d4ca7]368 <xsl:text> || \&#xA; wget </xsl:text>
[a4ccd54]369 <xsl:value-of select="ulink/@url"/>
370 </xsl:if>
[40d4ca7]371 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
[d6be7ea]372 </xsl:when>
373 <xsl:when test="contains(string(),'MD5')">
374 <xsl:text>echo "</xsl:text>
375 <xsl:value-of select="substring-after(string(),'sum: ')"/>
[d3d90e7]376 <xsl:text>&#x20;&#x20;$PACKAGE" | md5sum -c -&#xA;</xsl:text>
[d6be7ea]377 </xsl:when>
[40d4ca7]378 <!-- Patches -->
[e52ffe5]379 <xsl:when test="contains(string(ulink/@url),'.patch')">
[d6be7ea]380 <xsl:text>wget </xsl:text>
381 <xsl:value-of select="ulink/@url"/>
382 <xsl:text>&#xA;</xsl:text>
383 </xsl:when>
384 </xsl:choose>
385 </xsl:template>
386
[e5612bb]387 <xsl:template match="itemizedlist/listitem/para" mode="xorg7">
388 <xsl:if test="contains(string(ulink/@url),'.patch')">
389 <xsl:text>wget </xsl:text>
390 <xsl:value-of select="ulink/@url"/>
391 <xsl:text>&#xA;</xsl:text>
392 </xsl:if>
393 </xsl:template>
394
[d6be7ea]395<!--======================== Commands code ==========================-->
396
397 <xsl:template match="screen">
[1504208]398 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
[00f4966]399 <xsl:if test="@role = 'root' and $sudo = 'y'">
[1504208]400 <xsl:text>sudo sh -c "</xsl:text>
401 </xsl:if>
402 <xsl:apply-templates select="userinput"/>
[00f4966]403 <xsl:if test="@role = 'root' and $sudo = 'y'">
[1504208]404 <xsl:text>"</xsl:text>
405 </xsl:if>
406 <xsl:text>&#xA;</xsl:text>
[d6be7ea]407 </xsl:if>
408 </xsl:template>
409
[e5612bb]410 <xsl:template match="screen" mode="wget_lst">
411 <xsl:value-of select="substring-after(string(),' -i ')"/>
412 </xsl:template>
413
[d6be7ea]414 <xsl:template match="para/command">
415 <xsl:if test="(contains(string(),'test') or
416 contains(string(),'check'))">
417 <xsl:text>#</xsl:text>
418 <xsl:value-of select="substring-before(string(),'make')"/>
419 <xsl:text>make -k</xsl:text>
420 <xsl:value-of select="substring-after(string(),'make')"/>
421 <xsl:text> || true&#xA;</xsl:text>
422 </xsl:if>
423 </xsl:template>
424
[1504208]425 <xsl:template match="userinput">
[d6be7ea]426 <xsl:apply-templates/>
427 </xsl:template>
428
429 <xsl:template match="replaceable">
430 <xsl:text>**EDITME</xsl:text>
431 <xsl:apply-templates/>
432 <xsl:text>EDITME**</xsl:text>
433 </xsl:template>
434
435</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.