source: BLFS/libs/scripts.xsl@ 838b61a

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

Actually fixed the bug when generating scripts for non-package files, I think.

  • Property mode set to 100644
File size: 7.1 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 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 <!-- The file names -->
24 <xsl:variable name="pi-file" select="processing-instruction('dbhtml')"/>
25 <xsl:variable name="pi-file-value" select="substring-after($pi-file,'filename=')"/>
26 <xsl:variable name="filename" select="substring-before(substring($pi-file-value,2),'.html')"/>
27 <!-- Package variables BROKEN Need be fixed -->
28 <xsl:param name="package" select="sect1info/keywordset/keyword[@role='package']"/>
29 <xsl:param name="ftpdir" select="sect1info/keywordset/keyword[@role='ftpdir']"/>
30 <!-- The build order -->
31 <xsl:variable name="position" select="position()"/>
32 <xsl:variable name="order">
33 <xsl:choose>
34 <xsl:when test="string-length($position) = 1">
35 <xsl:text>00</xsl:text>
36 <xsl:value-of select="$position"/>
37 </xsl:when>
38 <xsl:when test="string-length($position) = 2">
39 <xsl:text>0</xsl:text>
40 <xsl:value-of select="$position"/>
41 </xsl:when>
42 <xsl:otherwise>
43 <xsl:value-of select="$position"/>
44 </xsl:otherwise>
45 </xsl:choose>
46 </xsl:variable>
47 <!-- Creating dirs and files -->
48 <exsl:document href="{$order}-{$filename}" method="text">
49 <xsl:text>#!/bin/sh&#xA;set -e&#xA;&#xA;</xsl:text>
50 <xsl:choose>
51 <xsl:when test="sect2[@role='package']">
52 <xsl:apply-templates select="sect2">
53 <xsl:with-param name="package" select="$package"/>
54 <xsl:with-param name="ftpdir" select="$ftpdir"/>
55 </xsl:apply-templates>
56 <xsl:if test="sect2[@role='package']">
57 <xsl:text>cd ~/sources/</xsl:text>
58 <xsl:value-of select="$ftpdir"/>
59 <xsl:text>&#xA;rm -rf $UNPACKDIR&#xA;&#xA;</xsl:text>
60 </xsl:if>
61 </xsl:when>
62 <xsl:otherwise>
63 <xsl:apply-templates select=".//screen"/>
64 </xsl:otherwise>
65 </xsl:choose>
66 <xsl:text>exit</xsl:text>
67 </exsl:document>
68 </xsl:if>
69 </xsl:template>
70
71<!--======================= Sub-sections code =======================-->
72
73 <xsl:template match="sect2">
74 <xsl:param name="package" select="foo"/>
75 <xsl:param name="ftpdir" select="foo"/>
76 <xsl:choose>
77 <xsl:when test="@role = 'package'">
78 <xsl:text>mkdir -p ~/sources/</xsl:text>
79 <xsl:value-of select="$ftpdir"/>
80 <xsl:text>&#xA;cd ~/sources/</xsl:text>
81 <xsl:value-of select="$ftpdir"/>
82 <xsl:text>&#xA;</xsl:text>
83 <xsl:apply-templates select="itemizedlist/listitem/para">
84 <xsl:with-param name="package" select="$package"/>
85 <xsl:with-param name="ftpdir" select="$ftpdir"/>
86 </xsl:apply-templates>
87 <xsl:text>&#xA;</xsl:text>
88 </xsl:when>
89 <xsl:when test="@role = 'installation'">
90 <xsl:text>tar -xvf </xsl:text>
91 <xsl:value-of select="$package"/>
92 <xsl:text> > /tmp/unpacked&#xA;</xsl:text>
93 <xsl:text>UNPACKDIR=`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'`&#xA;</xsl:text>
94 <xsl:text>cd $UNPACKDIR&#xA;</xsl:text>
95 <xsl:apply-templates select=".//screen | .//para/command"/>
96 <xsl:text>&#xA;</xsl:text>
97 </xsl:when>
98 <xsl:when test="@role = 'configuration'">
99 <xsl:apply-templates select=".//screen"/>
100 <xsl:text>&#xA;</xsl:text>
101 </xsl:when>
102 <xsl:otherwise/>
103 </xsl:choose>
104 </xsl:template>
105
106<!--==================== Download code =======================-->
107
108 <xsl:template match="itemizedlist/listitem/para">
109 <xsl:param name="package" select="foo"/>
110 <xsl:param name="ftpdir" select="foo"/>
111 <xsl:choose>
112 <xsl:when test="contains(string(),'HTTP')">
113 <!-- SRC_ARCHIVE may have subdirectories or not -->
114 <xsl:text>cp $SRC_ARCHIVE/</xsl:text>
115 <xsl:value-of select="$ftpdir"/>
116 <xsl:text>/</xsl:text>
117 <xsl:value-of select="$package"/>
118 <xsl:text> || \&#xA;</xsl:text>
119 <xsl:text>cp $SRC_ARCHIVE/</xsl:text>
120 <xsl:value-of select="$package"/>
121 <xsl:text> || \&#xA;</xsl:text>
122 <!-- The FTP_SERVER mirror -->
123 <xsl:text>wget $FTP_SERVER/BLFS/conglomeration/</xsl:text>
124 <xsl:value-of select="$ftpdir"/>
125 <xsl:text>/</xsl:text>
126 <xsl:value-of select="$package"/>
127 <xsl:text> || \&#xA;</xsl:text>
128 <!-- Upstream HTTP URL -->
129 <xsl:text>wget </xsl:text>
130 <xsl:value-of select="ulink/@url"/>
131 <xsl:text> || \&#xA;</xsl:text>
132 </xsl:when>
133 <xsl:when test="contains(string(),'FTP')">
134 <!-- Upstream FTP URL -->
135 <xsl:text>wget </xsl:text>
136 <xsl:value-of select="ulink/@url"/>
137 <xsl:text>&#xA;</xsl:text>
138 </xsl:when>
139 <xsl:when test="contains(string(),'MD5')">
140 <xsl:text>echo "</xsl:text>
141 <xsl:value-of select="substring-after(string(),'sum: ')"/>
142 <xsl:text>&#x20;&#x20;</xsl:text>
143 <xsl:value-of select="$package"/>
144 <xsl:text>" | md5sum -c -&#xA;</xsl:text>
145 </xsl:when>
146 <!-- Patches. Need be veryfied -->
147 <xsl:when test="contains(string(),'patch')">
148 <xsl:text>wget </xsl:text>
149 <xsl:value-of select="ulink/@url"/>
150 <xsl:text>&#xA;</xsl:text>
151 </xsl:when>
152 <xsl:otherwise/>
153 </xsl:choose>
154 </xsl:template>
155
156<!--======================== Commands code ==========================-->
157
158 <xsl:template match="screen">
159 <xsl:if test="child::* = userinput">
160 <xsl:choose>
161 <xsl:when test="@role = 'nodump'"/>
162 <xsl:otherwise>
163 <xsl:if test="@role = 'root'">
164 <xsl:text>sudo </xsl:text>
165 </xsl:if>
166 <xsl:apply-templates select="userinput" mode="screen"/>
167 </xsl:otherwise>
168 </xsl:choose>
169 </xsl:if>
170 </xsl:template>
171
172 <xsl:template match="para/command">
173 <xsl:if test="(contains(string(),'test') or
174 contains(string(),'check'))">
175 <xsl:text>#</xsl:text>
176 <xsl:value-of select="substring-before(string(),'make')"/>
177 <xsl:text>make -k</xsl:text>
178 <xsl:value-of select="substring-after(string(),'make')"/>
179 <xsl:text> || true&#xA;</xsl:text>
180 </xsl:if>
181 </xsl:template>
182
183 <xsl:template match="userinput" mode="screen">
184 <xsl:apply-templates/>
185 <xsl:text>&#xA;</xsl:text>
186 </xsl:template>
187
188 <xsl:template match="replaceable">
189 <xsl:text>**EDITME</xsl:text>
190 <xsl:apply-templates/>
191 <xsl:text>EDITME**</xsl:text>
192 </xsl:template>
193
194</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.