source: BLFS/libs/scripts.xsl@ 3d888ef

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

Base code to extract packages name an FTP dirs.

  • Property mode set to 100644
File size: 8.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 <!-- Creating the scripts -->
63 <exsl:document href="{$order}-{$filename}" method="text">
64 <xsl:text>#!/bin/sh&#xA;set -e&#xA;&#xA;</xsl:text>
65 <xsl:choose>
66 <xsl:when test="sect2[@role='package']">
67 <xsl:apply-templates select="sect2">
68 <xsl:with-param name="package" select="$package"/>
69 <xsl:with-param name="ftpdir" select="$ftpdir"/>
70 </xsl:apply-templates>
71 <xsl:text>cd ~/sources/</xsl:text>
72 <xsl:value-of select="$ftpdir"/>
73 <xsl:text>&#xA;rm -rf $UNPACKDIR&#xA;&#xA;</xsl:text>
74 </xsl:when>
75 <xsl:otherwise>
76 <xsl:apply-templates select=".//screen"/>
77 </xsl:otherwise>
78 </xsl:choose>
79 <xsl:text>exit</xsl:text>
80 </exsl:document>
81
82 </xsl:if>
83 </xsl:template>
84
85<!--======================= Sub-sections code =======================-->
86
87 <xsl:template match="sect2">
88 <xsl:param name="package" select="foo"/>
89 <xsl:param name="ftpdir" select="foo"/>
90 <xsl:choose>
91 <xsl:when test="@role = 'package'">
92 <xsl:text>mkdir -p ~/sources/</xsl:text>
93 <xsl:value-of select="$ftpdir"/>
94 <xsl:text>&#xA;cd ~/sources/</xsl:text>
95 <xsl:value-of select="$ftpdir"/>
96 <xsl:text>&#xA;</xsl:text>
97 <xsl:apply-templates select="itemizedlist/listitem/para">
98 <xsl:with-param name="package" select="$package"/>
99 <xsl:with-param name="ftpdir" select="$ftpdir"/>
100 </xsl:apply-templates>
101 <xsl:text>&#xA;</xsl:text>
102 </xsl:when>
103 <xsl:when test="@role = 'installation'">
104 <xsl:text>tar -xvf </xsl:text>
105 <xsl:value-of select="$package"/>
106 <xsl:text> > /tmp/unpacked&#xA;</xsl:text>
107 <xsl:text>UNPACKDIR=`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'`&#xA;</xsl:text>
108 <xsl:text>cd $UNPACKDIR&#xA;</xsl:text>
109 <xsl:apply-templates select=".//screen | .//para/command"/>
110 <xsl:text>&#xA;</xsl:text>
111 </xsl:when>
112 <xsl:when test="@role = 'configuration'">
113 <xsl:apply-templates select=".//screen"/>
114 <xsl:text>&#xA;</xsl:text>
115 </xsl:when>
116 <xsl:otherwise/>
117 </xsl:choose>
118 </xsl:template>
119
120<!--==================== Download code =======================-->
121
122 <xsl:template name="package_name">
123 <xsl:param name="url" select="foo"/>
124 <xsl:message>
125 <xsl:text>URL es </xsl:text>
126 <xsl:value-of select="$url"/>
127 </xsl:message>
128 <xsl:param name="sub-url" select="substring-after($url,'/')"/>
129 <xsl:choose>
130 <xsl:when test="contains($sub-url,'/')">
131 <xsl:call-template name="package_name">
132 <xsl:with-param name="url" select="$sub-url"/>
133 </xsl:call-template>
134 </xsl:when>
135 <xsl:otherwise>
136 <xsl:choose>
137 <xsl:when test="contains($sub-url,'?')">
138 <xsl:value-of select="substring-before($sub-url,'?')"/>
139 </xsl:when>
140 <xsl:otherwise>
141 <xsl:value-of select="$sub-url"/>
142 </xsl:otherwise>
143 </xsl:choose>
144 </xsl:otherwise>
145 </xsl:choose>
146 </xsl:template>
147
148 <xsl:template name="ftp_dir">
149 <xsl:param name="package" select="foo"/>
150 <!-- Placeholder. We need here a lot of code from BLFS patcheslist.xsl -->
151 <xsl:value-of select="substring-before($package,'-')"/>
152 </xsl:template>
153
154 <xsl:template match="itemizedlist/listitem/para">
155 <xsl:param name="package" select="foo"/>
156 <xsl:param name="ftpdir" select="foo"/>
157 <xsl:choose>
158 <xsl:when test="contains(string(),'HTTP')">
159 <!-- SRC_ARCHIVE may have subdirectories or not -->
160 <xsl:text>cp $SRC_ARCHIVE/</xsl:text>
161 <xsl:value-of select="$ftpdir"/>
162 <xsl:text>/</xsl:text>
163 <xsl:value-of select="$package"/>
164 <xsl:text> || \&#xA;</xsl:text>
165 <xsl:text>cp $SRC_ARCHIVE/</xsl:text>
166 <xsl:value-of select="$package"/>
167 <xsl:text> || \&#xA;</xsl:text>
168 <!-- The FTP_SERVER mirror -->
169 <xsl:text>wget $FTP_SERVER/BLFS/conglomeration/</xsl:text>
170 <xsl:value-of select="$ftpdir"/>
171 <xsl:text>/</xsl:text>
172 <xsl:value-of select="$package"/>
173 <xsl:text> || \&#xA;</xsl:text>
174 <!-- Upstream HTTP URL -->
175 <xsl:text>wget </xsl:text>
176 <xsl:value-of select="ulink/@url"/>
177 <xsl:text> || \&#xA;</xsl:text>
178 </xsl:when>
179 <xsl:when test="contains(string(),'FTP')">
180 <!-- Upstream FTP URL -->
181 <xsl:text>wget </xsl:text>
182 <xsl:value-of select="ulink/@url"/>
183 <xsl:text>&#xA;</xsl:text>
184 </xsl:when>
185 <xsl:when test="contains(string(),'MD5')">
186 <xsl:text>echo "</xsl:text>
187 <xsl:value-of select="substring-after(string(),'sum: ')"/>
188 <xsl:text>&#x20;&#x20;</xsl:text>
189 <xsl:value-of select="$package"/>
190 <xsl:text>" | md5sum -c -&#xA;</xsl:text>
191 </xsl:when>
192 <!-- Patches. Need be veryfied -->
193 <xsl:when test="contains(string(),'patch')">
194 <xsl:text>wget </xsl:text>
195 <xsl:value-of select="ulink/@url"/>
196 <xsl:text>&#xA;</xsl:text>
197 </xsl:when>
198 <xsl:otherwise/>
199 </xsl:choose>
200 </xsl:template>
201
202<!--======================== Commands code ==========================-->
203
204 <xsl:template match="screen">
205 <xsl:if test="child::* = userinput">
206 <xsl:choose>
207 <xsl:when test="@role = 'nodump'"/>
208 <xsl:otherwise>
209 <xsl:if test="@role = 'root'">
210 <xsl:text>sudo </xsl:text>
211 </xsl:if>
212 <xsl:apply-templates select="userinput" mode="screen"/>
213 </xsl:otherwise>
214 </xsl:choose>
215 </xsl:if>
216 </xsl:template>
217
218 <xsl:template match="para/command">
219 <xsl:if test="(contains(string(),'test') or
220 contains(string(),'check'))">
221 <xsl:text>#</xsl:text>
222 <xsl:value-of select="substring-before(string(),'make')"/>
223 <xsl:text>make -k</xsl:text>
224 <xsl:value-of select="substring-after(string(),'make')"/>
225 <xsl:text> || true&#xA;</xsl:text>
226 </xsl:if>
227 </xsl:template>
228
229 <xsl:template match="userinput" mode="screen">
230 <xsl:apply-templates/>
231 <xsl:text>&#xA;</xsl:text>
232 </xsl:template>
233
234 <xsl:template match="replaceable">
235 <xsl:text>**EDITME</xsl:text>
236 <xsl:apply-templates/>
237 <xsl:text>EDITME**</xsl:text>
238 </xsl:template>
239
240</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.