source: BLFS/libs/scripts.xsl@ 8b7df52

experimental
Last change on this file since 8b7df52 was e5612bb, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Merged r2964:2965 from trunk.

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