source: BLFS/libs/scripts.xsl@ d3d90e7

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

Added Some envars.
Better handled of packages download.

  • Property mode set to 100644
File size: 9.8 KB
RevLine 
[d6be7ea]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
[3d888ef]10<!-- XSLT stylesheet to create shell scripts from "linear build" BLFS books. -->
[d6be7ea]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']))">
[3d888ef]23
[d6be7ea]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')"/>
[3d888ef]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
[d6be7ea]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>
[3d888ef]61
[37ac06a]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
[3d888ef]73 <!-- Creating the scripts -->
[d6be7ea]74 <exsl:document href="{$order}-{$filename}" method="text">
75 <xsl:text>#!/bin/sh&#xA;set -e&#xA;&#xA;</xsl:text>
[838b61a]76 <xsl:choose>
[d3d90e7]77 <!-- Package page -->
[838b61a]78 <xsl:when test="sect2[@role='package']">
[d3d90e7]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 -->
[838b61a]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>
[d3d90e7]91 <!-- Clean-up -->
92 <xsl:text>cd ~/sources/$PKG_DIR&#xA;</xsl:text>
93 <xsl:text>rm -rf $UNPACKDIR&#xA;&#xA;</xsl:text>
[838b61a]94 </xsl:when>
[d3d90e7]95 <!-- Non-package page -->
[838b61a]96 <xsl:otherwise>
97 <xsl:apply-templates select=".//screen"/>
98 </xsl:otherwise>
99 </xsl:choose>
[d6be7ea]100 <xsl:text>exit</xsl:text>
101 </exsl:document>
[3d888ef]102
[d6be7ea]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'">
[d3d90e7]113 <xsl:text>mkdir -p ~/sources/$PKG_DIR&#xA;</xsl:text>
114 <xsl:text>cd ~/sources/$PKG_DIR&#xA;</xsl:text>
[d6be7ea]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'">
[d3d90e7]122 <xsl:text>tar -xvf $PACKAGE > unpacked&#xA;</xsl:text>
123 <xsl:text>UNPACKDIR=`head -n1 unpacked | sed 's@^./@@;s@/.*@@'`&#xA;</xsl:text>
[d6be7ea]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
[3d888ef]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"/>
[37ac06a]161 <!-- From BLFS patcheslist.xsl. Need be revised and fixed. -->
162 <xsl:choose>
163 <!-- cdparanoia -->
164 <xsl:when test="contains($package, '-III')">
165 <xsl:text>cdparanoia</xsl:text>
166 </xsl:when>
167 <!-- Open Office -->
168 <xsl:when test="contains($package, 'OOo')">
169 <xsl:text>OOo</xsl:text>
170 </xsl:when>
171 <!-- QT -->
172 <xsl:when test="contains($package, 'qt-x')">
173 <xsl:text>qt</xsl:text>
174 </xsl:when>
175 <!-- XOrg -->
176 <xsl:when test="contains($package, 'X11R6')">
177 <xsl:text>xorg</xsl:text>
178 </xsl:when>
179 <!-- General rule -->
180 <xsl:otherwise>
181 <xsl:variable name="cut"
182 select="translate(substring-after($package, '-'), '0123456789', '0000000000')"/>
183 <xsl:variable name="package2">
184 <xsl:value-of select="substring-before($package, '-')"/>
185 <xsl:text>-</xsl:text>
186 <xsl:value-of select="$cut"/>
187 </xsl:variable>
188 <xsl:value-of select="substring-before($package2, '-0')"/>
189 </xsl:otherwise>
190 </xsl:choose>
[3d888ef]191 </xsl:template>
192
[d6be7ea]193 <xsl:template match="itemizedlist/listitem/para">
194 <xsl:param name="package" select="foo"/>
195 <xsl:param name="ftpdir" select="foo"/>
196 <xsl:choose>
[d3d90e7]197 <!-- This depend on all package pages having both "Download HTTP" and "Download FTP" lines -->
[d6be7ea]198 <xsl:when test="contains(string(),'HTTP')">
[d3d90e7]199 <xsl:text>if [[ ! -f $PACKAGE ]] ; then&#xA;</xsl:text>
[6e4e0dd]200 <!-- SRC_ARCHIVE may have subdirectories or not -->
[d3d90e7]201 <xsl:text> if [[ -f $SRC_ARCHIVE/$PKG_DIR/$PACKAGE ]] ; then&#xA;</xsl:text>
202 <xsl:text> cp $SRC_ARCHIVE/$PKG_DIR/$PACKAGE $PACKAGE&#xA;</xsl:text>
203 <xsl:text> elif [[ -f $SRC_ARCHIVE/$PACKAGE ]] ; then&#xA;</xsl:text>
204 <xsl:text> cp $SRC_ARCHIVE/$PACKAGE $PACKAGE&#xA; else&#xA;</xsl:text>
[d6be7ea]205 <!-- The FTP_SERVER mirror -->
[d3d90e7]206 <xsl:text> wget $FTP_SERVER/BLFS/conglomeration/$PKG_DIR/$PACKAGE || \&#xA;</xsl:text>
[d6be7ea]207 <!-- Upstream HTTP URL -->
[d3d90e7]208 <xsl:text> wget </xsl:text>
[d6be7ea]209 <xsl:value-of select="ulink/@url"/>
210 <xsl:text> || \&#xA;</xsl:text>
211 </xsl:when>
212 <xsl:when test="contains(string(),'FTP')">
213 <!-- Upstream FTP URL -->
[d3d90e7]214 <xsl:text> wget </xsl:text>
[d6be7ea]215 <xsl:value-of select="ulink/@url"/>
[d3d90e7]216 <xsl:text>&#xA; fi&#xA;fi&#xA;</xsl:text>
[d6be7ea]217 </xsl:when>
218 <xsl:when test="contains(string(),'MD5')">
219 <xsl:text>echo "</xsl:text>
220 <xsl:value-of select="substring-after(string(),'sum: ')"/>
[d3d90e7]221 <xsl:text>&#x20;&#x20;$PACKAGE" | md5sum -c -&#xA;</xsl:text>
[d6be7ea]222 </xsl:when>
223 <!-- Patches. Need be veryfied -->
224 <xsl:when test="contains(string(),'patch')">
225 <xsl:text>wget </xsl:text>
226 <xsl:value-of select="ulink/@url"/>
227 <xsl:text>&#xA;</xsl:text>
228 </xsl:when>
229 </xsl:choose>
230 </xsl:template>
231
232<!--======================== Commands code ==========================-->
233
234 <xsl:template match="screen">
235 <xsl:if test="child::* = userinput">
236 <xsl:choose>
237 <xsl:when test="@role = 'nodump'"/>
238 <xsl:otherwise>
239 <xsl:if test="@role = 'root'">
240 <xsl:text>sudo </xsl:text>
241 </xsl:if>
242 <xsl:apply-templates select="userinput" mode="screen"/>
243 </xsl:otherwise>
244 </xsl:choose>
245 </xsl:if>
246 </xsl:template>
247
248 <xsl:template match="para/command">
249 <xsl:if test="(contains(string(),'test') or
250 contains(string(),'check'))">
251 <xsl:text>#</xsl:text>
252 <xsl:value-of select="substring-before(string(),'make')"/>
253 <xsl:text>make -k</xsl:text>
254 <xsl:value-of select="substring-after(string(),'make')"/>
255 <xsl:text> || true&#xA;</xsl:text>
256 </xsl:if>
257 </xsl:template>
258
259 <xsl:template match="userinput" mode="screen">
260 <xsl:apply-templates/>
261 <xsl:text>&#xA;</xsl:text>
262 </xsl:template>
263
264 <xsl:template match="replaceable">
265 <xsl:text>**EDITME</xsl:text>
266 <xsl:apply-templates/>
267 <xsl:text>EDITME**</xsl:text>
268 </xsl:template>
269
270</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.