[e576789] | 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
|
---|
[5fb012d] | 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
|
---|
[e576789] | 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
|
---|
[4f3c433] | 35 | EXCEPTIONS=$(grep 'ENTITY.*version[ ]*"[^0-9"&.].*[0-9]' ${BLFS_DIR}/packages.ent |
|
---|
[e576789] | 36 | sed 's@^[^"]*"\([^"]*\)".*@\1@')
|
---|
| 37 |
|
---|
[5fb012d] | 38 | # Non-versioned packages:
|
---|
[625cb14] | 39 | NV_LIST="postlfs-config-profile postlfs-config-random postlfs-config-vimrc \
|
---|
[05f3977] | 40 | initramfs xorg-env kde-pre-install-config kf5-intro \
|
---|
[625cb14] | 41 | lxqt-pre-install lxqt-post-install ojdk-conf tex-path"
|
---|
[5fb012d] | 42 |
|
---|
[e576789] | 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>
|
---|
[82bd7a6] | 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>
|
---|
[e576789] | 58 | EOF
|
---|
| 59 |
|
---|
[5fb012d] | 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 |
|
---|
[e576789] | 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
|
---|
| 94 | cat >tmpfile << EOF
|
---|
| 95 | <xsl:template name="expand-deps">
|
---|
| 96 | <xsl:param name="section"/>
|
---|
| 97 | <xsl:param name="status"/>
|
---|
[7a0c3d2] | 98 | <xsl:param name="build"/>
|
---|
[e576789] | 99 | <xsl:choose>
|
---|
| 100 | EOF
|
---|
[0cd09c6] | 101 | for 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
|
---|
[e576789] | 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>
 </xsl:text>
|
---|
| 109 | <xsl:element name="name">$id</xsl:element>
|
---|
| 110 | <xsl:text>
 </xsl:text>
|
---|
| 111 | EOF
|
---|
| 112 | cat >> tmpfile << EOF
|
---|
| 113 | <xsl:when test="\$section='$id'">
|
---|
| 114 | EOF
|
---|
| 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.
|
---|
[0cd09c6] | 121 | list_cat="$(sed -n '/>cat.*\.\(md5\|dat\)/,/EOF</p' $file | grep -v 'cat\|EOF\|#' |
|
---|
[342c862] | 122 | awk '{ print $NF }' | sed 's/-&.*//')"
|
---|
[e576789] | 123 |
|
---|
[0cd09c6] | 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
|
---|
[e576789] | 150 | cat >>$SPECIAL_FILE << EOF
|
---|
| 151 | <module><xsl:text>
 </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 -->
|
---|
| 162 | EOF
|
---|
| 163 | if test $precpack != NONE; then
|
---|
| 164 | cat >>$SPECIAL_FILE << EOF
|
---|
| 165 | <xsl:element name="dependency">
|
---|
| 166 | <xsl:attribute name="status">required</xsl:attribute>
|
---|
[7a0c3d2] | 167 | <xsl:attribute name="build">before</xsl:attribute>
|
---|
[e576789] | 168 | <xsl:attribute name="name">$precpack</xsl:attribute>
|
---|
| 169 | <xsl:attribute name="type">ref</xsl:attribute>
|
---|
| 170 | </xsl:element>
|
---|
| 171 | EOF
|
---|
| 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"/>
|
---|
| 178 | EOF
|
---|
| 179 | fi
|
---|
| 180 | cat >>$SPECIAL_FILE << EOF
|
---|
| 181 | <!-- End dependencies -->
|
---|
| 182 | </module>
|
---|
| 183 | EOF
|
---|
| 184 | cat >> tmpfile << EOF
|
---|
| 185 | <xsl:element name="dependency">
|
---|
| 186 | <xsl:attribute name="status">
|
---|
| 187 | <xsl:value-of select="\$status"/>
|
---|
| 188 | </xsl:attribute>
|
---|
[7a0c3d2] | 189 | <xsl:attribute name="build">
|
---|
| 190 | <xsl:value-of select="\$build"/>
|
---|
| 191 | </xsl:attribute>
|
---|
[e576789] | 192 | <xsl:attribute name="name">$packname</xsl:attribute>
|
---|
| 193 | <xsl:attribute name="type">ref</xsl:attribute>
|
---|
| 194 | </xsl:element>
|
---|
| 195 | EOF
|
---|
[0cd09c6] | 196 | precpack=$packname
|
---|
[e576789] | 197 | done
|
---|
| 198 | cat >>$SPECIAL_FILE << EOF
|
---|
| 199 | </package>
|
---|
| 200 | </xsl:when>
|
---|
| 201 | EOF
|
---|
| 202 | cat >> tmpfile << EOF
|
---|
| 203 | </xsl:when>
|
---|
| 204 | EOF
|
---|
| 205 | done
|
---|
| 206 |
|
---|
| 207 | for 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'">
|
---|
[1646303] | 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>
 </xsl:text>
|
---|
| 217 | <xsl:element name="name">$id</xsl:element>
|
---|
| 218 | <xsl:text>
 </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>
 </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>
|
---|
[e576789] | 229 | <!-- Dependencies -->
|
---|
[1646303] | 230 | <xsl:apply-templates select=".//para[@role='required' or
|
---|
| 231 | @role='recommended' or
|
---|
| 232 | @role='optional']"
|
---|
| 233 | mode="dependency"/>
|
---|
[e576789] | 234 | <!-- End dependencies -->
|
---|
[1646303] | 235 | <xsl:text>
 </xsl:text>
|
---|
| 236 | </module><xsl:text>
</xsl:text>
|
---|
| 237 | </xsl:when>
|
---|
| 238 | <xsl:otherwise>
|
---|
| 239 | <xsl:text> </xsl:text>
|
---|
| 240 | <package><xsl:text>
 </xsl:text>
|
---|
| 241 | <xsl:element name="name">$id</xsl:element>
|
---|
| 242 | <xsl:text>
 </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>
 </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>
 </xsl:text>
|
---|
| 260 | </package><xsl:text>
</xsl:text>
|
---|
| 261 | </xsl:otherwise>
|
---|
| 262 | </xsl:choose>
|
---|
[e576789] | 263 | </xsl:when>
|
---|
| 264 | EOF
|
---|
| 265 | done
|
---|
| 266 |
|
---|
| 267 | cat >>$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>
|
---|
| 279 | EOF
|
---|
| 280 | cat $SPECIAL_FILE tmpfile > tmpfile1
|
---|
| 281 | mv tmpfile1 $SPECIAL_FILE
|
---|
| 282 | rm tmpfile
|
---|
| 283 | cat >> $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>
|
---|
| 292 | EOF
|
---|