source: BLFS/gen-special.sh@ 625cb14

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

Add possibility to automate bash shell startup files, vimrc, and rng.
This adds a new variable to the configuration (LANGUAGE).
Also automate the generation of various <replaceable> instructions

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