source: BLFS/gen-special.sh@ 0f7a988

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

Fix a sed for kf5-intro version

  • Property mode set to 100755
File size: 12.6 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# Actually, kf5-intro contains some version info, so should be
63# versioned. For other packages, we define version to 1.0.0
64# because the DTD needs a version tag.
65 DUM_VER=1.0.0
66 if [ $nv_id = kf5-intro ]; then
67 DUM_VER=$(grep kf5-version $BLFS_DIR/packages.ent | \
68 sed 's/[^"]*"\([^"]*\).*/\1/')
69 fi
70 cat >>$SPECIAL_FILE << EOF
71 <xsl:when test="@id='$nv_id'">
72 <xsl:text> </xsl:text>
73 <package><xsl:text>&#xA; </xsl:text>
74 <xsl:element name="name">$nv_id</xsl:element>
75 <xsl:text>&#xA; </xsl:text>
76 <xsl:element name="version">$DUM_VER</xsl:element>
77 <xsl:if
78 test="document(\$installed-packages)//package[name=current()/@id]">
79 <xsl:text>&#xA; </xsl:text>
80 <xsl:element name="inst-version">
81 <xsl:value-of
82 select="document(\$installed-packages
83 )//package[name=current()/@id]/version"/>
84 </xsl:element>
85 </xsl:if>
86<!-- Dependencies -->
87 <xsl:apply-templates select=".//para[@role='required' or
88 @role='recommended' or
89 @role='optional']"
90 mode="dependency"/>
91<!-- End dependencies -->
92 <xsl:text>&#xA; </xsl:text>
93 </package><xsl:text>&#xA;</xsl:text>
94 </xsl:when>
95EOF
96done
97
98# Taking packages contained in pages installing several packages (x7* except
99# x7driver, kf5-frameworks, and plasma5-all), as versionned modules.
100# We also write a dependency expansion when a dep is of the form
101# xorg7-something or kf5-frameworks or plasma5-build. Since that is another
102# template, we need a temporary file, which we shall concatenate at the end
103cat >tmpfile << EOF
104 <xsl:template name="expand-deps">
105 <xsl:param name="section"/>
106 <xsl:param name="status"/>
107 <xsl:param name="build"/>
108 <xsl:choose>
109EOF
110for file in $(ls ${BLFS_DIR}/x/installing/x7* | grep -v x7driver) \
111 ${BLFS_DIR}/kde/kf5/kf5-frameworks.xml \
112 ${BLFS_DIR}/kde/plasma5/plasma-all.xml; do
113 id=$(grep xreflabel $file | sed 's@.*id="\([^"]*\).*@\1@')
114 cat >>$SPECIAL_FILE << EOF
115 <xsl:when test="@id='$id'">
116 <xsl:text> </xsl:text>
117 <package><xsl:text>&#xA; </xsl:text>
118 <xsl:element name="name">$id</xsl:element>
119 <xsl:text>&#xA; </xsl:text>
120EOF
121 cat >> tmpfile << EOF
122 <xsl:when test="\$section='$id'">
123EOF
124# We extract the list of packages for those pages from
125# the "cat" command that creates the md5 file. We assume
126# that the preceding package is a dependency of the following,
127# except the first.
128# note that some pages may have several "cat" command, so we have to
129# make a complex regex for the first line to save. All those lines have
130# .md5 in them except the one for x7legacy that has .dat.
131# we need also to remove lines beginning with #.
132# Note that only xorg pages have '&' in them. So for kde
133# pages, what is extracted it the full tarball name.
134 list_cat="$(sed -n '/>cat.*\.\(md5\|dat\)/,/EOF</p' $file | \
135 grep -v '>cat\|EOF<\|#' | \
136 awk '{ print $NF }' | sed 's/-&.*//')"
137
138 precpack=NONE
139 for pack in $list_cat; do
140 if grep -q x7 $file; then # this is an xorg package
141 packname=$pack
142# We extract the version from the ENTITY parts of the .xml file.
143 packversion=$(grep "ENTITY ${pack}-version" $file | \
144 sed 's@[^"]*"\([^"]*\).*@\1@')
145 else
146 packname=${pack%-[[:digit:]]*}
147 packversion=$(echo $pack | sed 's/[^.]*-\([.[:digit:]]*\)\.tar.*/\1/')
148 fi
149 cat >>$SPECIAL_FILE << EOF
150 <module><xsl:text>&#xA; </xsl:text>
151 <xsl:element name="name">$packname</xsl:element>
152 <xsl:element name="version">$packversion</xsl:element>
153 <xsl:if test="document(\$installed-packages)//package[name='$packname']">
154 <xsl:element name="inst-version">
155 <xsl:value-of
156 select="document(\$installed-packages
157 )//package[name='$packname']/version"/>
158 </xsl:element>
159 </xsl:if>
160<!-- Dependencies -->
161EOF
162 if test $precpack != NONE; then
163 cat >>$SPECIAL_FILE << EOF
164 <xsl:element name="dependency">
165 <xsl:attribute name="status">required</xsl:attribute>
166 <xsl:attribute name="build">before</xsl:attribute>
167 <xsl:attribute name="name">$precpack</xsl:attribute>
168 <xsl:attribute name="type">ref</xsl:attribute>
169 </xsl:element>
170EOF
171 else
172 cat >>$SPECIAL_FILE << EOF
173 <xsl:apply-templates select=".//para[@role='required' or
174 @role='recommended' or
175 @role='optional']"
176 mode="dependency"/>
177EOF
178 fi
179 cat >>$SPECIAL_FILE << EOF
180<!-- End dependencies -->
181 </module>
182EOF
183# cat >> tmpfile << EOF
184# <xsl:element name="dependency">
185# <xsl:attribute name="status">
186# <xsl:value-of select="\$status"/>
187# </xsl:attribute>
188# <xsl:attribute name="build">
189# <xsl:value-of select="\$build"/>
190# </xsl:attribute>
191# <xsl:attribute name="name">$packname</xsl:attribute>
192# <xsl:attribute name="type">ref</xsl:attribute>
193# </xsl:element>
194#EOF
195 precpack=$packname
196 done
197# We need a dummy package for plasma post install instructions
198 if [ $(basename $file .xml) = plasma-all ]; then
199 cat >>$SPECIAL_FILE << EOF
200 <module><xsl:text>&#xA; </xsl:text>
201 <xsl:element name="name">plasma-post-install</xsl:element>
202 <xsl:element name="version">1.0.0</xsl:element>
203 <xsl:if test="document(\$installed-packages)//package[name='$packname']">
204 <xsl:element name="inst-version">
205 <xsl:value-of
206 select="document(\$installed-packages
207 )//package[name='$packname']/version"/>
208 </xsl:element>
209 </xsl:if>
210<!-- Dependencies -->
211 <xsl:element name="dependency">
212 <xsl:attribute name="status">required</xsl:attribute>
213 <xsl:attribute name="build">before</xsl:attribute>
214 <xsl:attribute name="name">$precpack</xsl:attribute>
215 <xsl:attribute name="type">ref</xsl:attribute>
216 </xsl:element>
217<!-- End dependencies -->
218 </module>
219EOF
220 fi
221
222 cat >>$SPECIAL_FILE << EOF
223 </package>
224 </xsl:when>
225EOF
226 cat >> tmpfile << EOF
227 <xsl:element name="dependency">
228 <xsl:attribute name="status">
229 <xsl:value-of select="\$status"/>
230 </xsl:attribute>
231 <xsl:attribute name="build">
232 <xsl:value-of select="\$build"/>
233 </xsl:attribute>
234 <xsl:attribute name="name">$packname</xsl:attribute>
235 <xsl:attribute name="type">ref</xsl:attribute>
236 </xsl:element>
237 </xsl:when>
238EOF
239done
240
241for ver_ent in $EXCEPTIONS; do
242 id=$(grep 'xreflabel=".*'$ver_ent $BLFS_XML | sed 's@.*id="\([^"]*\)".*@\1@')
243 [[ -z $id ]] && continue
244 cat >>$SPECIAL_FILE << EOF
245 <xsl:when test="@id='$id'">
246<!-- if there is a sect1 ancestor, we have a module -->
247 <xsl:choose>
248 <xsl:when test="ancestor::sect1">
249 <xsl:text> </xsl:text>
250 <module><xsl:text>&#xA; </xsl:text>
251 <xsl:element name="name">$id</xsl:element>
252 <xsl:text>&#xA; </xsl:text>
253 <xsl:element name="version">$ver_ent</xsl:element>
254 <xsl:if
255 test="document(\$installed-packages)//package[name=current()/@id]">
256 <xsl:text>&#xA; </xsl:text>
257 <xsl:element name="inst-version">
258 <xsl:value-of
259 select="document(\$installed-packages
260 )//package[name=current()/@id]/version"/>
261 </xsl:element>
262 </xsl:if>
263<!-- Dependencies -->
264 <xsl:apply-templates select=".//para[@role='required' or
265 @role='recommended' or
266 @role='optional']"
267 mode="dependency"/>
268<!-- End dependencies -->
269 <xsl:text>&#xA; </xsl:text>
270 </module><xsl:text>&#xA;</xsl:text>
271 </xsl:when>
272 <xsl:otherwise>
273 <xsl:text> </xsl:text>
274 <package><xsl:text>&#xA; </xsl:text>
275 <xsl:element name="name">$id</xsl:element>
276 <xsl:text>&#xA; </xsl:text>
277 <xsl:element name="version">$ver_ent</xsl:element>
278 <xsl:if
279 test="document(\$installed-packages)//package[name=current()/@id]">
280 <xsl:text>&#xA; </xsl:text>
281 <xsl:element name="inst-version">
282 <xsl:value-of
283 select="document(\$installed-packages
284 )//package[name=current()/@id]/version"/>
285 </xsl:element>
286 </xsl:if>
287<!-- Dependencies -->
288 <xsl:apply-templates select=".//para[@role='required' or
289 @role='recommended' or
290 @role='optional']"
291 mode="dependency"/>
292<!-- End dependencies -->
293 <xsl:text>&#xA; </xsl:text>
294 </package><xsl:text>&#xA;</xsl:text>
295 </xsl:otherwise>
296 </xsl:choose>
297 </xsl:when>
298EOF
299done
300
301cat >>$SPECIAL_FILE << EOF
302 <xsl:otherwise>
303 <xsl:apply-templates
304 select="self::node()[contains(translate(@xreflabel,
305 '123456789',
306 '000000000'),
307 '-0')
308 ]"
309 mode="normal"/>
310 </xsl:otherwise>
311 </xsl:choose>
312</xsl:template>
313EOF
314cat $SPECIAL_FILE tmpfile > tmpfile1
315mv tmpfile1 $SPECIAL_FILE
316rm tmpfile
317cat >> $SPECIAL_FILE << EOF
318 <xsl:otherwise>
319 <xsl:message>
320 <xsl:text>You should not be seeing this</xsl:text>
321 </xsl:message>
322 </xsl:otherwise>
323 </xsl:choose>
324</xsl:template>
325</xsl:stylesheet>
326EOF
Note: See TracBrowser for help on using the repository browser.