source: BLFS/libs/scripts.xsl@ da49058

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

Trying to fix commands that need be run as root.
Need be verified.

  • 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:when test="contains($sub-url,'.patch')"/>
164 <xsl:otherwise>
165 <xsl:value-of select="$sub-url"/>
166 </xsl:otherwise>
167 </xsl:choose>
168 </xsl:otherwise>
169 </xsl:choose>
170 </xsl:template>
171
172 <xsl:template name="ftp_dir">
173 <xsl:param name="package" select="foo"/>
174 <!-- A lot of hardcoded dir names. Not full revised yet. -->
175 <xsl:choose>
176 <!-- cdparanoia -->
177 <xsl:when test="contains($package, '-III')">
178 <xsl:text>cdparanoia</xsl:text>
179 </xsl:when>
180 <!-- DobBook 3.1 -->
181 <xsl:when test="contains($package, 'docbk31')">
182 <xsl:text>docbk</xsl:text>
183 </xsl:when>
184 <!-- gc -->
185 <xsl:when test="contains($package, 'gc6')">
186 <xsl:text>gc</xsl:text>
187 </xsl:when>
188 <!-- ISO-codes -->
189 <xsl:when test="contains($package, 'iso-codes')">
190 <xsl:text>iso-codes</xsl:text>
191 </xsl:when>
192 <!-- JPEG -->
193 <xsl:when test="contains($package, 'jpegsrc')">
194 <xsl:text>jpeg</xsl:text>
195 </xsl:when>
196 <!-- lynx -->
197 <xsl:when test="contains($package, 'lynx')">
198 <xsl:text>lynx</xsl:text>
199 </xsl:when>
200 <!-- ntp -->
201 <xsl:when test="contains($package, 'ntp')">
202 <xsl:text>ntp</xsl:text>
203 </xsl:when>
204 <!-- OpenLDAP -->
205 <xsl:when test="contains($package, 'openldap')">
206 <xsl:text>openldap</xsl:text>
207 </xsl:when>
208 <!-- Open Office -->
209 <xsl:when test="contains($package, 'OOo')">
210 <xsl:text>OOo</xsl:text>
211 </xsl:when>
212 <!-- pine -->
213 <xsl:when test="contains($package, 'pine')">
214 <xsl:text>pine</xsl:text>
215 </xsl:when>
216 <!-- portmap -->
217 <xsl:when test="contains($package, 'portmap')">
218 <xsl:text>portmap</xsl:text>
219 </xsl:when>
220 <!-- psutils -->
221 <xsl:when test="contains($package, 'psutils')">
222 <xsl:text>psutils</xsl:text>
223 </xsl:when>
224 <!-- qpopper -->
225 <xsl:when test="contains($package, 'qpopper')">
226 <xsl:text>qpopper</xsl:text>
227 </xsl:when>
228 <!-- QT -->
229 <xsl:when test="contains($package, 'qt-x')">
230 <xsl:text>qt-x11-free</xsl:text>
231 </xsl:when>
232 <!-- sendmail -->
233 <xsl:when test="contains($package, 'sendmail')">
234 <xsl:text>sendmail</xsl:text>
235 </xsl:when>
236 <!-- Slib -->
237 <xsl:when test="contains($package, 'slib')">
238 <xsl:text>slib</xsl:text>
239 </xsl:when>
240 <!-- TCL -->
241 <xsl:when test="contains($package, 'tcl')">
242 <xsl:text>tcl</xsl:text>
243 </xsl:when>
244 <!-- tcpwrappers -->
245 <xsl:when test="contains($package, 'tcp_wrappers')">
246 <xsl:text>tcp_wrappers</xsl:text>
247 </xsl:when>
248 <!-- TeTeX -->
249 <xsl:when test="contains($package, 'tetex')">
250 <xsl:text>tetex</xsl:text>
251 </xsl:when>
252 <!-- Tidy -->
253 <xsl:when test="contains($package, 'tidy')">
254 <xsl:text>tidy</xsl:text>
255 </xsl:when>
256 <!-- Tk -->
257 <xsl:when test="contains($package, 'tk8')">
258 <xsl:text>tk</xsl:text>
259 </xsl:when>
260 <!-- unzip -->
261 <xsl:when test="contains($package, 'unzip')">
262 <xsl:text>unzip</xsl:text>
263 </xsl:when>
264 <!-- wireless_tools -->
265 <xsl:when test="contains($package, 'wireless_tools')">
266 <xsl:text>wireless_tools</xsl:text>
267 </xsl:when>
268 <!-- whois -->
269 <xsl:when test="contains($package, 'whois')">
270 <xsl:text>whois</xsl:text>
271 </xsl:when>
272 <!-- XOrg -->
273 <xsl:when test="contains($package, 'X11R6')">
274 <xsl:text>Xorg</xsl:text>
275 </xsl:when>
276 <!-- zip -->
277 <xsl:when test="contains($package, 'zip2')">
278 <xsl:text>zip</xsl:text>
279 </xsl:when>
280 <!-- General rule -->
281 <xsl:otherwise>
282 <xsl:variable name="cut"
283 select="translate(substring-after($package, '-'), '0123456789', '0000000000')"/>
284 <xsl:variable name="package2">
285 <xsl:value-of select="substring-before($package, '-')"/>
286 <xsl:text>-</xsl:text>
287 <xsl:value-of select="$cut"/>
288 </xsl:variable>
289 <xsl:value-of select="substring-before($package2, '-0')"/>
290 </xsl:otherwise>
291 </xsl:choose>
292 </xsl:template>
293
294 <xsl:template match="itemizedlist/listitem/para">
295 <xsl:param name="package" select="foo"/>
296 <xsl:param name="ftpdir" select="foo"/>
297 <xsl:choose>
298 <!-- This depend on all package pages having both "Download HTTP" and "Download FTP" lines -->
299 <xsl:when test="contains(string(),'HTTP')">
300 <xsl:text>if [[ ! -f $PACKAGE ]] ; then&#xA;</xsl:text>
301 <!-- SRC_ARCHIVE may have subdirectories or not -->
302 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$PACKAGE ]] ; then&#xA;</xsl:text>
303 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$PACKAGE $PACKAGE&#xA;</xsl:text>
304 <xsl:text> elif [[ -f $SRC_ARCHIVE/$PACKAGE ]] ; then&#xA;</xsl:text>
305 <xsl:text> cp $SRC_ARCHIVE/$PACKAGE $PACKAGE&#xA; else&#xA;</xsl:text>
306 <!-- The FTP_SERVER mirror -->
307 <xsl:text> wget $FTP_SERVER/BLFS/conglomeration/$PKG_DIR/$PACKAGE</xsl:text>
308 <!-- Upstream HTTP URL -->
309 <xsl:if test="string-length(ulink/@url) &gt; '10' and
310 not(contains(string(ulink/@url),'sourceforge'))">
311 <xsl:text> || \&#xA; wget </xsl:text>
312 <xsl:value-of select="ulink/@url"/>
313 </xsl:if>
314 </xsl:when>
315 <xsl:when test="contains(string(),'FTP')">
316 <!-- Upstream FTP URL -->
317 <xsl:if test="string-length(ulink/@url) &gt; '10'">
318 <xsl:text> || \&#xA; wget </xsl:text>
319 <xsl:value-of select="ulink/@url"/>
320 </xsl:if>
321 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
322 </xsl:when>
323 <xsl:when test="contains(string(),'MD5')">
324 <xsl:text>echo "</xsl:text>
325 <xsl:value-of select="substring-after(string(),'sum: ')"/>
326 <xsl:text>&#x20;&#x20;$PACKAGE" | md5sum -c -&#xA;</xsl:text>
327 </xsl:when>
328 <!-- Patches -->
329 <xsl:when test="contains(string(ulink/@url),'.patch')">
330 <xsl:text>wget </xsl:text>
331 <xsl:value-of select="ulink/@url"/>
332 <xsl:text>&#xA;</xsl:text>
333 </xsl:when>
334 </xsl:choose>
335 </xsl:template>
336
337<!--======================== Commands code ==========================-->
338
339 <xsl:template match="screen">
340 <xsl:if test="child::* = userinput and not(@role = 'nodump')">
341 <xsl:if test="@role = 'root'">
342 <xsl:text>sudo sh -c "</xsl:text>
343 </xsl:if>
344 <xsl:apply-templates select="userinput"/>
345 <xsl:if test="@role = 'root'">
346 <xsl:text>"</xsl:text>
347 </xsl:if>
348 <xsl:text>&#xA;</xsl:text>
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">
364 <xsl:apply-templates/>
365 </xsl:template>
366
367 <xsl:template match="replaceable">
368 <xsl:text>**EDITME</xsl:text>
369 <xsl:apply-templates/>
370 <xsl:text>EDITME**</xsl:text>
371 </xsl:template>
372
373</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.