source: BLFS/libs/scripts.xsl@ 40d4ca7

experimental
Last change on this file since 40d4ca7 was 40d4ca7, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Skipped SourceForge downloads.

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