source: BLFS/gen-special.sh@ 1646303

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

A module can be a special case, too (perl-test-mockmodule)

  • Property mode set to 100755
File size: 11.5 KB
Line 
1#!/bin/bash
2
3# $Id$
4
5#-------------------------------------------------------------------------
6# generates an xsl stylesheet containing a template for special
7# cases in the book:
8# - If the version does not begin with a number, it is impossible to know
9# where the package name ends and where the version begins. We therefore
10# use the ENTITY at the beginning of the validated full-xml.
11# - If a package is part of a group of xorg packages (proto, fonts, etc)
12# there is no easy way to extract it from the xml. We use the ENTITY at
13# the top of each file x7*.xml
14# - Some non-versioned packages are needed as dependencies of others: we
15# attribute version 1.0.0 to them. It is just used to know if the package
16# is installed, by checking inst-version.
17# - If a package is versioned but the version is not mentioned in the book
18# (currently only udev), we retrieve the version by other means
19#-------------------------------------------------------------------------
20# Arguments:
21# $1 contains the name of the validated xml book
22# $2 contains the name of the ouput xsl file
23# $3 contains the name of the book sources directory
24#-------------------------------------------------------------------------
25
26BLFS_XML=$1
27if ! test -f ${BLFS_XML}; then
28 echo File \`${BLFS_XML}\' does not exist
29 exit 1
30fi
31SPECIAL_FILE=$2
32if test -z "${SPECIAL_FILE}"; then SPECIAL_FILE=specialCases.xsl;fi
33BLFS_DIR=$3
34if test -z "${BLFS_DIR}"; then BLFS_DIR=$(cd $(dirname ${BLFS_XML})/.. ; pwd);fi
35
36# Packages whose version does not begin with a number
37EXCEPTIONS=$(grep 'ENTITY.*version[ ]*"[^0-9"&.].*[0-9]' ${BLFS_DIR}/packages.ent |
38 sed 's@^[^"]*"\([^"]*\)".*@\1@')
39
40# Non-versioned packages:
41NV_LIST="postlfs-config-profile postlfs-config-random postlfs-config-vimrc \
42xorg-env kde-pre-install-config kf5-intro \
43lxqt-pre-install lxqt-post-install ojdk-conf tex-path"
44
45# Set PATH to be sure to find udevadm
46SAVPATH=$PATH
47PATH=/bin:/sbin:/usr/bin:/usr/sbin
48UDEVVERSION=$(udevadm --version)
49
50cat >$SPECIAL_FILE << EOF
51<?xml version="1.0" encoding="ISO-8859-1"?>
52
53<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
54 version="1.0">
55
56<xsl:template match='*' mode="special">
57 <xsl:choose>
58 <xsl:when test="contains(@id,'udev')">
59 <xsl:text> </xsl:text>
60 <package><xsl:text>&#xA; </xsl:text>
61 <xsl:element name="name"><xsl:value-of select="@id"/></xsl:element>
62 <xsl:text>&#xA; </xsl:text>
63 <xsl:element name="version">$UDEVVERSION</xsl:element>
64 <xsl:if
65 test="document(\$installed-packages)//package[name=current()/@id]">
66 <xsl:text>&#xA; </xsl:text>
67 <xsl:element name="inst-version">
68 <xsl:value-of
69 select="document(\$installed-packages
70 )//package[name=current()/@id]/version"/>
71 </xsl:element>
72 </xsl:if>
73<!-- Dependencies -->
74 <xsl:apply-templates select=".//para[@role='required' or
75 @role='recommended' or
76 @role='optional']"
77 mode="dependency"/>
78<!-- End dependencies -->
79 <xsl:text>&#xA; </xsl:text>
80 </package><xsl:text>&#xA;</xsl:text>
81 </xsl:when>
82<!-- Although versioned, this page is not a package. But
83 the sect2 with id "xorg-env" is referred to at several
84 places in the book. We have added it to the list of non
85 versioned packages. -->
86 <xsl:when test="@id='xorg7'">
87 <xsl:apply-templates select="child::sect2" mode="special"/>
88 </xsl:when>
89EOF
90
91# Non-versionned packages. Add to NV_LIST if you need more.
92for nv_id in $NV_LIST; do
93 cat >>$SPECIAL_FILE << EOF
94 <xsl:when test="@id='$nv_id'">
95 <xsl:text> </xsl:text>
96 <package><xsl:text>&#xA; </xsl:text>
97 <xsl:element name="name">$nv_id</xsl:element>
98 <xsl:text>&#xA; </xsl:text>
99 <xsl:element name="version">1.0.0</xsl:element>
100 <xsl:if
101 test="document(\$installed-packages)//package[name=current()/@id]">
102 <xsl:text>&#xA; </xsl:text>
103 <xsl:element name="inst-version">
104 <xsl:value-of
105 select="document(\$installed-packages
106 )//package[name=current()/@id]/version"/>
107 </xsl:element>
108 </xsl:if>
109<!-- Dependencies -->
110 <xsl:apply-templates select=".//para[@role='required' or
111 @role='recommended' or
112 @role='optional']"
113 mode="dependency"/>
114<!-- End dependencies -->
115 <xsl:text>&#xA; </xsl:text>
116 </package><xsl:text>&#xA;</xsl:text>
117 </xsl:when>
118EOF
119done
120
121# Taking packages inside x7proto etc, as versionned modules.
122# We also write a dependency expansion when a dep is of the form
123# xorg7-something. Since that is another template, we need
124# a temporary file, which we shall concatenate at the end
125cat >tmpfile << EOF
126 <xsl:template name="expand-deps">
127 <xsl:param name="section"/>
128 <xsl:param name="status"/>
129 <xsl:param name="build"/>
130 <xsl:choose>
131EOF
132for file in $(ls ${BLFS_DIR}/x/installing/x7* | grep -v x7driver); do
133 id=$(grep xreflabel $file | sed 's@.*id="\([^"]*\).*@\1@')
134 cat >>$SPECIAL_FILE << EOF
135 <xsl:when test="@id='$id'">
136 <xsl:text> </xsl:text>
137 <package><xsl:text>&#xA; </xsl:text>
138 <xsl:element name="name">$id</xsl:element>
139 <xsl:text>&#xA; </xsl:text>
140EOF
141 cat >> tmpfile << EOF
142 <xsl:when test="\$section='$id'">
143EOF
144# We extract the list of packages for an xorg page from
145# the version part of the .xml file. Seems that
146# the order is not always the same as in the "cat" command.
147# So we have to read that command too, since it may be assumed
148# that the preceding package is a dependency of the following,
149# except the first.
150 list_cat="$(sed -n '/>cat/,/EOF</p' $file | grep -v 'cat\|EOF' |
151 awk '{ print $NF }' | sed 's/-&.*//')"
152
153# Rationale for the sed below: the following for breaks words at spaces (unless
154# we tweak IFS). So replace spaces with commas in lines so that only newlines
155# are separators.
156 for pack in \
157 $(grep 'ENTITY.*version' $file | sed 's/[ ]\+/,/g'); do
158 packname=$(echo $pack | sed s'@.*ENTITY,\(.*\)-version.*@\1@')
159 packversion=$(echo $pack | sed 's@[^"]*"\([^"]*\).*@\1@')
160 precpack=NONE
161 for i in $list_cat; do
162 if [ "$i" = "$packname" ]; then break; fi
163 precpack=$i
164 done
165
166 cat >>$SPECIAL_FILE << EOF
167 <module><xsl:text>&#xA; </xsl:text>
168 <xsl:element name="name">$packname</xsl:element>
169 <xsl:element name="version">$packversion</xsl:element>
170 <xsl:if test="document(\$installed-packages)//package[name='$packname']">
171 <xsl:element name="inst-version">
172 <xsl:value-of
173 select="document(\$installed-packages
174 )//package[name='$packname']/version"/>
175 </xsl:element>
176 </xsl:if>
177<!-- Dependencies -->
178EOF
179 if test $precpack != NONE; then
180 cat >>$SPECIAL_FILE << EOF
181 <xsl:element name="dependency">
182 <xsl:attribute name="status">required</xsl:attribute>
183 <xsl:attribute name="build">before</xsl:attribute>
184 <xsl:attribute name="name">$precpack</xsl:attribute>
185 <xsl:attribute name="type">ref</xsl:attribute>
186 </xsl:element>
187EOF
188 else
189 cat >>$SPECIAL_FILE << EOF
190 <xsl:apply-templates select=".//para[@role='required' or
191 @role='recommended' or
192 @role='optional']"
193 mode="dependency"/>
194EOF
195 fi
196 cat >>$SPECIAL_FILE << EOF
197<!-- End dependencies -->
198 </module>
199EOF
200 cat >> tmpfile << EOF
201 <xsl:element name="dependency">
202 <xsl:attribute name="status">
203 <xsl:value-of select="\$status"/>
204 </xsl:attribute>
205 <xsl:attribute name="build">
206 <xsl:value-of select="\$build"/>
207 </xsl:attribute>
208 <xsl:attribute name="name">$packname</xsl:attribute>
209 <xsl:attribute name="type">ref</xsl:attribute>
210 </xsl:element>
211EOF
212 done
213 cat >>$SPECIAL_FILE << EOF
214 </package>
215 </xsl:when>
216EOF
217 cat >> tmpfile << EOF
218 </xsl:when>
219EOF
220done
221
222for ver_ent in $EXCEPTIONS; do
223 id=$(grep 'xreflabel=".*'$ver_ent $BLFS_XML | sed 's@.*id="\([^"]*\)".*@\1@')
224 [[ -z $id ]] && continue
225 cat >>$SPECIAL_FILE << EOF
226 <xsl:when test="@id='$id'">
227<!-- if there is a sect1 ancestor, we have a module -->
228 <xsl:choose>
229 <xsl:when test="ancestor::sect1">
230 <xsl:text> </xsl:text>
231 <module><xsl:text>&#xA; </xsl:text>
232 <xsl:element name="name">$id</xsl:element>
233 <xsl:text>&#xA; </xsl:text>
234 <xsl:element name="version">$ver_ent</xsl:element>
235 <xsl:if
236 test="document(\$installed-packages)//package[name=current()/@id]">
237 <xsl:text>&#xA; </xsl:text>
238 <xsl:element name="inst-version">
239 <xsl:value-of
240 select="document(\$installed-packages
241 )//package[name=current()/@id]/version"/>
242 </xsl:element>
243 </xsl:if>
244<!-- Dependencies -->
245 <xsl:apply-templates select=".//para[@role='required' or
246 @role='recommended' or
247 @role='optional']"
248 mode="dependency"/>
249<!-- End dependencies -->
250 <xsl:text>&#xA; </xsl:text>
251 </module><xsl:text>&#xA;</xsl:text>
252 </xsl:when>
253 <xsl:otherwise>
254 <xsl:text> </xsl:text>
255 <package><xsl:text>&#xA; </xsl:text>
256 <xsl:element name="name">$id</xsl:element>
257 <xsl:text>&#xA; </xsl:text>
258 <xsl:element name="version">$ver_ent</xsl:element>
259 <xsl:if
260 test="document(\$installed-packages)//package[name=current()/@id]">
261 <xsl:text>&#xA; </xsl:text>
262 <xsl:element name="inst-version">
263 <xsl:value-of
264 select="document(\$installed-packages
265 )//package[name=current()/@id]/version"/>
266 </xsl:element>
267 </xsl:if>
268<!-- Dependencies -->
269 <xsl:apply-templates select=".//para[@role='required' or
270 @role='recommended' or
271 @role='optional']"
272 mode="dependency"/>
273<!-- End dependencies -->
274 <xsl:text>&#xA; </xsl:text>
275 </package><xsl:text>&#xA;</xsl:text>
276 </xsl:otherwise>
277 </xsl:choose>
278 </xsl:when>
279EOF
280done
281
282cat >>$SPECIAL_FILE << EOF
283 <xsl:otherwise>
284 <xsl:apply-templates
285 select="self::node()[contains(translate(@xreflabel,
286 '123456789',
287 '000000000'),
288 '-0')
289 ]"
290 mode="normal"/>
291 </xsl:otherwise>
292 </xsl:choose>
293</xsl:template>
294EOF
295cat $SPECIAL_FILE tmpfile > tmpfile1
296mv tmpfile1 $SPECIAL_FILE
297rm tmpfile
298cat >> $SPECIAL_FILE << EOF
299 <xsl:otherwise>
300 <xsl:message>
301 <xsl:text>You should not be seeing this</xsl:text>
302 </xsl:message>
303 </xsl:otherwise>
304 </xsl:choose>
305</xsl:template>
306</xsl:stylesheet>
307EOF
Note: See TracBrowser for help on using the repository browser.