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 |
|
---|
24 | BLFS_XML=$1
|
---|
25 | if ! test -f ${BLFS_XML}; then
|
---|
26 | echo File \`${BLFS_XML}\' does not exist
|
---|
27 | exit 1
|
---|
28 | fi
|
---|
29 | SPECIAL_FILE=$2
|
---|
30 | if test -z "${SPECIAL_FILE}"; then SPECIAL_FILE=specialCases.xsl;fi
|
---|
31 | BLFS_DIR=$3
|
---|
32 | if test -z "${BLFS_DIR}"; then BLFS_DIR=$(cd $(dirname ${BLFS_XML})/.. ; pwd);fi
|
---|
33 |
|
---|
34 | # Packages whose version does not begin with a number
|
---|
35 | EXCEPTIONS=$(grep 'ENTITY.*version[ ]*"[^0-9"&.].*[0-9]' ${BLFS_DIR}/packages.ent |
|
---|
36 | sed 's@^[^"]*"\([^"]*\)".*@\1@')
|
---|
37 |
|
---|
38 | # Non-versioned packages:
|
---|
39 | NV_LIST="postlfs-config-profile postlfs-config-random postlfs-config-vimrc \
|
---|
40 | initramfs xorg-env kde-pre-install-config kf5-intro \
|
---|
41 | lxqt-pre-install lxqt-post-install ojdk-conf tex-path"
|
---|
42 |
|
---|
43 | cat >$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>
|
---|
58 | EOF
|
---|
59 |
|
---|
60 | # Non-versionned packages. Add to NV_LIST if you need more.
|
---|
61 | for 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>
 </xsl:text>
|
---|
66 | <xsl:element name="name">$nv_id</xsl:element>
|
---|
67 | <xsl:text>
 </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>
 </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>
 </xsl:text>
|
---|
85 | </package><xsl:text>
</xsl:text>
|
---|
86 | </xsl:when>
|
---|
87 | EOF
|
---|
88 | done
|
---|
89 |
|
---|
90 | # Taking packages contained in pages installing several packages (x7* except
|
---|
91 | # x7driver, kf5-frameworks, and plasma5-all), as versionned modules.
|
---|
92 | # We also write a dependency expansion when a dep is of the form
|
---|
93 | # xorg7-something or kf5-frameworks or plasma5-build. Since that is another
|
---|
94 | # template, we need a temporary file, which we shall concatenate at the end
|
---|
95 | cat >tmpfile << EOF
|
---|
96 | <xsl:template name="expand-deps">
|
---|
97 | <xsl:param name="section"/>
|
---|
98 | <xsl:param name="status"/>
|
---|
99 | <xsl:param name="build"/>
|
---|
100 | <xsl:choose>
|
---|
101 | EOF
|
---|
102 | for file in $(ls ${BLFS_DIR}/x/installing/x7* | grep -v x7driver) \
|
---|
103 | ${BLFS_DIR}/kde/kf5/kf5-frameworks.xml \
|
---|
104 | ${BLFS_DIR}/kde/plasma5/plasma-all.xml; do
|
---|
105 | id=$(grep xreflabel $file | sed 's@.*id="\([^"]*\).*@\1@')
|
---|
106 | cat >>$SPECIAL_FILE << EOF
|
---|
107 | <xsl:when test="@id='$id'">
|
---|
108 | <xsl:text> </xsl:text>
|
---|
109 | <package><xsl:text>
 </xsl:text>
|
---|
110 | <xsl:element name="name">$id</xsl:element>
|
---|
111 | <xsl:text>
 </xsl:text>
|
---|
112 | EOF
|
---|
113 | cat >> tmpfile << EOF
|
---|
114 | <xsl:when test="\$section='$id'">
|
---|
115 | EOF
|
---|
116 | # We extract the list of packages for those pages from
|
---|
117 | # the "cat" command that creates the md5 file. We assume
|
---|
118 | # that the preceding package is a dependency of the following,
|
---|
119 | # except the first.
|
---|
120 | # note that some pages may have several "cat" command, so we have to
|
---|
121 | # make a complex regex for the first line to save. All those lines have
|
---|
122 | # .md5 in them except the one for x7legacy that has .dat.
|
---|
123 | # we need also to remove lines beginning with #.
|
---|
124 | # Note that only xorg pages have '&' in them. So for kde
|
---|
125 | # pages, what is extracted it the full tarball name.
|
---|
126 | list_cat="$(sed -n '/>cat.*\.\(md5\|dat\)/,/EOF</p' $file | \
|
---|
127 | grep -v '>cat\|EOF<\|#' | \
|
---|
128 | awk '{ print $NF }' | sed 's/-&.*//')"
|
---|
129 |
|
---|
130 | precpack=NONE
|
---|
131 | for pack in $list_cat; do
|
---|
132 | if grep -q x7 $file; then # this is an xorg package
|
---|
133 | packname=$pack
|
---|
134 | # We extract the version from the ENTITY parts of the .xml file.
|
---|
135 | packversion=$(grep "ENTITY ${pack}-version" $file | \
|
---|
136 | sed 's@[^"]*"\([^"]*\).*@\1@')
|
---|
137 | else
|
---|
138 | packname=${pack%-[[:digit:]]*}
|
---|
139 | packversion=$(echo $pack | sed 's/[^.]*-\([.[:digit:]]*\)\.tar.*/\1/')
|
---|
140 | fi
|
---|
141 | cat >>$SPECIAL_FILE << EOF
|
---|
142 | <module><xsl:text>
 </xsl:text>
|
---|
143 | <xsl:element name="name">$packname</xsl:element>
|
---|
144 | <xsl:element name="version">$packversion</xsl:element>
|
---|
145 | <xsl:if test="document(\$installed-packages)//package[name='$packname']">
|
---|
146 | <xsl:element name="inst-version">
|
---|
147 | <xsl:value-of
|
---|
148 | select="document(\$installed-packages
|
---|
149 | )//package[name='$packname']/version"/>
|
---|
150 | </xsl:element>
|
---|
151 | </xsl:if>
|
---|
152 | <!-- Dependencies -->
|
---|
153 | EOF
|
---|
154 | if test $precpack != NONE; then
|
---|
155 | cat >>$SPECIAL_FILE << EOF
|
---|
156 | <xsl:element name="dependency">
|
---|
157 | <xsl:attribute name="status">required</xsl:attribute>
|
---|
158 | <xsl:attribute name="build">before</xsl:attribute>
|
---|
159 | <xsl:attribute name="name">$precpack</xsl:attribute>
|
---|
160 | <xsl:attribute name="type">ref</xsl:attribute>
|
---|
161 | </xsl:element>
|
---|
162 | EOF
|
---|
163 | else
|
---|
164 | cat >>$SPECIAL_FILE << EOF
|
---|
165 | <xsl:apply-templates select=".//para[@role='required' or
|
---|
166 | @role='recommended' or
|
---|
167 | @role='optional']"
|
---|
168 | mode="dependency"/>
|
---|
169 | EOF
|
---|
170 | fi
|
---|
171 | cat >>$SPECIAL_FILE << EOF
|
---|
172 | <!-- End dependencies -->
|
---|
173 | </module>
|
---|
174 | EOF
|
---|
175 | # cat >> tmpfile << EOF
|
---|
176 | # <xsl:element name="dependency">
|
---|
177 | # <xsl:attribute name="status">
|
---|
178 | # <xsl:value-of select="\$status"/>
|
---|
179 | # </xsl:attribute>
|
---|
180 | # <xsl:attribute name="build">
|
---|
181 | # <xsl:value-of select="\$build"/>
|
---|
182 | # </xsl:attribute>
|
---|
183 | # <xsl:attribute name="name">$packname</xsl:attribute>
|
---|
184 | # <xsl:attribute name="type">ref</xsl:attribute>
|
---|
185 | # </xsl:element>
|
---|
186 | #EOF
|
---|
187 | precpack=$packname
|
---|
188 | done
|
---|
189 | cat >>$SPECIAL_FILE << EOF
|
---|
190 | </package>
|
---|
191 | </xsl:when>
|
---|
192 | EOF
|
---|
193 | cat >> tmpfile << EOF
|
---|
194 | <xsl:element name="dependency">
|
---|
195 | <xsl:attribute name="status">
|
---|
196 | <xsl:value-of select="\$status"/>
|
---|
197 | </xsl:attribute>
|
---|
198 | <xsl:attribute name="build">
|
---|
199 | <xsl:value-of select="\$build"/>
|
---|
200 | </xsl:attribute>
|
---|
201 | <xsl:attribute name="name">$packname</xsl:attribute>
|
---|
202 | <xsl:attribute name="type">ref</xsl:attribute>
|
---|
203 | </xsl:element>
|
---|
204 | </xsl:when>
|
---|
205 | EOF
|
---|
206 | done
|
---|
207 |
|
---|
208 | for ver_ent in $EXCEPTIONS; do
|
---|
209 | id=$(grep 'xreflabel=".*'$ver_ent $BLFS_XML | sed 's@.*id="\([^"]*\)".*@\1@')
|
---|
210 | [[ -z $id ]] && continue
|
---|
211 | cat >>$SPECIAL_FILE << EOF
|
---|
212 | <xsl:when test="@id='$id'">
|
---|
213 | <!-- if there is a sect1 ancestor, we have a module -->
|
---|
214 | <xsl:choose>
|
---|
215 | <xsl:when test="ancestor::sect1">
|
---|
216 | <xsl:text> </xsl:text>
|
---|
217 | <module><xsl:text>
 </xsl:text>
|
---|
218 | <xsl:element name="name">$id</xsl:element>
|
---|
219 | <xsl:text>
 </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>
 </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>
 </xsl:text>
|
---|
237 | </module><xsl:text>
</xsl:text>
|
---|
238 | </xsl:when>
|
---|
239 | <xsl:otherwise>
|
---|
240 | <xsl:text> </xsl:text>
|
---|
241 | <package><xsl:text>
 </xsl:text>
|
---|
242 | <xsl:element name="name">$id</xsl:element>
|
---|
243 | <xsl:text>
 </xsl:text>
|
---|
244 | <xsl:element name="version">$ver_ent</xsl:element>
|
---|
245 | <xsl:if
|
---|
246 | test="document(\$installed-packages)//package[name=current()/@id]">
|
---|
247 | <xsl:text>
 </xsl:text>
|
---|
248 | <xsl:element name="inst-version">
|
---|
249 | <xsl:value-of
|
---|
250 | select="document(\$installed-packages
|
---|
251 | )//package[name=current()/@id]/version"/>
|
---|
252 | </xsl:element>
|
---|
253 | </xsl:if>
|
---|
254 | <!-- Dependencies -->
|
---|
255 | <xsl:apply-templates select=".//para[@role='required' or
|
---|
256 | @role='recommended' or
|
---|
257 | @role='optional']"
|
---|
258 | mode="dependency"/>
|
---|
259 | <!-- End dependencies -->
|
---|
260 | <xsl:text>
 </xsl:text>
|
---|
261 | </package><xsl:text>
</xsl:text>
|
---|
262 | </xsl:otherwise>
|
---|
263 | </xsl:choose>
|
---|
264 | </xsl:when>
|
---|
265 | EOF
|
---|
266 | done
|
---|
267 |
|
---|
268 | cat >>$SPECIAL_FILE << EOF
|
---|
269 | <xsl:otherwise>
|
---|
270 | <xsl:apply-templates
|
---|
271 | select="self::node()[contains(translate(@xreflabel,
|
---|
272 | '123456789',
|
---|
273 | '000000000'),
|
---|
274 | '-0')
|
---|
275 | ]"
|
---|
276 | mode="normal"/>
|
---|
277 | </xsl:otherwise>
|
---|
278 | </xsl:choose>
|
---|
279 | </xsl:template>
|
---|
280 | EOF
|
---|
281 | cat $SPECIAL_FILE tmpfile > tmpfile1
|
---|
282 | mv tmpfile1 $SPECIAL_FILE
|
---|
283 | rm tmpfile
|
---|
284 | cat >> $SPECIAL_FILE << EOF
|
---|
285 | <xsl:otherwise>
|
---|
286 | <xsl:message>
|
---|
287 | <xsl:text>You should not be seeing this</xsl:text>
|
---|
288 | </xsl:message>
|
---|
289 | </xsl:otherwise>
|
---|
290 | </xsl:choose>
|
---|
291 | </xsl:template>
|
---|
292 | </xsl:stylesheet>
|
---|
293 | EOF
|
---|