source: BLFS/libs/scripts.xsl@ 8aba69a

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

More package dir name fixes.

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