source: BLFS/libs/scripts.xsl@ 9d158f9

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

Merged r2952,2953,2957 from trunk.

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