source: BLFS/libs/scripts.xsl@ e4f732c

2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since e4f732c was f221c2c, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Solved download from sourceforge URLs

  • Property mode set to 100644
File size: 15.5 KB
RevLine 
[3c10176]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
[c0bc66d]12 <!-- Build as user (y) or as root (n)? -->
13 <xsl:param name="sudo" select="y"/>
14
[3c10176]15 <xsl:template match="/">
16 <xsl:apply-templates select="//sect1"/>
17 </xsl:template>
18
19<!--=================== Master chunks code ======================-->
20
21 <xsl:template match="sect1">
[b45f723]22 <xsl:if test="(count(descendant::screen/userinput) &gt; 0 and
[3c10176]23 count(descendant::screen/userinput) &gt;
[b45f723]24 count(descendant::screen[@role='nodump'])) and
25 @id != 'locale-issues' and @id != 'xorg7' and
26 @id != 'x-setup'">
[3c10176]27
28 <!-- The file names -->
[f4ed135]29 <xsl:variable name="filename" select="@id"/>
[3c10176]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 -->
[73c3c1c]88 <exsl:document href="{$order}-z-{$filename}" method="text">
[91ff6a9]89 <xsl:text>#!/bin/bash&#xA;set -e&#xA;&#xA;</xsl:text>
[3c10176]90 <xsl:choose>
91 <!-- Package page -->
[b45f723]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')">
[3c10176]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"/>
[8b57785]102 <xsl:text>&#xA;SRC_DIR=$SRC_DIR&#xA;&#xA;</xsl:text>
[3c10176]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 -->
[f65d3cb]109 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
[859d863]110 <xsl:text>rm -rf $UNPACKDIR unpacked&#xA;&#xA;</xsl:text>
[3c10176]111 </xsl:when>
[b45f723]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>
[3c10176]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'">
[f65d3cb]139 <xsl:text>mkdir -p $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
140 <xsl:text>cd $SRC_DIR/$PKG_DIR&#xA;</xsl:text>
[3c10176]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'">
[859d863]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@/.*@@'`
[6ff1be4]155cd $UNPACKDIR&#xA;</xsl:text>
[3c10176]156 <xsl:apply-templates select=".//screen | .//para/command"/>
[a1d0d5c]157 <xsl:if test="$sudo = 'y'">
158 <xsl:text>sudo </xsl:text>
159 </xsl:if>
160 <xsl:text>ldconfig&#xA;&#xA;</xsl:text>
[3c10176]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
[b45f723]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"/>
[5be3651]174 <xsl:apply-templates select="../sect2[@role='package']/itemizedlist/listitem/para"
175 mode="xorg7"/>
[b45f723]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"/>
[5be3651]186 <xsl:text> cd ..
[b45f723]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
[3c10176]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 -->
[6d0dbc3]357 <xsl:text> wget ${FTP_SERVER}conglomeration/$PKG_DIR/$PACKAGE</xsl:text>
[3c10176]358 <!-- Upstream HTTP URL -->
[f221c2c]359 <xsl:if test="string-length(ulink/@url) &gt; '10'">
[3c10176]360 <xsl:text> || \&#xA; wget </xsl:text>
[f221c2c]361 <xsl:choose>
362 <xsl:when test="contains(ulink/@url,'?')">
363 <xsl:value-of select="substring-before(ulink/@url,'?')"/>
364 </xsl:when>
365 <xsl:otherwise>
366 <xsl:value-of select="ulink/@url"/>
367 </xsl:otherwise>
368 </xsl:choose>
[3c10176]369 </xsl:if>
370 </xsl:when>
371 <xsl:when test="contains(string(),'FTP')">
372 <!-- Upstream FTP URL -->
373 <xsl:if test="string-length(ulink/@url) &gt; '10'">
374 <xsl:text> || \&#xA; wget </xsl:text>
375 <xsl:value-of select="ulink/@url"/>
376 </xsl:if>
377 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
378 </xsl:when>
379 <xsl:when test="contains(string(),'MD5')">
380 <xsl:text>echo "</xsl:text>
381 <xsl:value-of select="substring-after(string(),'sum: ')"/>
382 <xsl:text>&#x20;&#x20;$PACKAGE" | md5sum -c -&#xA;</xsl:text>
383 </xsl:when>
384 <!-- Patches -->
385 <xsl:when test="contains(string(ulink/@url),'.patch')">
386 <xsl:text>wget </xsl:text>
387 <xsl:value-of select="ulink/@url"/>
388 <xsl:text>&#xA;</xsl:text>
389 </xsl:when>
390 </xsl:choose>
391 </xsl:template>
392
[5be3651]393 <xsl:template match="itemizedlist/listitem/para" mode="xorg7">
394 <xsl:if test="contains(string(ulink/@url),'.patch')">
395 <xsl:text>wget </xsl:text>
396 <xsl:value-of select="ulink/@url"/>
397 <xsl:text>&#xA;</xsl:text>
398 </xsl:if>
399 </xsl:template>
400
[3c10176]401<!--======================== Commands code ==========================-->
402
403 <xsl:template match="screen">
404 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
[c0bc66d]405 <xsl:if test="@role = 'root' and $sudo = 'y'">
[3c10176]406 <xsl:text>sudo sh -c "</xsl:text>
407 </xsl:if>
408 <xsl:apply-templates select="userinput"/>
[c0bc66d]409 <xsl:if test="@role = 'root' and $sudo = 'y'">
[3c10176]410 <xsl:text>"</xsl:text>
411 </xsl:if>
412 <xsl:text>&#xA;</xsl:text>
413 </xsl:if>
414 </xsl:template>
415
[b45f723]416 <xsl:template match="screen" mode="wget_lst">
417 <xsl:value-of select="substring-after(string(),' -i ')"/>
418 </xsl:template>
419
[3c10176]420 <xsl:template match="para/command">
421 <xsl:if test="(contains(string(),'test') or
422 contains(string(),'check'))">
423 <xsl:text>#</xsl:text>
424 <xsl:value-of select="substring-before(string(),'make')"/>
425 <xsl:text>make -k</xsl:text>
426 <xsl:value-of select="substring-after(string(),'make')"/>
427 <xsl:text> || true&#xA;</xsl:text>
428 </xsl:if>
429 </xsl:template>
430
431 <xsl:template match="userinput">
432 <xsl:apply-templates/>
433 </xsl:template>
434
435 <xsl:template match="replaceable">
436 <xsl:text>**EDITME</xsl:text>
437 <xsl:apply-templates/>
438 <xsl:text>EDITME**</xsl:text>
439 </xsl:template>
440
441</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.