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

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

Add automation for kf5 and plasma5

  • Property mode set to 100755
File size: 11.2 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 cat >>$SPECIAL_FILE << EOF
63 <xsl:when test="@id='$nv_id'">
64 <xsl:text> </xsl:text>
65 <package><xsl:text>&#xA; </xsl:text>
66 <xsl:element name="name">$nv_id</xsl:element>
67 <xsl:text>&#xA; </xsl:text>
68 <xsl:element name="version">1.0.0</xsl:element>
69 <xsl:if
70 test="document(\$installed-packages)//package[name=current()/@id]">
71 <xsl:text>&#xA; </xsl:text>
72 <xsl:element name="inst-version">
73 <xsl:value-of
74 select="document(\$installed-packages
75 )//package[name=current()/@id]/version"/>
76 </xsl:element>
77 </xsl:if>
78<!-- Dependencies -->
79 <xsl:apply-templates select=".//para[@role='required' or
80 @role='recommended' or
81 @role='optional']"
82 mode="dependency"/>
83<!-- End dependencies -->
84 <xsl:text>&#xA; </xsl:text>
85 </package><xsl:text>&#xA;</xsl:text>
86 </xsl:when>
87EOF
88done
89
90# Taking packages inside x7proto etc, as versionned modules.
91# We also write a dependency expansion when a dep is of the form
92# xorg7-something. Since that is another template, we need
93# a temporary file, which we shall concatenate at the end
94cat >tmpfile << EOF
95 <xsl:template name="expand-deps">
96 <xsl:param name="section"/>
97 <xsl:param name="status"/>
98 <xsl:param name="build"/>
99 <xsl:choose>
100EOF
101for file in $(ls ${BLFS_DIR}/x/installing/x7* | grep -v x7driver) \
102 ${BLFS_DIR}/kde/kf5/kf5-frameworks.xml \
103 ${BLFS_DIR}/kde/plasma5/plasma-all.xml; do
104 id=$(grep xreflabel $file | sed 's@.*id="\([^"]*\).*@\1@')
105 cat >>$SPECIAL_FILE << EOF
106 <xsl:when test="@id='$id'">
107 <xsl:text> </xsl:text>
108 <package><xsl:text>&#xA; </xsl:text>
109 <xsl:element name="name">$id</xsl:element>
110 <xsl:text>&#xA; </xsl:text>
111EOF
112 cat >> tmpfile << EOF
113 <xsl:when test="\$section='$id'">
114EOF
115# We extract the list of packages for an xorg page from
116# the version part of the .xml file. Seems that
117# the order is not always the same as in the "cat" command.
118# So we have to read that command too, since it may be assumed
119# that the preceding package is a dependency of the following,
120# except the first.
121list_cat="$(sed -n '/>cat.*\.\(md5\|dat\)/,/EOF</p' $file | grep -v 'cat\|EOF\|#' |
122 awk '{ print $NF }' | sed 's/-&.*//')"
123
124 precpack=NONE
125 for pack in $list_cat; do
126 if grep -q x7 $file; then # this is an xorg package
127 packname=$pack
128 packversion=$(grep "ENTITY ${pack}-version" $file | \
129 sed 's@[^"]*"\([^"]*\).*@\1@')
130 else
131 packname=${pack%%-[[:digit:]]*}
132 packversion=$(echo $pack | sed 's/[^.]*-\([.[:digit:]]*\)\.tar.*/\1/')
133 fi
134## Rationale for the sed below: the following for breaks words at spaces (unless
135## we tweak IFS). So replace spaces with commas in lines so that only newlines
136## are separators.
137# for pack in \
138# $(grep 'ENTITY.*version' $file | sed 's/[ ]\+/,/g'); do
139# packname=$(echo $pack | sed s'@.*ENTITY,\(.*\)-version.*@\1@')
140# packversion=$(echo $pack | sed 's@[^"]*"\([^"]*\).*@\1@')
141# for i in $list_cat; do
142# if [ "$i" = "$packname" ]; then break; fi
143# precpack=$i
144# done
145## It may happen that packname is not in list_cat, because its entity
146## is commented out in the xml, but we do not check that (too complicated).
147## In that case, the whole list is scanned, and $precpack=$i at the end.
148## when packname is found in the list $precpack!=$i.
149# if [ "$precpack" = "$i" ]; then continue; fi
150 cat >>$SPECIAL_FILE << EOF
151 <module><xsl:text>&#xA; </xsl:text>
152 <xsl:element name="name">$packname</xsl:element>
153 <xsl:element name="version">$packversion</xsl:element>
154 <xsl:if test="document(\$installed-packages)//package[name='$packname']">
155 <xsl:element name="inst-version">
156 <xsl:value-of
157 select="document(\$installed-packages
158 )//package[name='$packname']/version"/>
159 </xsl:element>
160 </xsl:if>
161<!-- Dependencies -->
162EOF
163 if test $precpack != NONE; then
164 cat >>$SPECIAL_FILE << EOF
165 <xsl:element name="dependency">
166 <xsl:attribute name="status">required</xsl:attribute>
167 <xsl:attribute name="build">before</xsl:attribute>
168 <xsl:attribute name="name">$precpack</xsl:attribute>
169 <xsl:attribute name="type">ref</xsl:attribute>
170 </xsl:element>
171EOF
172 else
173 cat >>$SPECIAL_FILE << EOF
174 <xsl:apply-templates select=".//para[@role='required' or
175 @role='recommended' or
176 @role='optional']"
177 mode="dependency"/>
178EOF
179 fi
180 cat >>$SPECIAL_FILE << EOF
181<!-- End dependencies -->
182 </module>
183EOF
184 cat >> tmpfile << EOF
185 <xsl:element name="dependency">
186 <xsl:attribute name="status">
187 <xsl:value-of select="\$status"/>
188 </xsl:attribute>
189 <xsl:attribute name="build">
190 <xsl:value-of select="\$build"/>
191 </xsl:attribute>
192 <xsl:attribute name="name">$packname</xsl:attribute>
193 <xsl:attribute name="type">ref</xsl:attribute>
194 </xsl:element>
195EOF
196 precpack=$packname
197 done
198 cat >>$SPECIAL_FILE << EOF
199 </package>
200 </xsl:when>
201EOF
202 cat >> tmpfile << EOF
203 </xsl:when>
204EOF
205done
206
207for ver_ent in $EXCEPTIONS; do
208 id=$(grep 'xreflabel=".*'$ver_ent $BLFS_XML | sed 's@.*id="\([^"]*\)".*@\1@')
209 [[ -z $id ]] && continue
210 cat >>$SPECIAL_FILE << EOF
211 <xsl:when test="@id='$id'">
212<!-- if there is a sect1 ancestor, we have a module -->
213 <xsl:choose>
214 <xsl:when test="ancestor::sect1">
215 <xsl:text> </xsl:text>
216 <module><xsl:text>&#xA; </xsl:text>
217 <xsl:element name="name">$id</xsl:element>
218 <xsl:text>&#xA; </xsl:text>
219 <xsl:element name="version">$ver_ent</xsl:element>
220 <xsl:if
221 test="document(\$installed-packages)//package[name=current()/@id]">
222 <xsl:text>&#xA; </xsl:text>
223 <xsl:element name="inst-version">
224 <xsl:value-of
225 select="document(\$installed-packages
226 )//package[name=current()/@id]/version"/>
227 </xsl:element>
228 </xsl:if>
229<!-- Dependencies -->
230 <xsl:apply-templates select=".//para[@role='required' or
231 @role='recommended' or
232 @role='optional']"
233 mode="dependency"/>
234<!-- End dependencies -->
235 <xsl:text>&#xA; </xsl:text>
236 </module><xsl:text>&#xA;</xsl:text>
237 </xsl:when>
238 <xsl:otherwise>
239 <xsl:text> </xsl:text>
240 <package><xsl:text>&#xA; </xsl:text>
241 <xsl:element name="name">$id</xsl:element>
242 <xsl:text>&#xA; </xsl:text>
243 <xsl:element name="version">$ver_ent</xsl:element>
244 <xsl:if
245 test="document(\$installed-packages)//package[name=current()/@id]">
246 <xsl:text>&#xA; </xsl:text>
247 <xsl:element name="inst-version">
248 <xsl:value-of
249 select="document(\$installed-packages
250 )//package[name=current()/@id]/version"/>
251 </xsl:element>
252 </xsl:if>
253<!-- Dependencies -->
254 <xsl:apply-templates select=".//para[@role='required' or
255 @role='recommended' or
256 @role='optional']"
257 mode="dependency"/>
258<!-- End dependencies -->
259 <xsl:text>&#xA; </xsl:text>
260 </package><xsl:text>&#xA;</xsl:text>
261 </xsl:otherwise>
262 </xsl:choose>
263 </xsl:when>
264EOF
265done
266
267cat >>$SPECIAL_FILE << EOF
268 <xsl:otherwise>
269 <xsl:apply-templates
270 select="self::node()[contains(translate(@xreflabel,
271 '123456789',
272 '000000000'),
273 '-0')
274 ]"
275 mode="normal"/>
276 </xsl:otherwise>
277 </xsl:choose>
278</xsl:template>
279EOF
280cat $SPECIAL_FILE tmpfile > tmpfile1
281mv tmpfile1 $SPECIAL_FILE
282rm tmpfile
283cat >> $SPECIAL_FILE << EOF
284 <xsl:otherwise>
285 <xsl:message>
286 <xsl:text>You should not be seeing this</xsl:text>
287 </xsl:message>
288 </xsl:otherwise>
289 </xsl:choose>
290</xsl:template>
291</xsl:stylesheet>
292EOF
Note: See TracBrowser for help on using the repository browser.