[e576789] | 1 | #!/bin/bash
|
---|
| 2 |
|
---|
[56178ba] | 3 | # $Id$
|
---|
[e576789] | 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
|
---|
[5fb012d] | 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
|
---|
[e576789] | 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 |
|
---|
| 26 | BLFS_XML=$1
|
---|
| 27 | if ! test -f ${BLFS_XML}; then
|
---|
| 28 | echo File \`${BLFS_XML}\' does not exist
|
---|
| 29 | exit 1
|
---|
| 30 | fi
|
---|
| 31 | SPECIAL_FILE=$2
|
---|
| 32 | if test -z "${SPECIAL_FILE}"; then SPECIAL_FILE=specialCases.xsl;fi
|
---|
| 33 | BLFS_DIR=$3
|
---|
| 34 | if test -z "${BLFS_DIR}"; then BLFS_DIR=$(cd $(dirname ${BLFS_XML})/.. ; pwd);fi
|
---|
| 35 |
|
---|
| 36 | # Packages whose version does not begin with a number
|
---|
[4f3c433] | 37 | EXCEPTIONS=$(grep 'ENTITY.*version[ ]*"[^0-9"&.].*[0-9]' ${BLFS_DIR}/packages.ent |
|
---|
[e576789] | 38 | sed 's@^[^"]*"\([^"]*\)".*@\1@')
|
---|
| 39 |
|
---|
[5fb012d] | 40 | # Non-versioned packages:
|
---|
[625cb14] | 41 | NV_LIST="postlfs-config-profile postlfs-config-random postlfs-config-vimrc \
|
---|
| 42 | xorg-env kde-pre-install-config kf5-intro \
|
---|
| 43 | lxqt-pre-install lxqt-post-install ojdk-conf tex-path"
|
---|
[5fb012d] | 44 |
|
---|
[e576789] | 45 | # Set PATH to be sure to find udevadm
|
---|
| 46 | SAVPATH=$PATH
|
---|
| 47 | PATH=/bin:/sbin:/usr/bin:/usr/sbin
|
---|
| 48 | UDEVVERSION=$(udevadm --version)
|
---|
| 49 |
|
---|
| 50 | cat >$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>
 </xsl:text>
|
---|
| 61 | <xsl:element name="name"><xsl:value-of select="@id"/></xsl:element>
|
---|
| 62 | <xsl:text>
 </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>
 </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>
 </xsl:text>
|
---|
| 80 | </package><xsl:text>
</xsl:text>
|
---|
| 81 | </xsl:when>
|
---|
[82bd7a6] | 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>
|
---|
[e576789] | 89 | EOF
|
---|
| 90 |
|
---|
[5fb012d] | 91 | # Non-versionned packages. Add to NV_LIST if you need more.
|
---|
| 92 | for 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>
 </xsl:text>
|
---|
| 97 | <xsl:element name="name">$nv_id</xsl:element>
|
---|
| 98 | <xsl:text>
 </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>
 </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>
 </xsl:text>
|
---|
| 116 | </package><xsl:text>
</xsl:text>
|
---|
| 117 | </xsl:when>
|
---|
| 118 | EOF
|
---|
| 119 | done
|
---|
| 120 |
|
---|
[e576789] | 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
|
---|
| 125 | cat >tmpfile << EOF
|
---|
| 126 | <xsl:template name="expand-deps">
|
---|
| 127 | <xsl:param name="section"/>
|
---|
| 128 | <xsl:param name="status"/>
|
---|
[7a0c3d2] | 129 | <xsl:param name="build"/>
|
---|
[e576789] | 130 | <xsl:choose>
|
---|
| 131 | EOF
|
---|
| 132 | for 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>
 </xsl:text>
|
---|
| 138 | <xsl:element name="name">$id</xsl:element>
|
---|
| 139 | <xsl:text>
 </xsl:text>
|
---|
| 140 | EOF
|
---|
| 141 | cat >> tmpfile << EOF
|
---|
| 142 | <xsl:when test="\$section='$id'">
|
---|
| 143 | EOF
|
---|
| 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' |
|
---|
[342c862] | 151 | awk '{ print $NF }' | sed 's/-&.*//')"
|
---|
[e576789] | 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>
 </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 -->
|
---|
| 178 | EOF
|
---|
| 179 | if test $precpack != NONE; then
|
---|
| 180 | cat >>$SPECIAL_FILE << EOF
|
---|
| 181 | <xsl:element name="dependency">
|
---|
| 182 | <xsl:attribute name="status">required</xsl:attribute>
|
---|
[7a0c3d2] | 183 | <xsl:attribute name="build">before</xsl:attribute>
|
---|
[e576789] | 184 | <xsl:attribute name="name">$precpack</xsl:attribute>
|
---|
| 185 | <xsl:attribute name="type">ref</xsl:attribute>
|
---|
| 186 | </xsl:element>
|
---|
| 187 | EOF
|
---|
| 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"/>
|
---|
| 194 | EOF
|
---|
| 195 | fi
|
---|
| 196 | cat >>$SPECIAL_FILE << EOF
|
---|
| 197 | <!-- End dependencies -->
|
---|
| 198 | </module>
|
---|
| 199 | EOF
|
---|
| 200 | cat >> tmpfile << EOF
|
---|
| 201 | <xsl:element name="dependency">
|
---|
| 202 | <xsl:attribute name="status">
|
---|
| 203 | <xsl:value-of select="\$status"/>
|
---|
| 204 | </xsl:attribute>
|
---|
[7a0c3d2] | 205 | <xsl:attribute name="build">
|
---|
| 206 | <xsl:value-of select="\$build"/>
|
---|
| 207 | </xsl:attribute>
|
---|
[e576789] | 208 | <xsl:attribute name="name">$packname</xsl:attribute>
|
---|
| 209 | <xsl:attribute name="type">ref</xsl:attribute>
|
---|
| 210 | </xsl:element>
|
---|
| 211 | EOF
|
---|
| 212 | done
|
---|
| 213 | cat >>$SPECIAL_FILE << EOF
|
---|
| 214 | </package>
|
---|
| 215 | </xsl:when>
|
---|
| 216 | EOF
|
---|
| 217 | cat >> tmpfile << EOF
|
---|
| 218 | </xsl:when>
|
---|
| 219 | EOF
|
---|
| 220 | done
|
---|
| 221 |
|
---|
| 222 | for 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>
 </xsl:text>
|
---|
| 229 | <xsl:element name="name">$id</xsl:element>
|
---|
| 230 | <xsl:text>
 </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>
 </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>
 </xsl:text>
|
---|
| 248 | </package><xsl:text>
</xsl:text>
|
---|
| 249 | </xsl:when>
|
---|
| 250 | EOF
|
---|
| 251 | done
|
---|
| 252 |
|
---|
| 253 | cat >>$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>
|
---|
| 265 | EOF
|
---|
| 266 | cat $SPECIAL_FILE tmpfile > tmpfile1
|
---|
| 267 | mv tmpfile1 $SPECIAL_FILE
|
---|
| 268 | rm tmpfile
|
---|
| 269 | cat >> $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>
|
---|
| 278 | EOF
|
---|