source: BLFS/libs/scripts.xsl@ b928382

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

Merged r2942:2948 from trunk.

  • Property mode set to 100644
File size: 13.5 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">
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']))">
[3d888ef]26
[d6be7ea]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')"/>
[3d888ef]31
[a4ccd54]32 <!-- Package name (use "Download FTP" by default. If empty, use "Download HTTP" -->
[3d888ef]33 <xsl:param name="package">
[a4ccd54]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>
[3d888ef]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
[d6be7ea]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>
[3d888ef]76
[37ac06a]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
[3d888ef]88 <!-- Creating the scripts -->
[d0d9e90]89 <exsl:document href="{$order}-z-{$filename}" method="text">
[d6be7ea]90 <xsl:text>#!/bin/sh&#xA;set -e&#xA;&#xA;</xsl:text>
[838b61a]91 <xsl:choose>
[d3d90e7]92 <!-- Package page -->
[838b61a]93 <xsl:when test="sect2[@role='package']">
[d3d90e7]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"/>
[2fedf49]100 <xsl:text>&#xA;SRC_DIR=$SRC_DIR&#xA;&#xA;</xsl:text>
[d3d90e7]101 <!-- Download code and build commands -->
[838b61a]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>
[d3d90e7]106 <!-- Clean-up -->
[2fedf49]107 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
[d0d9e90]108 <xsl:text>rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
[838b61a]109 </xsl:when>
[d3d90e7]110 <!-- Non-package page -->
[838b61a]111 <xsl:otherwise>
112 <xsl:apply-templates select=".//screen"/>
113 </xsl:otherwise>
114 </xsl:choose>
[d6be7ea]115 <xsl:text>exit</xsl:text>
116 </exsl:document>
[3d888ef]117
[d6be7ea]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'">
[2fedf49]128 <xsl:text>mkdir -p $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
129 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
[d6be7ea]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'">
[d0d9e90]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>
[d6be7ea]146 <xsl:apply-templates select=".//screen | .//para/command"/>
147 <xsl:text>&#xA;</xsl:text>
148 </xsl:when>
149 <xsl:when test="@role = 'configuration'">
150 <xsl:apply-templates select=".//screen"/>
151 <xsl:text>&#xA;</xsl:text>
152 </xsl:when>
153 </xsl:choose>
154 </xsl:template>
155
156<!--==================== Download code =======================-->
157
[3d888ef]158 <xsl:template name="package_name">
159 <xsl:param name="url" select="foo"/>
160 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
161 <xsl:choose>
162 <xsl:when test="contains($sub-url,'/')">
163 <xsl:call-template name="package_name">
164 <xsl:with-param name="url" select="$sub-url"/>
165 </xsl:call-template>
166 </xsl:when>
167 <xsl:otherwise>
168 <xsl:choose>
169 <xsl:when test="contains($sub-url,'?')">
170 <xsl:value-of select="substring-before($sub-url,'?')"/>
171 </xsl:when>
[07eac51]172 <xsl:when test="contains($sub-url,'.patch')"/>
[3d888ef]173 <xsl:otherwise>
174 <xsl:value-of select="$sub-url"/>
175 </xsl:otherwise>
176 </xsl:choose>
177 </xsl:otherwise>
178 </xsl:choose>
179 </xsl:template>
180
181 <xsl:template name="ftp_dir">
182 <xsl:param name="package" select="foo"/>
[edf7e4c]183 <!-- A lot of hardcoded dir names. Not full revised yet. -->
[37ac06a]184 <xsl:choose>
185 <!-- cdparanoia -->
186 <xsl:when test="contains($package, '-III')">
187 <xsl:text>cdparanoia</xsl:text>
[edf7e4c]188 </xsl:when>
189 <!-- DobBook 3.1 -->
190 <xsl:when test="contains($package, 'docbk31')">
191 <xsl:text>docbk</xsl:text>
192 </xsl:when>
193 <!-- gc -->
194 <xsl:when test="contains($package, 'gc6')">
195 <xsl:text>gc</xsl:text>
196 </xsl:when>
197 <!-- ISO-codes -->
198 <xsl:when test="contains($package, 'iso-codes')">
199 <xsl:text>iso-codes</xsl:text>
200 </xsl:when>
201 <!-- JPEG -->
202 <xsl:when test="contains($package, 'jpegsrc')">
203 <xsl:text>jpeg</xsl:text>
204 </xsl:when>
205 <!-- lynx -->
206 <xsl:when test="contains($package, 'lynx')">
207 <xsl:text>lynx</xsl:text>
208 </xsl:when>
209 <!-- ntp -->
210 <xsl:when test="contains($package, 'ntp')">
211 <xsl:text>ntp</xsl:text>
212 </xsl:when>
213 <!-- OpenLDAP -->
214 <xsl:when test="contains($package, 'openldap')">
215 <xsl:text>openldap</xsl:text>
[37ac06a]216 </xsl:when>
217 <!-- Open Office -->
218 <xsl:when test="contains($package, 'OOo')">
219 <xsl:text>OOo</xsl:text>
220 </xsl:when>
[edf7e4c]221 <!-- pine -->
222 <xsl:when test="contains($package, 'pine')">
223 <xsl:text>pine</xsl:text>
[a4ccd54]224 </xsl:when>
225 <!-- portmap -->
226 <xsl:when test="contains($package, 'portmap')">
227 <xsl:text>portmap</xsl:text>
[edf7e4c]228 </xsl:when>
229 <!-- psutils -->
230 <xsl:when test="contains($package, 'psutils')">
231 <xsl:text>psutils</xsl:text>
[a4ccd54]232 </xsl:when>
233 <!-- qpopper -->
234 <xsl:when test="contains($package, 'qpopper')">
235 <xsl:text>qpopper</xsl:text>
[8aba69a]236 </xsl:when>
237 <!-- QT -->
238 <xsl:when test="contains($package, 'qt-x')">
239 <xsl:text>qt-x11-free</xsl:text>
[edf7e4c]240 </xsl:when>
241 <!-- sendmail -->
242 <xsl:when test="contains($package, 'sendmail')">
243 <xsl:text>sendmail</xsl:text>
244 </xsl:when>
245 <!-- Slib -->
246 <xsl:when test="contains($package, 'slib')">
247 <xsl:text>slib</xsl:text>
248 </xsl:when>
249 <!-- TCL -->
250 <xsl:when test="contains($package, 'tcl')">
251 <xsl:text>tcl</xsl:text>
252 </xsl:when>
253 <!-- tcpwrappers -->
254 <xsl:when test="contains($package, 'tcp_wrappers')">
255 <xsl:text>tcp_wrappers</xsl:text>
256 </xsl:when>
257 <!-- TeTeX -->
258 <xsl:when test="contains($package, 'tetex')">
259 <xsl:text>tetex</xsl:text>
260 </xsl:when>
261 <!-- Tidy -->
262 <xsl:when test="contains($package, 'tidy')">
263 <xsl:text>tidy</xsl:text>
264 </xsl:when>
265 <!-- Tk -->
[8aba69a]266 <xsl:when test="contains($package, 'tk8')">
[edf7e4c]267 <xsl:text>tk</xsl:text>
268 </xsl:when>
269 <!-- unzip -->
270 <xsl:when test="contains($package, 'unzip')">
271 <xsl:text>unzip</xsl:text>
272 </xsl:when>
273 <!-- wireless_tools -->
274 <xsl:when test="contains($package, 'wireless_tools')">
275 <xsl:text>wireless_tools</xsl:text>
276 </xsl:when>
277 <!-- whois -->
278 <xsl:when test="contains($package, 'whois')">
279 <xsl:text>whois</xsl:text>
[37ac06a]280 </xsl:when>
281 <!-- XOrg -->
282 <xsl:when test="contains($package, 'X11R6')">
[edf7e4c]283 <xsl:text>Xorg</xsl:text>
284 </xsl:when>
285 <!-- zip -->
286 <xsl:when test="contains($package, 'zip2')">
287 <xsl:text>zip</xsl:text>
[37ac06a]288 </xsl:when>
289 <!-- General rule -->
290 <xsl:otherwise>
291 <xsl:variable name="cut"
292 select="translate(substring-after($package, '-'), '0123456789', '0000000000')"/>
293 <xsl:variable name="package2">
294 <xsl:value-of select="substring-before($package, '-')"/>
295 <xsl:text>-</xsl:text>
296 <xsl:value-of select="$cut"/>
297 </xsl:variable>
298 <xsl:value-of select="substring-before($package2, '-0')"/>
299 </xsl:otherwise>
300 </xsl:choose>
[3d888ef]301 </xsl:template>
302
[d6be7ea]303 <xsl:template match="itemizedlist/listitem/para">
304 <xsl:param name="package" select="foo"/>
305 <xsl:param name="ftpdir" select="foo"/>
306 <xsl:choose>
[d3d90e7]307 <!-- This depend on all package pages having both "Download HTTP" and "Download FTP" lines -->
[d6be7ea]308 <xsl:when test="contains(string(),'HTTP')">
[d3d90e7]309 <xsl:text>if [[ ! -f $PACKAGE ]] ; then&#xA;</xsl:text>
[6e4e0dd]310 <!-- SRC_ARCHIVE may have subdirectories or not -->
[d3d90e7]311 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$PACKAGE ]] ; then&#xA;</xsl:text>
312 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$PACKAGE $PACKAGE&#xA;</xsl:text>
313 <xsl:text> elif [[ -f $SRC_ARCHIVE/$PACKAGE ]] ; then&#xA;</xsl:text>
314 <xsl:text> cp $SRC_ARCHIVE/$PACKAGE $PACKAGE&#xA; else&#xA;</xsl:text>
[d6be7ea]315 <!-- The FTP_SERVER mirror -->
[d0d9e90]316 <xsl:text> wget ${FTP_SERVER}conglomeration/$PKG_DIR/$PACKAGE</xsl:text>
[d6be7ea]317 <!-- Upstream HTTP URL -->
[40d4ca7]318 <xsl:if test="string-length(ulink/@url) &gt; '10' and
319 not(contains(string(ulink/@url),'sourceforge'))">
320 <xsl:text> || \&#xA; wget </xsl:text>
[a4ccd54]321 <xsl:value-of select="ulink/@url"/>
322 </xsl:if>
[d6be7ea]323 </xsl:when>
324 <xsl:when test="contains(string(),'FTP')">
325 <!-- Upstream FTP URL -->
[a4ccd54]326 <xsl:if test="string-length(ulink/@url) &gt; '10'">
[40d4ca7]327 <xsl:text> || \&#xA; wget </xsl:text>
[a4ccd54]328 <xsl:value-of select="ulink/@url"/>
329 </xsl:if>
[40d4ca7]330 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
[d6be7ea]331 </xsl:when>
332 <xsl:when test="contains(string(),'MD5')">
333 <xsl:text>echo "</xsl:text>
334 <xsl:value-of select="substring-after(string(),'sum: ')"/>
[d3d90e7]335 <xsl:text>&#x20;&#x20;$PACKAGE" | md5sum -c -&#xA;</xsl:text>
[d6be7ea]336 </xsl:when>
[40d4ca7]337 <!-- Patches -->
[e52ffe5]338 <xsl:when test="contains(string(ulink/@url),'.patch')">
[d6be7ea]339 <xsl:text>wget </xsl:text>
340 <xsl:value-of select="ulink/@url"/>
341 <xsl:text>&#xA;</xsl:text>
342 </xsl:when>
343 </xsl:choose>
344 </xsl:template>
345
346<!--======================== Commands code ==========================-->
347
348 <xsl:template match="screen">
[1504208]349 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
[00f4966]350 <xsl:if test="@role = 'root' and $sudo = 'y'">
[1504208]351 <xsl:text>sudo sh -c "</xsl:text>
352 </xsl:if>
353 <xsl:apply-templates select="userinput"/>
[00f4966]354 <xsl:if test="@role = 'root' and $sudo = 'y'">
[1504208]355 <xsl:text>"</xsl:text>
356 </xsl:if>
357 <xsl:text>&#xA;</xsl:text>
[d6be7ea]358 </xsl:if>
359 </xsl:template>
360
361 <xsl:template match="para/command">
362 <xsl:if test="(contains(string(),'test') or
363 contains(string(),'check'))">
364 <xsl:text>#</xsl:text>
365 <xsl:value-of select="substring-before(string(),'make')"/>
366 <xsl:text>make -k</xsl:text>
367 <xsl:value-of select="substring-after(string(),'make')"/>
368 <xsl:text> || true&#xA;</xsl:text>
369 </xsl:if>
370 </xsl:template>
371
[1504208]372 <xsl:template match="userinput">
[d6be7ea]373 <xsl:apply-templates/>
374 </xsl:template>
375
376 <xsl:template match="replaceable">
377 <xsl:text>**EDITME</xsl:text>
378 <xsl:apply-templates/>
379 <xsl:text>EDITME**</xsl:text>
380 </xsl:template>
381
382</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.