source: BLFS/libs/scripts.xsl@ 44994cb

experimental
Last change on this file since 44994cb 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
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:param 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: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
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/sh&#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:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
110 <xsl:text>rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
111 </xsl:when>
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>
121 <!-- Non-package page -->
122 <xsl:otherwise>
123 <xsl:apply-templates select=".//screen"/>
124 </xsl:otherwise>
125 </xsl:choose>
126 <xsl:text>exit</xsl:text>
127 </exsl:document>
128
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'">
139 <xsl:text>mkdir -p $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
140 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
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'">
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@/.*@@'`
155cd $UNPACKDIR&#xA;</xsl:text>
156 <xsl:apply-templates select=".//screen | .//para/command"/>
157 <xsl:if test="$sudo = 'y'">
158 <xsl:text>sudo </xsl:text>
159 </xsl:if>
160 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
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
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
197<!--==================== Download code =======================-->
198
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>
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 name="ftp_dir">
223 <xsl:param name="package" select="foo"/>
224 <!-- A lot of hardcoded dir names. Not full revised yet. -->
225 <xsl:choose>
226 <!-- cdparanoia -->
227 <xsl:when test="contains($package, '-III')">
228 <xsl:text>cdparanoia</xsl:text>
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>
257 </xsl:when>
258 <!-- Open Office -->
259 <xsl:when test="contains($package, 'OOo')">
260 <xsl:text>OOo</xsl:text>
261 </xsl:when>
262 <!-- pine -->
263 <xsl:when test="contains($package, 'pine')">
264 <xsl:text>pine</xsl:text>
265 </xsl:when>
266 <!-- portmap -->
267 <xsl:when test="contains($package, 'portmap')">
268 <xsl:text>portmap</xsl:text>
269 </xsl:when>
270 <!-- psutils -->
271 <xsl:when test="contains($package, 'psutils')">
272 <xsl:text>psutils</xsl:text>
273 </xsl:when>
274 <!-- qpopper -->
275 <xsl:when test="contains($package, 'qpopper')">
276 <xsl:text>qpopper</xsl:text>
277 </xsl:when>
278 <!-- QT -->
279 <xsl:when test="contains($package, 'qt-x')">
280 <xsl:text>qt-x11-free</xsl:text>
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 -->
307 <xsl:when test="contains($package, 'tk8')">
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>
321 </xsl:when>
322 <!-- XOrg -->
323 <xsl:when test="contains($package, 'X11R6')">
324 <xsl:text>Xorg</xsl:text>
325 </xsl:when>
326 <!-- zip -->
327 <xsl:when test="contains($package, 'zip2')">
328 <xsl:text>zip</xsl:text>
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>
342 </xsl:template>
343
344 <xsl:template match="itemizedlist/listitem/para">
345 <xsl:param name="package" select="foo"/>
346 <xsl:param name="ftpdir" select="foo"/>
347 <xsl:choose>
348 <!-- This depend on all package pages having both "Download HTTP" and "Download FTP" lines -->
349 <xsl:when test="contains(string(),'HTTP')">
350 <xsl:text>if [[ ! -f $PACKAGE ]] ; then&#xA;</xsl:text>
351 <!-- SRC_ARCHIVE may have subdirectories or not -->
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>
356 <!-- The FTP_SERVER mirror -->
357 <xsl:text> wget ${FTP_SERVER}conglomeration/$PKG_DIR/$PACKAGE</xsl:text>
358 <!-- Upstream HTTP URL -->
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>
362 <xsl:value-of select="ulink/@url"/>
363 </xsl:if>
364 </xsl:when>
365 <xsl:when test="contains(string(),'FTP')">
366 <!-- Upstream FTP URL -->
367 <xsl:if test="string-length(ulink/@url) &gt; '10'">
368 <xsl:text> || \&#xA; wget </xsl:text>
369 <xsl:value-of select="ulink/@url"/>
370 </xsl:if>
371 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
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: ')"/>
376 <xsl:text>&#x20;&#x20;$PACKAGE" | md5sum -c -&#xA;</xsl:text>
377 </xsl:when>
378 <!-- Patches -->
379 <xsl:when test="contains(string(ulink/@url),'.patch')">
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
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
395<!--======================== Commands code ==========================-->
396
397 <xsl:template match="screen">
398 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
399 <xsl:if test="@role = 'root' and $sudo = 'y'">
400 <xsl:text>sudo sh -c "</xsl:text>
401 </xsl:if>
402 <xsl:apply-templates select="userinput"/>
403 <xsl:if test="@role = 'root' and $sudo = 'y'">
404 <xsl:text>"</xsl:text>
405 </xsl:if>
406 <xsl:text>&#xA;</xsl:text>
407 </xsl:if>
408 </xsl:template>
409
410 <xsl:template match="screen" mode="wget_lst">
411 <xsl:value-of select="substring-after(string(),' -i ')"/>
412 </xsl:template>
413
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
425 <xsl:template match="userinput">
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.