source: BLFS/gen-special.sh@ 6613034

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

Add code to account to the new role attribute in dependencies

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