source: BLFS/xsl/process-install.xsl@ 7933ed7

ablfs-more legacy trunk
Last change on this file since 7933ed7 was 7933ed7, checked in by Pierre Labastie <pierre@…>, 5 years ago

Refactoring the output of installation instructions:

Create a template which processes the instruction tree fragment (only header
for now, the content is bogus), and call it from main sheet.

  • Property mode set to 100644
File size: 9.6 KB
Line 
1<?xml version="1.0" encoding="ISO-8859-1"?>
2
3<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
4 version="1.0">
5
6<!-- $Id: gen-install.xsl 4107 2019-06-15 15:26:23Z pierre $ -->
7
8 <xsl:template name="process-install">
9 <xsl:param name="instruction-tree"/>
10 <xsl:param name="want-stats"/>
11 <xsl:param name="root-seen"/>
12 <xsl:param name="install-seen"/>
13 <xsl:param name="test-seen"/>
14 <xsl:param name="doc-seen"/>
15
16<!-- "nature" variables:
17 - 'non-root': executable as user
18 - 'config': execute as root, with no special formatting
19 - 'install': execute as root, with PKG_DEST or escape instructions
20 - 'none': does not exist (for preceding of following uniquely)
21-->
22 <xsl:variable name="my-nature">
23 <xsl:choose>
24 <xsl:when test="not(@role)">
25 <xsl:text>non-root</xsl:text>
26 </xsl:when>
27 <xsl:when test="contains(string(),'useradd') or
28 contains(string(),'groupadd') or
29 contains(string(),'usermod') or
30 contains(string(),'icon-cache') or
31 contains(string(),'desktop-database') or
32 contains(string(),'compile-schemas') or
33 contains(string(),'query-loaders') or
34 contains(string(),'pam.d') or
35 contains(string(),'query-immodules')">
36 <xsl:text>config</xsl:text>
37 </xsl:when>
38 <xsl:otherwise>
39 <xsl:text>install</xsl:text>
40 </xsl:otherwise>
41 </xsl:choose>
42 </xsl:variable>
43
44 <xsl:variable
45 name="prec-screen"
46 select="preceding::screen[not(@role='nodump') and ./userinput][1]
47 [ancestor::sect2 = current()/ancestor::sect2]"/>
48
49 <xsl:variable
50 name="prec-string"
51 select="string($prec-screen)"/>
52
53<!--
54 <xsl:message>
55 <xsl:text>
56==============================
57List of preceding siblings for "</xsl:text>
58 <xsl:value-of select="./userinput"/>
59 <xsl:text>":
60</xsl:text>
61 <xsl:for-each select="preceding-sibling::screen[not(@role='nodump') and
62 ./userinput] |
63 preceding-sibling::para/command">
64 <xsl:copy-of select=".//text()"/>
65 <xsl:text>
66===
67</xsl:text>
68 </xsl:for-each>
69 </xsl:message>
70-->
71 <xsl:variable name="prec-nature">
72 <xsl:choose>
73 <xsl:when
74 test="$prec-string='' or
75 (preceding::screen[not(@role='nodump') and
76 ./userinput] |
77 preceding::command[contains(text(),'check') or
78 contains(text(),'test')]
79 )[last()][self::command]">
80 <xsl:text>none</xsl:text>
81 </xsl:when>
82 <xsl:when test="$prec-screen[not(@role)]">
83 <xsl:text>non-root</xsl:text>
84 </xsl:when>
85 <xsl:when test="contains($prec-string,'useradd') or
86 contains($prec-string,'groupadd') or
87 contains($prec-string,'usermod') or
88 contains($prec-string,'icon-cache') or
89 contains($prec-string,'desktop-database') or
90 contains($prec-string,'compile-schemas') or
91 contains($prec-string,'query-loaders') or
92 contains($prec-string,'pam.d') or
93 contains($prec-string,'query-immodules')">
94 <xsl:text>config</xsl:text>
95 </xsl:when>
96 <xsl:otherwise>
97 <xsl:text>install</xsl:text>
98 </xsl:otherwise>
99 </xsl:choose>
100 </xsl:variable>
101
102 <xsl:variable
103 name="follow-screen"
104 select="following::screen[not(@role='nodump') and ./userinput][1]
105 [ancestor::sect2 = current()/ancestor::sect2]"/>
106
107 <xsl:variable
108 name="follow-string"
109 select="string($follow-screen)"/>
110
111 <xsl:variable name="follow-nature">
112 <xsl:choose>
113 <xsl:when
114 test="$follow-string='' or
115 (following::screen[not(@role='nodump') and
116 ./userinput] |
117 following::command[contains(text(),'check') or
118 contains(text(),'test')]
119 )[1][self::command]">
120 <xsl:text>none</xsl:text>
121 </xsl:when>
122 <xsl:when test="$follow-screen[not(@role)]">
123 <xsl:text>non-root</xsl:text>
124 </xsl:when>
125 <xsl:when test="contains($follow-string,'useradd') or
126 contains($follow-string,'groupadd') or
127 contains($follow-string,'usermod') or
128 contains($follow-string,'icon-cache') or
129 contains($follow-string,'desktop-database') or
130 contains($follow-string,'compile-schemas') or
131 contains($follow-string,'query-loaders') or
132 contains($follow-string,'pam.d') or
133 contains($follow-string,'query-immodules')">
134 <xsl:text>config</xsl:text>
135 </xsl:when>
136 <xsl:otherwise>
137 <xsl:text>install</xsl:text>
138 </xsl:otherwise>
139 </xsl:choose>
140 </xsl:variable>
141
142 <xsl:choose>
143 <xsl:when test="$my-nature='non-root'">
144 <xsl:if test="$prec-nature='install'">
145 <xsl:call-template name="end-install"/>
146 <xsl:call-template name="end-root"/>
147 </xsl:if>
148 <xsl:if test="$prec-nature='config'">
149 <xsl:call-template name="end-root"/>
150 </xsl:if>
151 <xsl:apply-templates/>
152 </xsl:when>
153
154 <xsl:when test="$my-nature='config'">
155 <xsl:if test="$prec-nature='none' or $prec-nature='non-root'">
156 <xsl:call-template name="begin-root"/>
157 </xsl:if>
158 <xsl:if test="$prec-nature='install'">
159 <xsl:call-template name="end-install"/>
160 </xsl:if>
161 <xsl:apply-templates mode="root"/>
162 <xsl:if test="$follow-nature='none'">
163 <xsl:call-template name="end-root"/>
164 </xsl:if>
165 </xsl:when>
166
167 <xsl:when test="$my-nature='install'">
168 <xsl:if test="$prec-nature='none' or $prec-nature='non-root'">
169 <xsl:if test="$want-stats">
170 <xsl:call-template name="output-destdir"/>
171 </xsl:if>
172 <xsl:call-template name="begin-root"/>
173 <xsl:call-template name="begin-install"/>
174 </xsl:if>
175 <xsl:if test="$prec-nature='config'">
176 <xsl:if test="$want-stats">
177 <xsl:call-template name="end-root"/>
178 <xsl:call-template name="output-destdir"/>
179 <xsl:call-template name="begin-root"/>
180 </xsl:if>
181 <xsl:call-template name="begin-install"/>
182 </xsl:if>
183 <xsl:apply-templates mode="install"/>
184 <xsl:if test="$follow-nature='none'">
185 <xsl:call-template name="end-install"/>
186 <xsl:call-template name="end-root"/>
187 </xsl:if>
188 </xsl:when>
189
190 </xsl:choose>
191 </xsl:template>
192
193 <xsl:template name="begin-root">
194 <xsl:if test="$sudo='y'">
195 <xsl:text>
196sudo -E sh &lt;&lt; ROOT_EOF</xsl:text>
197 </xsl:if>
198 </xsl:template>
199
200 <xsl:template name="begin-install">
201 <xsl:if test="$wrap-install = 'y'">
202 <xsl:text>
203if [ -r "$JH_PACK_INSTALL" ]; then
204 source $JH_PACK_INSTALL
205 export -f wrapInstall
206 export -f packInstall
207fi
208wrapInstall '</xsl:text>
209 </xsl:if>
210 </xsl:template>
211
212 <xsl:template name="end-root">
213 <xsl:if test="$sudo='y'">
214 <xsl:text>
215ROOT_EOF</xsl:text>
216 </xsl:if>
217 </xsl:template>
218
219 <xsl:template name="end-install">
220 <xsl:if test="$del-la-files = 'y'">
221 <xsl:call-template name="output-root">
222 <xsl:with-param name="out-string" select="$la-files-instr"/>
223 </xsl:call-template>
224 </xsl:if>
225 <xsl:if test="$wrap-install = 'y'">
226 <xsl:text>'&#xA;packInstall</xsl:text>
227 </xsl:if>
228 </xsl:template>
229
230 <xsl:template match="userinput" mode="install">
231 <xsl:text>
232</xsl:text>
233 <xsl:call-template name="output-install">
234 <xsl:with-param name="out-string" select="string()"/>
235 </xsl:call-template>
236 </xsl:template>
237
238 <xsl:template name="output-install">
239 <xsl:param name="out-string" select="''"/>
240 <xsl:choose>
241 <xsl:when test="starts-with($out-string, 'make ') or
242 contains($out-string,' make ') or
243 contains($out-string,'&#xA;make')">
244 <xsl:call-template name="output-install">
245 <xsl:with-param
246 name="out-string"
247 select="substring-before($out-string,'make ')"/>
248 </xsl:call-template>
249 <xsl:text>make -j1 </xsl:text>
250 <xsl:call-template name="output-install">
251 <xsl:with-param
252 name="out-string"
253 select="substring-after($out-string,'make ')"/>
254 </xsl:call-template>
255 </xsl:when>
256 <xsl:when test="contains($out-string,string($APOS))
257 and $wrap-install = 'y'">
258 <xsl:call-template name="output-root">
259 <xsl:with-param
260 name="out-string"
261 select="substring-before($out-string,string($APOS))"/>
262 </xsl:call-template>
263 <xsl:text>'\''</xsl:text>
264 <xsl:call-template name="output-install">
265 <xsl:with-param name="out-string"
266 select="substring-after($out-string,string($APOS))"/>
267 </xsl:call-template>
268 </xsl:when>
269 <xsl:otherwise>
270 <xsl:call-template name="output-root">
271 <xsl:with-param name="out-string" select="$out-string"/>
272 </xsl:call-template>
273 </xsl:otherwise>
274 </xsl:choose>
275 </xsl:template>
276
277</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.