source: BLFS/gen-special.sh@ fbdd1a8

2.4 ablfs-more legacy trunk
Last change on this file since fbdd1a8 was 342c862, checked in by Pierre Labastie <pierre@…>, 8 years ago

Merge new_feature branch r3884 to3886:

  • Adapt BLFS/envars.conf to modern BLFS books
  • Fix try order for downloading BLFS packages
  • Fixes to use the XORG Legacy page in BLFS
  • Property mode set to 100755
File size: 10.0 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_DIR}/packages.ent |
38 sed 's@^[^"]*"\([^"]*\)".*@\1@')
39
40# Non-versioned packages:
41NV_LIST="cacerts xorg-env kde-pre-install-config kf5-intro lxqt-pre-install \
42lxqt-post-install ojdk-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. 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>
88EOF
89
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
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"/>
128 <xsl:choose>
129EOF
130for file in $(ls ${BLFS_DIR}/x/installing/x7* | grep -v x7driver); do
131 id=$(grep xreflabel $file | sed 's@.*id="\([^"]*\).*@\1@')
132 cat >>$SPECIAL_FILE << EOF
133 <xsl:when test="@id='$id'">
134 <xsl:text> </xsl:text>
135 <package><xsl:text>&#xA; </xsl:text>
136 <xsl:element name="name">$id</xsl:element>
137 <xsl:text>&#xA; </xsl:text>
138EOF
139 cat >> tmpfile << EOF
140 <xsl:when test="\$section='$id'">
141EOF
142# We extract the list of packages for an xorg page from
143# the version part of the .xml file. Seems that
144# the order is not always the same as in the "cat" command.
145# So we have to read that command too, since it may be assumed
146# that the preceding package is a dependency of the following,
147# except the first.
148 list_cat="$(sed -n '/>cat/,/EOF</p' $file | grep -v 'cat\|EOF' |
149 awk '{ print $NF }' | sed 's/-&.*//')"
150
151# Rationale for the sed below: the following for breaks words at spaces (unless
152# we tweak IFS). So replace spaces with commas in lines so that only newlines
153# are separators.
154 for pack in \
155 $(grep 'ENTITY.*version' $file | sed 's/[ ]\+/,/g'); do
156 packname=$(echo $pack | sed s'@.*ENTITY,\(.*\)-version.*@\1@')
157 packversion=$(echo $pack | sed 's@[^"]*"\([^"]*\).*@\1@')
158 precpack=NONE
159 for i in $list_cat; do
160 if [ "$i" = "$packname" ]; then break; fi
161 precpack=$i
162 done
163
164 cat >>$SPECIAL_FILE << EOF
165 <module><xsl:text>&#xA; </xsl:text>
166 <xsl:element name="name">$packname</xsl:element>
167 <xsl:element name="version">$packversion</xsl:element>
168 <xsl:if test="document(\$installed-packages)//package[name='$packname']">
169 <xsl:element name="inst-version">
170 <xsl:value-of
171 select="document(\$installed-packages
172 )//package[name='$packname']/version"/>
173 </xsl:element>
174 </xsl:if>
175<!-- Dependencies -->
176EOF
177 if test $precpack != NONE; then
178 cat >>$SPECIAL_FILE << EOF
179 <xsl:element name="dependency">
180 <xsl:attribute name="status">required</xsl:attribute>
181 <xsl:attribute name="name">$precpack</xsl:attribute>
182 <xsl:attribute name="type">ref</xsl:attribute>
183 </xsl:element>
184EOF
185 else
186 cat >>$SPECIAL_FILE << EOF
187 <xsl:apply-templates select=".//para[@role='required' or
188 @role='recommended' or
189 @role='optional']"
190 mode="dependency"/>
191EOF
192 fi
193 cat >>$SPECIAL_FILE << EOF
194<!-- End dependencies -->
195 </module>
196EOF
197 cat >> tmpfile << EOF
198 <xsl:element name="dependency">
199 <xsl:attribute name="status">
200 <xsl:value-of select="\$status"/>
201 </xsl:attribute>
202 <xsl:attribute name="name">$packname</xsl:attribute>
203 <xsl:attribute name="type">ref</xsl:attribute>
204 </xsl:element>
205EOF
206 done
207 cat >>$SPECIAL_FILE << EOF
208 </package>
209 </xsl:when>
210EOF
211 cat >> tmpfile << EOF
212 </xsl:when>
213EOF
214done
215
216for ver_ent in $EXCEPTIONS; do
217 id=$(grep 'xreflabel=".*'$ver_ent $BLFS_XML | sed 's@.*id="\([^"]*\)".*@\1@')
218 [[ -z $id ]] && continue
219 cat >>$SPECIAL_FILE << EOF
220 <xsl:when test="@id='$id'">
221 <xsl:text> </xsl:text>
222 <package><xsl:text>&#xA; </xsl:text>
223 <xsl:element name="name">$id</xsl:element>
224 <xsl:text>&#xA; </xsl:text>
225 <xsl:element name="version">$ver_ent</xsl:element>
226 <xsl:if
227 test="document(\$installed-packages)//package[name=current()/@id]">
228 <xsl:text>&#xA; </xsl:text>
229 <xsl:element name="inst-version">
230 <xsl:value-of
231 select="document(\$installed-packages
232 )//package[name=current()/@id]/version"/>
233 </xsl:element>
234 </xsl:if>
235<!-- Dependencies -->
236 <xsl:apply-templates select=".//para[@role='required' or
237 @role='recommended' or
238 @role='optional']"
239 mode="dependency"/>
240<!-- End dependencies -->
241 <xsl:text>&#xA; </xsl:text>
242 </package><xsl:text>&#xA;</xsl:text>
243 </xsl:when>
244EOF
245done
246
247cat >>$SPECIAL_FILE << EOF
248 <xsl:otherwise>
249 <xsl:apply-templates
250 select="self::node()[contains(translate(@xreflabel,
251 '123456789',
252 '000000000'),
253 '-0')
254 ]"
255 mode="normal"/>
256 </xsl:otherwise>
257 </xsl:choose>
258</xsl:template>
259EOF
260cat $SPECIAL_FILE tmpfile > tmpfile1
261mv tmpfile1 $SPECIAL_FILE
262rm tmpfile
263cat >> $SPECIAL_FILE << EOF
264 <xsl:otherwise>
265 <xsl:message>
266 <xsl:text>You should not be seeing this</xsl:text>
267 </xsl:message>
268 </xsl:otherwise>
269 </xsl:choose>
270</xsl:template>
271</xsl:stylesheet>
272EOF
Note: See TracBrowser for help on using the repository browser.