source: BLFS/gen-special.sh@ e6a1ec3

ablfs-more trunk
Last change on this file since e6a1ec3 was e6a1ec3, checked in by Pierre Labastie <pierre.labastie@…>, 14 months ago

Update comments in BLFS/gen-special.sh

Also change a %%-:digit:]* to %-[[:digit:* because we want to
select only the last occurrence of this pattern.

  • Property mode set to 100755
File size: 10.8 KB
Line 
1#!/bin/bash
2
3#-------------------------------------------------------------------------
4# generates an xsl stylesheet containing a template for special
5# cases in the book:
6# - If the version does not begin with a number, it is impossible to know
7# where the package name ends and where the version begins. We therefore
8# use the ENTITY at the beginning of the validated full-xml.
9# - If a package is part of a group of xorg packages (proto, fonts, etc)
10# there is no easy way to extract it from the xml. We use the ENTITY at
11# the top of each file x7*.xml
12# - Some non-versioned packages are needed as dependencies of others: we
13# attribute version 1.0.0 to them. It is just used to know if the package
14# is installed, by checking inst-version.
15# - If a package is versioned but the version is not mentioned in the book
16# (currently only udev), we retrieve the version by other means
17#-------------------------------------------------------------------------
18# Arguments:
19# $1 contains the name of the validated xml book
20# $2 contains the name of the ouput xsl file
21# $3 contains the name of the book sources directory
22#-------------------------------------------------------------------------
23
24BLFS_XML=$1
25if ! test -f ${BLFS_XML}; then
26 echo File \`${BLFS_XML}\' does not exist
27 exit 1
28fi
29SPECIAL_FILE=$2
30if test -z "${SPECIAL_FILE}"; then SPECIAL_FILE=specialCases.xsl;fi
31BLFS_DIR=$3
32if test -z "${BLFS_DIR}"; then BLFS_DIR=$(cd $(dirname ${BLFS_XML})/.. ; pwd);fi
33
34# Packages whose version does not begin with a number
35EXCEPTIONS=$(grep 'ENTITY.*version[ ]*"[^0-9"&.].*[0-9]' ${BLFS_DIR}/packages.ent |
36 sed 's@^[^"]*"\([^"]*\)".*@\1@')
37
38# Non-versioned packages:
39NV_LIST="postlfs-config-profile postlfs-config-random postlfs-config-vimrc \
40initramfs xorg-env kde-pre-install-config kf5-intro \
41lxqt-pre-install lxqt-post-install ojdk-conf tex-path"
42
43cat >$SPECIAL_FILE << EOF
44<?xml version="1.0" encoding="ISO-8859-1"?>
45
46<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
47 version="1.0">
48
49<xsl:template match='*' mode="special">
50 <xsl:choose>
51<!-- Although versioned, this page is not a package. But
52 the sect2 with id "xorg-env" is referred to at several
53 places in the book. We have added it to the list of non
54 versioned packages. -->
55 <xsl:when test="@id='xorg7'">
56 <xsl:apply-templates select="child::sect2" mode="special"/>
57 </xsl:when>
58EOF
59
60# Non-versionned packages. Add to NV_LIST if you need more.
61for nv_id in $NV_LIST; do
62 cat >>$SPECIAL_FILE << EOF
63 <xsl:when test="@id='$nv_id'">
64 <xsl:text> </xsl:text>
65 <package><xsl:text>&#xA; </xsl:text>
66 <xsl:element name="name">$nv_id</xsl:element>
67 <xsl:text>&#xA; </xsl:text>
68 <xsl:element name="version">1.0.0</xsl:element>
69 <xsl:if
70 test="document(\$installed-packages)//package[name=current()/@id]">
71 <xsl:text>&#xA; </xsl:text>
72 <xsl:element name="inst-version">
73 <xsl:value-of
74 select="document(\$installed-packages
75 )//package[name=current()/@id]/version"/>
76 </xsl:element>
77 </xsl:if>
78<!-- Dependencies -->
79 <xsl:apply-templates select=".//para[@role='required' or
80 @role='recommended' or
81 @role='optional']"
82 mode="dependency"/>
83<!-- End dependencies -->
84 <xsl:text>&#xA; </xsl:text>
85 </package><xsl:text>&#xA;</xsl:text>
86 </xsl:when>
87EOF
88done
89
90# Taking packages contained in pages installing several packages (x7* except
91# x7driver, kf5-frameworks, and plasma5-all), as versionned modules.
92# We also write a dependency expansion when a dep is of the form
93# xorg7-something or kf5-frameworks or plasma5-build. Since that is another
94# template, we need a temporary file, which we shall concatenate at the end
95cat >tmpfile << EOF
96 <xsl:template name="expand-deps">
97 <xsl:param name="section"/>
98 <xsl:param name="status"/>
99 <xsl:param name="build"/>
100 <xsl:choose>
101EOF
102for file in $(ls ${BLFS_DIR}/x/installing/x7* | grep -v x7driver) \
103 ${BLFS_DIR}/kde/kf5/kf5-frameworks.xml \
104 ${BLFS_DIR}/kde/plasma5/plasma-all.xml; do
105 id=$(grep xreflabel $file | sed 's@.*id="\([^"]*\).*@\1@')
106 cat >>$SPECIAL_FILE << EOF
107 <xsl:when test="@id='$id'">
108 <xsl:text> </xsl:text>
109 <package><xsl:text>&#xA; </xsl:text>
110 <xsl:element name="name">$id</xsl:element>
111 <xsl:text>&#xA; </xsl:text>
112EOF
113 cat >> tmpfile << EOF
114 <xsl:when test="\$section='$id'">
115EOF
116# We extract the list of packages for those pages from
117# the "cat" command that creates the md5 file. We assume
118# that the preceding package is a dependency of the following,
119# except the first.
120# note that some pages may have several "cat" command, so we have to
121# make a complex regex for the first line to save. All those lines have
122# .md5 in them except the one for x7legacy that has .dat.
123# we need also to remove lines beginning with #.
124# Note that only xorg pages have '&' in them. So for kde
125# pages, what is extracted it the full tarball name.
126list_cat="$(sed -n '/>cat.*\.\(md5\|dat\)/,/EOF</p' $file | \
127 grep -v 'cat\|EOF\|#' | \
128 awk '{ print $NF }' | sed 's/-&.*//')"
129
130 precpack=NONE
131 for pack in $list_cat; do
132 if grep -q x7 $file; then # this is an xorg package
133 packname=$pack
134# We extract the version from the ENTITY parts of the .xml file.
135 packversion=$(grep "ENTITY ${pack}-version" $file | \
136 sed 's@[^"]*"\([^"]*\).*@\1@')
137 else
138 packname=${pack%-[[:digit:]]*}
139 packversion=$(echo $pack | sed 's/[^.]*-\([.[:digit:]]*\)\.tar.*/\1/')
140 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 precpack=$packname
188 done
189 cat >>$SPECIAL_FILE << EOF
190 </package>
191 </xsl:when>
192EOF
193 cat >> tmpfile << EOF
194 </xsl:when>
195EOF
196done
197
198for ver_ent in $EXCEPTIONS; do
199 id=$(grep 'xreflabel=".*'$ver_ent $BLFS_XML | sed 's@.*id="\([^"]*\)".*@\1@')
200 [[ -z $id ]] && continue
201 cat >>$SPECIAL_FILE << EOF
202 <xsl:when test="@id='$id'">
203<!-- if there is a sect1 ancestor, we have a module -->
204 <xsl:choose>
205 <xsl:when test="ancestor::sect1">
206 <xsl:text> </xsl:text>
207 <module><xsl:text>&#xA; </xsl:text>
208 <xsl:element name="name">$id</xsl:element>
209 <xsl:text>&#xA; </xsl:text>
210 <xsl:element name="version">$ver_ent</xsl:element>
211 <xsl:if
212 test="document(\$installed-packages)//package[name=current()/@id]">
213 <xsl:text>&#xA; </xsl:text>
214 <xsl:element name="inst-version">
215 <xsl:value-of
216 select="document(\$installed-packages
217 )//package[name=current()/@id]/version"/>
218 </xsl:element>
219 </xsl:if>
220<!-- Dependencies -->
221 <xsl:apply-templates select=".//para[@role='required' or
222 @role='recommended' or
223 @role='optional']"
224 mode="dependency"/>
225<!-- End dependencies -->
226 <xsl:text>&#xA; </xsl:text>
227 </module><xsl:text>&#xA;</xsl:text>
228 </xsl:when>
229 <xsl:otherwise>
230 <xsl:text> </xsl:text>
231 <package><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 </package><xsl:text>&#xA;</xsl:text>
252 </xsl:otherwise>
253 </xsl:choose>
254 </xsl:when>
255EOF
256done
257
258cat >>$SPECIAL_FILE << EOF
259 <xsl:otherwise>
260 <xsl:apply-templates
261 select="self::node()[contains(translate(@xreflabel,
262 '123456789',
263 '000000000'),
264 '-0')
265 ]"
266 mode="normal"/>
267 </xsl:otherwise>
268 </xsl:choose>
269</xsl:template>
270EOF
271cat $SPECIAL_FILE tmpfile > tmpfile1
272mv tmpfile1 $SPECIAL_FILE
273rm tmpfile
274cat >> $SPECIAL_FILE << EOF
275 <xsl:otherwise>
276 <xsl:message>
277 <xsl:text>You should not be seeing this</xsl:text>
278 </xsl:message>
279 </xsl:otherwise>
280 </xsl:choose>
281</xsl:template>
282</xsl:stylesheet>
283EOF
Note: See TracBrowser for help on using the repository browser.