source: BLFS/gen-special.sh@ fbbe081

ablfs-more legacy trunk
Last change on this file since fbbe081 was c2af9cd7, checked in by Pierre Labastie <pierre.labastie@…>, 3 years ago

Fix gen-special when an entity is commented out:

In the xorg application, mkfontdir is commented out, but we did not
check that because it was complicated with the shell. This was
leading to mkfontfir appearing in the packages to install, which
is not wanted. We use the information in the "cat" command to
eliminate the commented out package.

  • Property mode set to 100755
File size: 10.7 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 \
42initramfs xorg-env kde-pre-install-config kf5-intro \
43lxqt-pre-install lxqt-post-install ojdk-conf tex-path"
44
45cat >$SPECIAL_FILE << EOF
46<?xml version="1.0" encoding="ISO-8859-1"?>
47
48<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
49 version="1.0">
50
51<xsl:template match='*' mode="special">
52 <xsl:choose>
53<!-- Although versioned, this page is not a package. But
54 the sect2 with id "xorg-env" is referred to at several
55 places in the book. We have added it to the list of non
56 versioned packages. -->
57 <xsl:when test="@id='xorg7'">
58 <xsl:apply-templates select="child::sect2" mode="special"/>
59 </xsl:when>
60EOF
61
62# Non-versionned packages. Add to NV_LIST if you need more.
63for nv_id in $NV_LIST; do
64 cat >>$SPECIAL_FILE << EOF
65 <xsl:when test="@id='$nv_id'">
66 <xsl:text> </xsl:text>
67 <package><xsl:text>&#xA; </xsl:text>
68 <xsl:element name="name">$nv_id</xsl:element>
69 <xsl:text>&#xA; </xsl:text>
70 <xsl:element name="version">1.0.0</xsl:element>
71 <xsl:if
72 test="document(\$installed-packages)//package[name=current()/@id]">
73 <xsl:text>&#xA; </xsl:text>
74 <xsl:element name="inst-version">
75 <xsl:value-of
76 select="document(\$installed-packages
77 )//package[name=current()/@id]/version"/>
78 </xsl:element>
79 </xsl:if>
80<!-- Dependencies -->
81 <xsl:apply-templates select=".//para[@role='required' or
82 @role='recommended' or
83 @role='optional']"
84 mode="dependency"/>
85<!-- End dependencies -->
86 <xsl:text>&#xA; </xsl:text>
87 </package><xsl:text>&#xA;</xsl:text>
88 </xsl:when>
89EOF
90done
91
92# Taking packages inside x7proto etc, as versionned modules.
93# We also write a dependency expansion when a dep is of the form
94# xorg7-something. Since that is another template, we need
95# a temporary file, which we shall concatenate at the end
96cat >tmpfile << EOF
97 <xsl:template name="expand-deps">
98 <xsl:param name="section"/>
99 <xsl:param name="status"/>
100 <xsl:param name="build"/>
101 <xsl:choose>
102EOF
103for file in $(ls ${BLFS_DIR}/x/installing/x7* | grep -v x7driver); do
104 id=$(grep xreflabel $file | sed 's@.*id="\([^"]*\).*@\1@')
105 cat >>$SPECIAL_FILE << EOF
106 <xsl:when test="@id='$id'">
107 <xsl:text> </xsl:text>
108 <package><xsl:text>&#xA; </xsl:text>
109 <xsl:element name="name">$id</xsl:element>
110 <xsl:text>&#xA; </xsl:text>
111EOF
112 cat >> tmpfile << EOF
113 <xsl:when test="\$section='$id'">
114EOF
115# We extract the list of packages for an xorg page from
116# the version part of the .xml file. Seems that
117# the order is not always the same as in the "cat" command.
118# So we have to read that command too, since it may be assumed
119# that the preceding package is a dependency of the following,
120# except the first.
121 list_cat="$(sed -n '/>cat/,/EOF</p' $file | grep -v 'cat\|EOF' |
122 awk '{ print $NF }' | sed 's/-&.*//')"
123
124# Rationale for the sed below: the following for breaks words at spaces (unless
125# we tweak IFS). So replace spaces with commas in lines so that only newlines
126# are separators.
127 for pack in \
128 $(grep 'ENTITY.*version' $file | sed 's/[ ]\+/,/g'); do
129 packname=$(echo $pack | sed s'@.*ENTITY,\(.*\)-version.*@\1@')
130 packversion=$(echo $pack | sed 's@[^"]*"\([^"]*\).*@\1@')
131 precpack=NONE
132 for i in $list_cat; do
133 if [ "$i" = "$packname" ]; then break; fi
134 precpack=$i
135 done
136# It may happen that packname is not in list_cat, because its entity
137# is commented out in the xml, but we do not check that (too complicated).
138# In that case, the whole list is scanned, and $precpack=$i at the end.
139# when packname is found in the list $precpack!=$i.
140 if [ "$precpack" = "$i" ]; then continue; fi
141 cat >>$SPECIAL_FILE << EOF
142 <module><xsl:text>&#xA; </xsl:text>
143 <xsl:element name="name">$packname</xsl:element>
144 <xsl:element name="version">$packversion</xsl:element>
145 <xsl:if test="document(\$installed-packages)//package[name='$packname']">
146 <xsl:element name="inst-version">
147 <xsl:value-of
148 select="document(\$installed-packages
149 )//package[name='$packname']/version"/>
150 </xsl:element>
151 </xsl:if>
152<!-- Dependencies -->
153EOF
154 if test $precpack != NONE; then
155 cat >>$SPECIAL_FILE << EOF
156 <xsl:element name="dependency">
157 <xsl:attribute name="status">required</xsl:attribute>
158 <xsl:attribute name="build">before</xsl:attribute>
159 <xsl:attribute name="name">$precpack</xsl:attribute>
160 <xsl:attribute name="type">ref</xsl:attribute>
161 </xsl:element>
162EOF
163 else
164 cat >>$SPECIAL_FILE << EOF
165 <xsl:apply-templates select=".//para[@role='required' or
166 @role='recommended' or
167 @role='optional']"
168 mode="dependency"/>
169EOF
170 fi
171 cat >>$SPECIAL_FILE << EOF
172<!-- End dependencies -->
173 </module>
174EOF
175 cat >> tmpfile << EOF
176 <xsl:element name="dependency">
177 <xsl:attribute name="status">
178 <xsl:value-of select="\$status"/>
179 </xsl:attribute>
180 <xsl:attribute name="build">
181 <xsl:value-of select="\$build"/>
182 </xsl:attribute>
183 <xsl:attribute name="name">$packname</xsl:attribute>
184 <xsl:attribute name="type">ref</xsl:attribute>
185 </xsl:element>
186EOF
187 done
188 cat >>$SPECIAL_FILE << EOF
189 </package>
190 </xsl:when>
191EOF
192 cat >> tmpfile << EOF
193 </xsl:when>
194EOF
195done
196
197for ver_ent in $EXCEPTIONS; do
198 id=$(grep 'xreflabel=".*'$ver_ent $BLFS_XML | sed 's@.*id="\([^"]*\)".*@\1@')
199 [[ -z $id ]] && continue
200 cat >>$SPECIAL_FILE << EOF
201 <xsl:when test="@id='$id'">
202<!-- if there is a sect1 ancestor, we have a module -->
203 <xsl:choose>
204 <xsl:when test="ancestor::sect1">
205 <xsl:text> </xsl:text>
206 <module><xsl:text>&#xA; </xsl:text>
207 <xsl:element name="name">$id</xsl:element>
208 <xsl:text>&#xA; </xsl:text>
209 <xsl:element name="version">$ver_ent</xsl:element>
210 <xsl:if
211 test="document(\$installed-packages)//package[name=current()/@id]">
212 <xsl:text>&#xA; </xsl:text>
213 <xsl:element name="inst-version">
214 <xsl:value-of
215 select="document(\$installed-packages
216 )//package[name=current()/@id]/version"/>
217 </xsl:element>
218 </xsl:if>
219<!-- Dependencies -->
220 <xsl:apply-templates select=".//para[@role='required' or
221 @role='recommended' or
222 @role='optional']"
223 mode="dependency"/>
224<!-- End dependencies -->
225 <xsl:text>&#xA; </xsl:text>
226 </module><xsl:text>&#xA;</xsl:text>
227 </xsl:when>
228 <xsl:otherwise>
229 <xsl:text> </xsl:text>
230 <package><xsl:text>&#xA; </xsl:text>
231 <xsl:element name="name">$id</xsl:element>
232 <xsl:text>&#xA; </xsl:text>
233 <xsl:element name="version">$ver_ent</xsl:element>
234 <xsl:if
235 test="document(\$installed-packages)//package[name=current()/@id]">
236 <xsl:text>&#xA; </xsl:text>
237 <xsl:element name="inst-version">
238 <xsl:value-of
239 select="document(\$installed-packages
240 )//package[name=current()/@id]/version"/>
241 </xsl:element>
242 </xsl:if>
243<!-- Dependencies -->
244 <xsl:apply-templates select=".//para[@role='required' or
245 @role='recommended' or
246 @role='optional']"
247 mode="dependency"/>
248<!-- End dependencies -->
249 <xsl:text>&#xA; </xsl:text>
250 </package><xsl:text>&#xA;</xsl:text>
251 </xsl:otherwise>
252 </xsl:choose>
253 </xsl:when>
254EOF
255done
256
257cat >>$SPECIAL_FILE << EOF
258 <xsl:otherwise>
259 <xsl:apply-templates
260 select="self::node()[contains(translate(@xreflabel,
261 '123456789',
262 '000000000'),
263 '-0')
264 ]"
265 mode="normal"/>
266 </xsl:otherwise>
267 </xsl:choose>
268</xsl:template>
269EOF
270cat $SPECIAL_FILE tmpfile > tmpfile1
271mv tmpfile1 $SPECIAL_FILE
272rm tmpfile
273cat >> $SPECIAL_FILE << EOF
274 <xsl:otherwise>
275 <xsl:message>
276 <xsl:text>You should not be seeing this</xsl:text>
277 </xsl:message>
278 </xsl:otherwise>
279 </xsl:choose>
280</xsl:template>
281</xsl:stylesheet>
282EOF
Note: See TracBrowser for help on using the repository browser.