source: BLFS/libs/scripts.xsl@ 6e4e0dd

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

Bug and typo fix.

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