source: BLFS/libs/scripts.xsl@ edf7e4c

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

Fixed several packages dirs names.

  • Property mode set to 100644
File size: 12.2 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 <!-- sendmail -->
208 <xsl:when test="contains($package, 'sendmail')">
209 <xsl:text>sendmail</xsl:text>
210 </xsl:when>
211 <!-- Slib -->
212 <xsl:when test="contains($package, 'slib')">
213 <xsl:text>slib</xsl:text>
214 </xsl:when>
215 <!-- TCL -->
216 <xsl:when test="contains($package, 'tcl')">
217 <xsl:text>tcl</xsl:text>
218 </xsl:when>
219 <!-- tcpwrappers -->
220 <xsl:when test="contains($package, 'tcp_wrappers')">
221 <xsl:text>tcp_wrappers</xsl:text>
222 </xsl:when>
223 <!-- TeTeX -->
224 <xsl:when test="contains($package, 'tetex')">
225 <xsl:text>tetex</xsl:text>
226 </xsl:when>
227 <!-- Tidy -->
228 <xsl:when test="contains($package, 'tidy')">
229 <xsl:text>tidy</xsl:text>
230 </xsl:when>
231 <!-- Tk -->
232 <xsl:when test="contains($package, 'tk')">
233 <xsl:text>tk</xsl:text>
234 </xsl:when>
235 <!-- unzip -->
236 <xsl:when test="contains($package, 'unzip')">
237 <xsl:text>unzip</xsl:text>
238 </xsl:when>
239 <!-- wireless_tools -->
240 <xsl:when test="contains($package, 'wireless_tools')">
241 <xsl:text>wireless_tools</xsl:text>
242 </xsl:when>
243 <!-- whois -->
244 <xsl:when test="contains($package, 'whois')">
245 <xsl:text>whois</xsl:text>
246 </xsl:when>
247 <!-- XOrg -->
248 <xsl:when test="contains($package, 'X11R6')">
249 <xsl:text>Xorg</xsl:text>
250 </xsl:when>
251 <!-- zip -->
252 <xsl:when test="contains($package, 'zip2')">
253 <xsl:text>zip</xsl:text>
254 </xsl:when>
255 <!-- General rule -->
256 <xsl:otherwise>
257 <xsl:variable name="cut"
258 select="translate(substring-after($package, '-'), '0123456789', '0000000000')"/>
259 <xsl:variable name="package2">
260 <xsl:value-of select="substring-before($package, '-')"/>
261 <xsl:text>-</xsl:text>
262 <xsl:value-of select="$cut"/>
263 </xsl:variable>
264 <xsl:value-of select="substring-before($package2, '-0')"/>
265 </xsl:otherwise>
266 </xsl:choose>
267 </xsl:template>
268
269 <xsl:template match="itemizedlist/listitem/para">
270 <xsl:param name="package" select="foo"/>
271 <xsl:param name="ftpdir" select="foo"/>
272 <xsl:choose>
273 <!-- This depend on all package pages having both "Download HTTP" and "Download FTP" lines -->
274 <xsl:when test="contains(string(),'HTTP')">
275 <xsl:text>if [[ ! -f $PACKAGE ]] ; then&#xA;</xsl:text>
276 <!-- SRC_ARCHIVE may have subdirectories or not -->
277 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$PACKAGE ]] ; then&#xA;</xsl:text>
278 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$PACKAGE $PACKAGE&#xA;</xsl:text>
279 <xsl:text> elif [[ -f $SRC_ARCHIVE/$PACKAGE ]] ; then&#xA;</xsl:text>
280 <xsl:text> cp $SRC_ARCHIVE/$PACKAGE $PACKAGE&#xA; else&#xA;</xsl:text>
281 <!-- The FTP_SERVER mirror -->
282 <xsl:text> wget $FTP_SERVER/BLFS/conglomeration/$PKG_DIR/$PACKAGE || \&#xA;</xsl:text>
283 <!-- Upstream HTTP URL -->
284 <xsl:text> wget </xsl:text>
285 <xsl:value-of select="ulink/@url"/>
286 <xsl:text> || \&#xA;</xsl:text>
287 </xsl:when>
288 <xsl:when test="contains(string(),'FTP')">
289 <!-- Upstream FTP URL -->
290 <xsl:text> wget </xsl:text>
291 <xsl:value-of select="ulink/@url"/>
292 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
293 </xsl:when>
294 <xsl:when test="contains(string(),'MD5')">
295 <xsl:text>echo "</xsl:text>
296 <xsl:value-of select="substring-after(string(),'sum: ')"/>
297 <xsl:text>&#x20;&#x20;$PACKAGE" | md5sum -c -&#xA;</xsl:text>
298 </xsl:when>
299 <!-- Patches. Need be veryfied -->
300 <xsl:when test="contains(string(),'patch')">
301 <xsl:text>wget </xsl:text>
302 <xsl:value-of select="ulink/@url"/>
303 <xsl:text>&#xA;</xsl:text>
304 </xsl:when>
305 </xsl:choose>
306 </xsl:template>
307
308<!--======================== Commands code ==========================-->
309
310 <xsl:template match="screen">
311 <xsl:if test="child::* = userinput">
312 <xsl:choose>
313 <xsl:when test="@role = 'nodump'"/>
314 <xsl:otherwise>
315 <xsl:if test="@role = 'root'">
316 <xsl:text>sudo </xsl:text>
317 </xsl:if>
318 <xsl:apply-templates select="userinput" mode="screen"/>
319 </xsl:otherwise>
320 </xsl:choose>
321 </xsl:if>
322 </xsl:template>
323
324 <xsl:template match="para/command">
325 <xsl:if test="(contains(string(),'test') or
326 contains(string(),'check'))">
327 <xsl:text>#</xsl:text>
328 <xsl:value-of select="substring-before(string(),'make')"/>
329 <xsl:text>make -k</xsl:text>
330 <xsl:value-of select="substring-after(string(),'make')"/>
331 <xsl:text> || true&#xA;</xsl:text>
332 </xsl:if>
333 </xsl:template>
334
335 <xsl:template match="userinput" mode="screen">
336 <xsl:apply-templates/>
337 <xsl:text>&#xA;</xsl:text>
338 </xsl:template>
339
340 <xsl:template match="replaceable">
341 <xsl:text>**EDITME</xsl:text>
342 <xsl:apply-templates/>
343 <xsl:text>EDITME**</xsl:text>
344 </xsl:template>
345
346</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.