source: BLFS/gen-special.sh@ 5fb012d

2.4 ablfs-more legacy new_features trunk
Last change on this file since 5fb012d was 5fb012d, checked in by Pierre Labastie <pierre@…>, 9 years ago

Add non-versioned packages in packages.xml. This allows for example to list dependencies of CA certificates

  • Property mode set to 100755
File size: 9.7 KB
Line 
1#!/bin/bash
2
3# $Id: gen-special.sh 21 2012-02-16 15:06:19Z labastie $
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_XML |
38 sed 's@^[^"]*"\([^"]*\)".*@\1@')
39
40# Non-versioned packages:
41NV_LIST="cacerts xorg-env kde-pre-install-config kf5-intro lxqt-pre-install \
42ojdk-conf tex-path"
43
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>
81<!-- Although versioned, this page is not a package -->
82 <xsl:when test="@id='xorg7'"/>
83EOF
84
85# Non-versionned packages. Add to NV_LIST if you need more.
86for nv_id in $NV_LIST; do
87 cat >>$SPECIAL_FILE << EOF
88 <xsl:when test="@id='$nv_id'">
89 <xsl:text> </xsl:text>
90 <package><xsl:text>&#xA; </xsl:text>
91 <xsl:element name="name">$nv_id</xsl:element>
92 <xsl:text>&#xA; </xsl:text>
93 <xsl:element name="version">1.0.0</xsl:element>
94 <xsl:if
95 test="document(\$installed-packages)//package[name=current()/@id]">
96 <xsl:text>&#xA; </xsl:text>
97 <xsl:element name="inst-version">
98 <xsl:value-of
99 select="document(\$installed-packages
100 )//package[name=current()/@id]/version"/>
101 </xsl:element>
102 </xsl:if>
103<!-- Dependencies -->
104 <xsl:apply-templates select=".//para[@role='required' or
105 @role='recommended' or
106 @role='optional']"
107 mode="dependency"/>
108<!-- End dependencies -->
109 <xsl:text>&#xA; </xsl:text>
110 </package><xsl:text>&#xA;</xsl:text>
111 </xsl:when>
112EOF
113done
114
115# Taking packages inside x7proto etc, as versionned modules.
116# We also write a dependency expansion when a dep is of the form
117# xorg7-something. Since that is another template, we need
118# a temporary file, which we shall concatenate at the end
119cat >tmpfile << EOF
120 <xsl:template name="expand-deps">
121 <xsl:param name="section"/>
122 <xsl:param name="status"/>
123 <xsl:choose>
124EOF
125for file in $(ls ${BLFS_DIR}/x/installing/x7* | grep -v x7driver); do
126 id=$(grep xreflabel $file | sed 's@.*id="\([^"]*\).*@\1@')
127 cat >>$SPECIAL_FILE << EOF
128 <xsl:when test="@id='$id'">
129 <xsl:text> </xsl:text>
130 <package><xsl:text>&#xA; </xsl:text>
131 <xsl:element name="name">$id</xsl:element>
132 <xsl:text>&#xA; </xsl:text>
133EOF
134 cat >> tmpfile << EOF
135 <xsl:when test="\$section='$id'">
136EOF
137# We extract the list of packages for an xorg page from
138# the version part of the .xml file. Seems that
139# the order is not always the same as in the "cat" command.
140# So we have to read that command too, since it may be assumed
141# that the preceding package is a dependency of the following,
142# except the first.
143 list_cat="$(sed -n '/>cat/,/EOF</p' $file | grep -v 'cat\|EOF' |
144 sed 's/^[^ ]*\ *\([^&]*\).*/\1/' | sed 's/-$//')"
145
146# Rationale for the sed below: the following for breaks words at spaces (unless
147# we tweak IFS). So replace spaces with commas in lines so that only newlines
148# are separators.
149 for pack in \
150 $(grep 'ENTITY.*version' $file | sed 's/[ ]\+/,/g'); do
151 packname=$(echo $pack | sed s'@.*ENTITY,\(.*\)-version.*@\1@')
152 packversion=$(echo $pack | sed 's@[^"]*"\([^"]*\).*@\1@')
153 precpack=NONE
154 for i in $list_cat; do
155 if [ "$i" = "$packname" ]; then break; fi
156 precpack=$i
157 done
158
159 cat >>$SPECIAL_FILE << EOF
160 <module><xsl:text>&#xA; </xsl:text>
161 <xsl:element name="name">$packname</xsl:element>
162 <xsl:element name="version">$packversion</xsl:element>
163 <xsl:if test="document(\$installed-packages)//package[name='$packname']">
164 <xsl:element name="inst-version">
165 <xsl:value-of
166 select="document(\$installed-packages
167 )//package[name='$packname']/version"/>
168 </xsl:element>
169 </xsl:if>
170<!-- Dependencies -->
171EOF
172 if test $precpack != NONE; then
173 cat >>$SPECIAL_FILE << EOF
174 <xsl:element name="dependency">
175 <xsl:attribute name="status">required</xsl:attribute>
176 <xsl:attribute name="name">$precpack</xsl:attribute>
177 <xsl:attribute name="type">ref</xsl:attribute>
178 </xsl:element>
179EOF
180 else
181 cat >>$SPECIAL_FILE << EOF
182 <xsl:apply-templates select=".//para[@role='required' or
183 @role='recommended' or
184 @role='optional']"
185 mode="dependency"/>
186EOF
187 fi
188 cat >>$SPECIAL_FILE << EOF
189<!-- End dependencies -->
190 </module>
191EOF
192 cat >> tmpfile << EOF
193 <xsl:element name="dependency">
194 <xsl:attribute name="status">
195 <xsl:value-of select="\$status"/>
196 </xsl:attribute>
197 <xsl:attribute name="name">$packname</xsl:attribute>
198 <xsl:attribute name="type">ref</xsl:attribute>
199 </xsl:element>
200EOF
201 done
202 cat >>$SPECIAL_FILE << EOF
203 </package>
204 </xsl:when>
205EOF
206 cat >> tmpfile << EOF
207 </xsl:when>
208EOF
209done
210
211for ver_ent in $EXCEPTIONS; do
212 id=$(grep 'xreflabel=".*'$ver_ent $BLFS_XML | sed 's@.*id="\([^"]*\)".*@\1@')
213 [[ -z $id ]] && continue
214 cat >>$SPECIAL_FILE << EOF
215 <xsl:when test="@id='$id'">
216 <xsl:text> </xsl:text>
217 <package><xsl:text>&#xA; </xsl:text>
218 <xsl:element name="name">$id</xsl:element>
219 <xsl:text>&#xA; </xsl:text>
220 <xsl:element name="version">$ver_ent</xsl:element>
221 <xsl:if
222 test="document(\$installed-packages)//package[name=current()/@id]">
223 <xsl:text>&#xA; </xsl:text>
224 <xsl:element name="inst-version">
225 <xsl:value-of
226 select="document(\$installed-packages
227 )//package[name=current()/@id]/version"/>
228 </xsl:element>
229 </xsl:if>
230<!-- Dependencies -->
231 <xsl:apply-templates select=".//para[@role='required' or
232 @role='recommended' or
233 @role='optional']"
234 mode="dependency"/>
235<!-- End dependencies -->
236 <xsl:text>&#xA; </xsl:text>
237 </package><xsl:text>&#xA;</xsl:text>
238 </xsl:when>
239EOF
240done
241
242cat >>$SPECIAL_FILE << EOF
243 <xsl:otherwise>
244 <xsl:apply-templates
245 select="self::node()[contains(translate(@xreflabel,
246 '123456789',
247 '000000000'),
248 '-0')
249 ]"
250 mode="normal"/>
251 </xsl:otherwise>
252 </xsl:choose>
253</xsl:template>
254EOF
255cat $SPECIAL_FILE tmpfile > tmpfile1
256mv tmpfile1 $SPECIAL_FILE
257rm tmpfile
258cat >> $SPECIAL_FILE << EOF
259 <xsl:otherwise>
260 <xsl:message>
261 <xsl:text>You should not be seeing this</xsl:text>
262 </xsl:message>
263 </xsl:otherwise>
264 </xsl:choose>
265</xsl:template>
266</xsl:stylesheet>
267EOF
Note: See TracBrowser for help on using the repository browser.