[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 |
|
---|
[e6a1ec3] | 90 | # Taking packages contained in pages installing several packages (x7* except
|
---|
| 91 | # x7driver, kf5-frameworks, and plasma5-all), as versionned modules.
|
---|
[e576789] | 92 | # We also write a dependency expansion when a dep is of the form
|
---|
[e6a1ec3] | 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
|
---|
[e576789] | 95 | cat >tmpfile << EOF
|
---|
| 96 | <xsl:template name="expand-deps">
|
---|
| 97 | <xsl:param name="section"/>
|
---|
| 98 | <xsl:param name="status"/>
|
---|
[7a0c3d2] | 99 | <xsl:param name="build"/>
|
---|
[e576789] | 100 | <xsl:choose>
|
---|
| 101 | EOF
|
---|
[0cd09c6] | 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
|
---|
[e576789] | 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
|
---|
[e6a1ec3] | 116 | # We extract the list of packages for those pages from
|
---|
| 117 | # the "cat" command that creates the md5 file. We assume
|
---|
[e576789] | 118 | # that the preceding package is a dependency of the following,
|
---|
| 119 | # except the first.
|
---|
[e6a1ec3] | 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/-&.*//')"
|
---|
[e576789] | 129 |
|
---|
[0cd09c6] | 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
|
---|
[e6a1ec3] | 134 | # We extract the version from the ENTITY parts of the .xml file.
|
---|
[0cd09c6] | 135 | packversion=$(grep "ENTITY ${pack}-version" $file | \
|
---|
| 136 | sed 's@[^"]*"\([^"]*\).*@\1@')
|
---|
| 137 | else
|
---|
[e6a1ec3] | 138 | packname=${pack%-[[:digit:]]*}
|
---|
[0cd09c6] | 139 | packversion=$(echo $pack | sed 's/[^.]*-\([.[:digit:]]*\)\.tar.*/\1/')
|
---|
| 140 | fi
|
---|
[e576789] | 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>
|
---|
[7a0c3d2] | 158 | <xsl:attribute name="build">before</xsl:attribute>
|
---|
[e576789] | 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>
|
---|
[7a0c3d2] | 180 | <xsl:attribute name="build">
|
---|
| 181 | <xsl:value-of select="\$build"/>
|
---|
| 182 | </xsl:attribute>
|
---|
[e576789] | 183 | <xsl:attribute name="name">$packname</xsl:attribute>
|
---|
| 184 | <xsl:attribute name="type">ref</xsl:attribute>
|
---|
| 185 | </xsl:element>
|
---|
| 186 | EOF
|
---|
[0cd09c6] | 187 | precpack=$packname
|
---|
[e576789] | 188 | done
|
---|
| 189 | cat >>$SPECIAL_FILE << EOF
|
---|
| 190 | </package>
|
---|
| 191 | </xsl:when>
|
---|
| 192 | EOF
|
---|
| 193 | cat >> tmpfile << EOF
|
---|
| 194 | </xsl:when>
|
---|
| 195 | EOF
|
---|
| 196 | done
|
---|
| 197 |
|
---|
| 198 | for ver_ent in $EXCEPTIONS; do
|
---|
| 199 | id=$(grep 'xreflabel=".*'$ver_ent $BLFS_XML | sed 's@.*id="\([^"]*\)".*@\1@')
|
---|
| 200 | [[ -z $id ]] && continue
|
---|
| 201 | cat >>$SPECIAL_FILE << EOF
|
---|
| 202 | <xsl:when test="@id='$id'">
|
---|
[1646303] | 203 | <!-- if there is a sect1 ancestor, we have a module -->
|
---|
| 204 | <xsl:choose>
|
---|
| 205 | <xsl:when test="ancestor::sect1">
|
---|
| 206 | <xsl:text> </xsl:text>
|
---|
| 207 | <module><xsl:text>
 </xsl:text>
|
---|
| 208 | <xsl:element name="name">$id</xsl:element>
|
---|
| 209 | <xsl:text>
 </xsl:text>
|
---|
| 210 | <xsl:element name="version">$ver_ent</xsl:element>
|
---|
| 211 | <xsl:if
|
---|
| 212 | test="document(\$installed-packages)//package[name=current()/@id]">
|
---|
| 213 | <xsl:text>
 </xsl:text>
|
---|
| 214 | <xsl:element name="inst-version">
|
---|
| 215 | <xsl:value-of
|
---|
| 216 | select="document(\$installed-packages
|
---|
| 217 | )//package[name=current()/@id]/version"/>
|
---|
| 218 | </xsl:element>
|
---|
| 219 | </xsl:if>
|
---|
[e576789] | 220 | <!-- Dependencies -->
|
---|
[1646303] | 221 | <xsl:apply-templates select=".//para[@role='required' or
|
---|
| 222 | @role='recommended' or
|
---|
| 223 | @role='optional']"
|
---|
| 224 | mode="dependency"/>
|
---|
[e576789] | 225 | <!-- End dependencies -->
|
---|
[1646303] | 226 | <xsl:text>
 </xsl:text>
|
---|
| 227 | </module><xsl:text>
</xsl:text>
|
---|
| 228 | </xsl:when>
|
---|
| 229 | <xsl:otherwise>
|
---|
| 230 | <xsl:text> </xsl:text>
|
---|
| 231 | <package><xsl:text>
 </xsl:text>
|
---|
| 232 | <xsl:element name="name">$id</xsl:element>
|
---|
| 233 | <xsl:text>
 </xsl:text>
|
---|
| 234 | <xsl:element name="version">$ver_ent</xsl:element>
|
---|
| 235 | <xsl:if
|
---|
| 236 | test="document(\$installed-packages)//package[name=current()/@id]">
|
---|
| 237 | <xsl:text>
 </xsl:text>
|
---|
| 238 | <xsl:element name="inst-version">
|
---|
| 239 | <xsl:value-of
|
---|
| 240 | select="document(\$installed-packages
|
---|
| 241 | )//package[name=current()/@id]/version"/>
|
---|
| 242 | </xsl:element>
|
---|
| 243 | </xsl:if>
|
---|
| 244 | <!-- Dependencies -->
|
---|
| 245 | <xsl:apply-templates select=".//para[@role='required' or
|
---|
| 246 | @role='recommended' or
|
---|
| 247 | @role='optional']"
|
---|
| 248 | mode="dependency"/>
|
---|
| 249 | <!-- End dependencies -->
|
---|
| 250 | <xsl:text>
 </xsl:text>
|
---|
| 251 | </package><xsl:text>
</xsl:text>
|
---|
| 252 | </xsl:otherwise>
|
---|
| 253 | </xsl:choose>
|
---|
[e576789] | 254 | </xsl:when>
|
---|
| 255 | EOF
|
---|
| 256 | done
|
---|
| 257 |
|
---|
| 258 | cat >>$SPECIAL_FILE << EOF
|
---|
| 259 | <xsl:otherwise>
|
---|
| 260 | <xsl:apply-templates
|
---|
| 261 | select="self::node()[contains(translate(@xreflabel,
|
---|
| 262 | '123456789',
|
---|
| 263 | '000000000'),
|
---|
| 264 | '-0')
|
---|
| 265 | ]"
|
---|
| 266 | mode="normal"/>
|
---|
| 267 | </xsl:otherwise>
|
---|
| 268 | </xsl:choose>
|
---|
| 269 | </xsl:template>
|
---|
| 270 | EOF
|
---|
| 271 | cat $SPECIAL_FILE tmpfile > tmpfile1
|
---|
| 272 | mv tmpfile1 $SPECIAL_FILE
|
---|
| 273 | rm tmpfile
|
---|
| 274 | cat >> $SPECIAL_FILE << EOF
|
---|
| 275 | <xsl:otherwise>
|
---|
| 276 | <xsl:message>
|
---|
| 277 | <xsl:text>You should not be seeing this</xsl:text>
|
---|
| 278 | </xsl:message>
|
---|
| 279 | </xsl:otherwise>
|
---|
| 280 | </xsl:choose>
|
---|
| 281 | </xsl:template>
|
---|
| 282 | </xsl:stylesheet>
|
---|
| 283 | EOF
|
---|