#!/bin/bash
#-------------------------------------------------------------------------
# generates an xsl stylesheet containing a template for special
# cases in the book:
# - If the version does not begin with a number, it is impossible to know
# where the package name ends and where the version begins. We therefore
# use the ENTITY at the beginning of the validated full-xml.
# - If a package is part of a group of xorg packages (proto, fonts, etc)
# there is no easy way to extract it from the xml. We use the ENTITY at
# the top of each file x7*.xml
# - Some non-versioned packages are needed as dependencies of others: we
# attribute version 1.0.0 to them. It is just used to know if the package
# is installed, by checking inst-version.
# - If a package is versioned but the version is not mentioned in the book
# (currently only udev), we retrieve the version by other means
#-------------------------------------------------------------------------
# Arguments:
# $1 contains the name of the validated xml book
# $2 contains the name of the ouput xsl file
# $3 contains the name of the book sources directory
#-------------------------------------------------------------------------
BLFS_XML=$1
if ! test -f ${BLFS_XML}; then
echo File \`${BLFS_XML}\' does not exist
exit 1
fi
SPECIAL_FILE=$2
if test -z "${SPECIAL_FILE}"; then SPECIAL_FILE=specialCases.xsl;fi
BLFS_DIR=$3
if test -z "${BLFS_DIR}"; then BLFS_DIR=$(cd $(dirname ${BLFS_XML})/.. ; pwd);fi
# Packages whose version does not begin with a number
EXCEPTIONS=$(grep 'ENTITY.*version[ ]*"[^0-9"&.].*[0-9]' ${BLFS_DIR}/packages.ent |
sed 's@^[^"]*"\([^"]*\)".*@\1@')
# Non-versioned packages:
NV_LIST="postlfs-config-profile postlfs-config-random postlfs-config-vimrc \
initramfs xorg-env kde-pre-install-config kf5-intro \
lxqt-pre-install lxqt-post-install ojdk-conf tex-path"
cat >$SPECIAL_FILE << EOF
EOF
# Non-versionned packages. Add to NV_LIST if you need more.
for nv_id in $NV_LIST; do
cat >>$SPECIAL_FILE << EOF
$nv_id
1.0.0
EOF
done
# Taking packages contained in pages installing several packages (x7* except
# x7driver, kf5-frameworks, and plasma5-all), as versionned modules.
# We also write a dependency expansion when a dep is of the form
# xorg7-something or kf5-frameworks or plasma5-build. Since that is another
# template, we need a temporary file, which we shall concatenate at the end
cat >tmpfile << EOF
EOF
for file in $(ls ${BLFS_DIR}/x/installing/x7* | grep -v x7driver) \
${BLFS_DIR}/kde/kf5/kf5-frameworks.xml \
${BLFS_DIR}/kde/plasma5/plasma-all.xml; do
id=$(grep xreflabel $file | sed 's@.*id="\([^"]*\).*@\1@')
cat >>$SPECIAL_FILE << EOF
$id
EOF
cat >> tmpfile << EOF
EOF
# We extract the list of packages for those pages from
# the "cat" command that creates the md5 file. We assume
# that the preceding package is a dependency of the following,
# except the first.
# note that some pages may have several "cat" command, so we have to
# make a complex regex for the first line to save. All those lines have
# .md5 in them except the one for x7legacy that has .dat.
# we need also to remove lines beginning with #.
# Note that only xorg pages have '&' in them. So for kde
# pages, what is extracted it the full tarball name.
list_cat="$(sed -n '/>cat.*\.\(md5\|dat\)/,/EOF
>$SPECIAL_FILE << EOF
$packname
$packversion
EOF
if test $precpack != NONE; then
cat >>$SPECIAL_FILE << EOF
required
before
$precpack
ref
EOF
else
cat >>$SPECIAL_FILE << EOF
EOF
fi
cat >>$SPECIAL_FILE << EOF
EOF
cat >> tmpfile << EOF
$packname
ref
EOF
precpack=$packname
done
cat >>$SPECIAL_FILE << EOF
EOF
cat >> tmpfile << EOF
EOF
done
for ver_ent in $EXCEPTIONS; do
id=$(grep 'xreflabel=".*'$ver_ent $BLFS_XML | sed 's@.*id="\([^"]*\)".*@\1@')
[[ -z $id ]] && continue
cat >>$SPECIAL_FILE << EOF
$id
$ver_ent
$id
$ver_ent
EOF
done
cat >>$SPECIAL_FILE << EOF
EOF
cat $SPECIAL_FILE tmpfile > tmpfile1
mv tmpfile1 $SPECIAL_FILE
rm tmpfile
cat >> $SPECIAL_FILE << EOF
You should not be seeing this
EOF