source: BLFS/libs/scripts.xsl@ 37ac06a

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

Trying to find the proper download directory for each package.

  • Property mode set to 100644
File size: 9.5 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 <xsl:when test="sect2[@role='package']">
78 <xsl:apply-templates select="sect2">
79 <xsl:with-param name="package" select="$package"/>
80 <xsl:with-param name="ftpdir" select="$ftpdir"/>
81 </xsl:apply-templates>
82 <xsl:text>cd ~/sources/</xsl:text>
83 <xsl:value-of select="$ftpdir"/>
84 <xsl:text>&#xA;rm -rf $UNPACKDIR&#xA;&#xA;</xsl:text>
85 </xsl:when>
86 <xsl:otherwise>
87 <xsl:apply-templates select=".//screen"/>
88 </xsl:otherwise>
89 </xsl:choose>
90 <xsl:text>exit</xsl:text>
91 </exsl:document>
92
93 </xsl:if>
94 </xsl:template>
95
96<!--======================= Sub-sections code =======================-->
97
98 <xsl:template match="sect2">
99 <xsl:param name="package" select="foo"/>
100 <xsl:param name="ftpdir" select="foo"/>
101 <xsl:choose>
102 <xsl:when test="@role = 'package'">
103 <xsl:text>mkdir -p ~/sources/</xsl:text>
104 <xsl:value-of select="$ftpdir"/>
105 <xsl:text>&#xA;cd ~/sources/</xsl:text>
106 <xsl:value-of select="$ftpdir"/>
107 <xsl:text>&#xA;</xsl:text>
108 <xsl:apply-templates select="itemizedlist/listitem/para">
109 <xsl:with-param name="package" select="$package"/>
110 <xsl:with-param name="ftpdir" select="$ftpdir"/>
111 </xsl:apply-templates>
112 <xsl:text>&#xA;</xsl:text>
113 </xsl:when>
114 <xsl:when test="@role = 'installation'">
115 <xsl:text>tar -xvf </xsl:text>
116 <xsl:value-of select="$package"/>
117 <xsl:text> > /tmp/unpacked&#xA;</xsl:text>
118 <xsl:text>UNPACKDIR=`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'`&#xA;</xsl:text>
119 <xsl:text>cd $UNPACKDIR&#xA;</xsl:text>
120 <xsl:apply-templates select=".//screen | .//para/command"/>
121 <xsl:text>&#xA;</xsl:text>
122 </xsl:when>
123 <xsl:when test="@role = 'configuration'">
124 <xsl:apply-templates select=".//screen"/>
125 <xsl:text>&#xA;</xsl:text>
126 </xsl:when>
127 <xsl:otherwise/>
128 </xsl:choose>
129 </xsl:template>
130
131<!--==================== Download code =======================-->
132
133 <xsl:template name="package_name">
134 <xsl:param name="url" select="foo"/>
135 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
136 <xsl:choose>
137 <xsl:when test="contains($sub-url,'/')">
138 <xsl:call-template name="package_name">
139 <xsl:with-param name="url" select="$sub-url"/>
140 </xsl:call-template>
141 </xsl:when>
142 <xsl:otherwise>
143 <xsl:choose>
144 <xsl:when test="contains($sub-url,'?')">
145 <xsl:value-of select="substring-before($sub-url,'?')"/>
146 </xsl:when>
147 <xsl:otherwise>
148 <xsl:value-of select="$sub-url"/>
149 </xsl:otherwise>
150 </xsl:choose>
151 </xsl:otherwise>
152 </xsl:choose>
153 </xsl:template>
154
155 <xsl:template name="ftp_dir">
156 <xsl:param name="package" select="foo"/>
157 <!-- From BLFS patcheslist.xsl. Need be revised and fixed. -->
158 <xsl:choose>
159 <!-- cdparanoia -->
160 <xsl:when test="contains($package, '-III')">
161 <xsl:text>cdparanoia</xsl:text>
162 </xsl:when>
163 <!-- Open Office -->
164 <xsl:when test="contains($package, 'OOo')">
165 <xsl:text>OOo</xsl:text>
166 </xsl:when>
167 <!-- QT -->
168 <xsl:when test="contains($package, 'qt-x')">
169 <xsl:text>qt</xsl:text>
170 </xsl:when>
171 <!-- XOrg -->
172 <xsl:when test="contains($package, 'X11R6')">
173 <xsl:text>xorg</xsl:text>
174 </xsl:when>
175 <!-- General rule -->
176 <xsl:otherwise>
177 <xsl:variable name="cut"
178 select="translate(substring-after($package, '-'), '0123456789', '0000000000')"/>
179 <xsl:variable name="package2">
180 <xsl:value-of select="substring-before($package, '-')"/>
181 <xsl:text>-</xsl:text>
182 <xsl:value-of select="$cut"/>
183 </xsl:variable>
184 <xsl:value-of select="substring-before($package2, '-0')"/>
185 </xsl:otherwise>
186 </xsl:choose>
187 </xsl:template>
188
189 <xsl:template match="itemizedlist/listitem/para">
190 <xsl:param name="package" select="foo"/>
191 <xsl:param name="ftpdir" select="foo"/>
192 <xsl:choose>
193 <xsl:when test="contains(string(),'HTTP')">
194 <!-- SRC_ARCHIVE may have subdirectories or not -->
195 <xsl:text>cp $SRC_ARCHIVE/</xsl:text>
196 <xsl:value-of select="$ftpdir"/>
197 <xsl:text>/</xsl:text>
198 <xsl:value-of select="$package"/>
199 <xsl:text> || \&#xA;</xsl:text>
200 <xsl:text>cp $SRC_ARCHIVE/</xsl:text>
201 <xsl:value-of select="$package"/>
202 <xsl:text> || \&#xA;</xsl:text>
203 <!-- The FTP_SERVER mirror -->
204 <xsl:text>wget $FTP_SERVER/BLFS/conglomeration/</xsl:text>
205 <xsl:value-of select="$ftpdir"/>
206 <xsl:text>/</xsl:text>
207 <xsl:value-of select="$package"/>
208 <xsl:text> || \&#xA;</xsl:text>
209 <!-- Upstream HTTP URL -->
210 <xsl:text>wget </xsl:text>
211 <xsl:value-of select="ulink/@url"/>
212 <xsl:text> || \&#xA;</xsl:text>
213 </xsl:when>
214 <xsl:when test="contains(string(),'FTP')">
215 <!-- Upstream FTP URL -->
216 <xsl:text>wget </xsl:text>
217 <xsl:value-of select="ulink/@url"/>
218 <xsl:text>&#xA;</xsl:text>
219 </xsl:when>
220 <xsl:when test="contains(string(),'MD5')">
221 <xsl:text>echo "</xsl:text>
222 <xsl:value-of select="substring-after(string(),'sum: ')"/>
223 <xsl:text>&#x20;&#x20;</xsl:text>
224 <xsl:value-of select="$package"/>
225 <xsl:text>" | md5sum -c -&#xA;</xsl:text>
226 </xsl:when>
227 <!-- Patches. Need be veryfied -->
228 <xsl:when test="contains(string(),'patch')">
229 <xsl:text>wget </xsl:text>
230 <xsl:value-of select="ulink/@url"/>
231 <xsl:text>&#xA;</xsl:text>
232 </xsl:when>
233 <xsl:otherwise/>
234 </xsl:choose>
235 </xsl:template>
236
237<!--======================== Commands code ==========================-->
238
239 <xsl:template match="screen">
240 <xsl:if test="child::* = userinput">
241 <xsl:choose>
242 <xsl:when test="@role = 'nodump'"/>
243 <xsl:otherwise>
244 <xsl:if test="@role = 'root'">
245 <xsl:text>sudo </xsl:text>
246 </xsl:if>
247 <xsl:apply-templates select="userinput" mode="screen"/>
248 </xsl:otherwise>
249 </xsl:choose>
250 </xsl:if>
251 </xsl:template>
252
253 <xsl:template match="para/command">
254 <xsl:if test="(contains(string(),'test') or
255 contains(string(),'check'))">
256 <xsl:text>#</xsl:text>
257 <xsl:value-of select="substring-before(string(),'make')"/>
258 <xsl:text>make -k</xsl:text>
259 <xsl:value-of select="substring-after(string(),'make')"/>
260 <xsl:text> || true&#xA;</xsl:text>
261 </xsl:if>
262 </xsl:template>
263
264 <xsl:template match="userinput" mode="screen">
265 <xsl:apply-templates/>
266 <xsl:text>&#xA;</xsl:text>
267 </xsl:template>
268
269 <xsl:template match="replaceable">
270 <xsl:text>**EDITME</xsl:text>
271 <xsl:apply-templates/>
272 <xsl:text>EDITME**</xsl:text>
273 </xsl:template>
274
275</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.