diff options
author | 2004-06-30 02:40:33 +0000 | |
---|---|---|
committer | 2004-06-30 02:40:33 +0000 | |
commit | 353d297390dbb424b9152383186141496e486f3a (patch) | |
tree | 1d62f8700ce891a36047850d2d0b85aeda1da271 | |
download | build-docbook-catalog-353d297390dbb424b9152383186141496e486f3a.tar.gz build-docbook-catalog-353d297390dbb424b9152383186141496e486f3a.tar.bz2 build-docbook-catalog-353d297390dbb424b9152383186141496e486f3a.zip |
see bug 52725v1.1
Signed-off-by: Aron Griffis <agriffis@gentoo.org>
-rw-r--r-- | README | 33 | ||||
-rwxr-xr-x | build-docbook-catalog | 265 |
2 files changed, 298 insertions, 0 deletions
@@ -0,0 +1,33 @@ +$Header: /usr/local/src/gentoo/gentoo-src/cvsroot/gentoo-src/build-docbook-catalog/README,v 1.1 2004/06/30 02:40:42 agriffis Exp $ + +This is the source for app-text/build-docbook-catalog, which is a +script to regenerate the xml docbook catalog. + +To make a release of this script, do the following: + +1. Commit your changes and copy the versioned, bzipped script to + gentoo's distfiles: + + cvs commit build-docbook-catalog + rev=$(awk '/^# .Header:/{print $4;exit}' build-docbook-catalog) + echo $rev + bzip2 -c build-docbook-catalog \ + >/usr/portage/distfiles/build-docbook-catalog-${rev}.bz2 + scp /usr/portage/distfiles/build-docbook-catalog-${rev}.bz2 \ + gentoo:/space/distfiles-local/ + +2. Make a new version of the build-docbook-catalog ebuild: + + ego build-docbook-catalog + cp $(/bin/ls -t1 *.ebuild | head -n 1) build-docbook-catalog-${rev}.ebuild + ekeyword ~all build-docbook-catalog-${rev}.ebuild + +3. Do the normal steps to generate a digest, mark the previous version + stable, use echangelog to add a ChangeLog entry, etc. + + cvs add build-docbook-catalog-${rev}.ebuild + ebuild build-docbook-catalog-${rev}.ebuild digest + echangelog + repoman commit -m "version bump to ${rev}" + +vim:sw=4 expandtab diff --git a/build-docbook-catalog b/build-docbook-catalog new file mode 100755 index 0000000..cf5f5e2 --- /dev/null +++ b/build-docbook-catalog @@ -0,0 +1,265 @@ +#!/bin/bash +# $Header: /usr/local/src/gentoo/gentoo-src/cvsroot/gentoo-src/build-docbook-catalog/build-docbook-catalog,v 1.1 2004/06/30 02:40:33 agriffis Exp $ +# +# build-docbook-catalog: populate /etc/xml/docbook based in +# installed docbook-xml-dtd versions. +# +# Copyright 2004 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# written by Aron Griffis +# + +ROOTCATALOG=/etc/xml/catalog +CATALOG=/etc/xml/docbook +DOCBOOKDIR=/usr/share/sgml/docbook +DTDS= +LATEST_DTD= +LATEST_DATE= + +# +# main (called from bottom) +# +main() { + typeset d v + + create_catalogs # will exit on error + populate_xsl + + # Clean out old dtds from catalog + echo "Cleaning out old DocBook XML versions from ${CATALOG} and ${ROOTCATALOG}" + clean_catalog "${DOCBOOKDIR}/xml-dtd-[^/\"']*/[^/\"']*" ${CATALOG} + clean_catalog "${DOCBOOKDIR}/xml-dtd-[^/\"']*/[^/\"']*" ${ROOTCATALOG} + + if set_dtds; then + for d in ${DTDS}; do + populate_dtd ${d} + done + populate_entities + fi + + exit 0 +} + +# +# fill in the DTDS variable based on installed versions +# +set_dtds() { + DTDS=$(find ${DOCBOOKDIR} -path '*/xml-dtd-*/docbookx.dtd') + if [[ -z ${DTDS} ]]; then + echo "No installed DocBook XML DTDs found" + return 1 + else + return 0 + fi +} + +# +# create the catalogs root and docbook specific +# +create_catalogs() { + if [[ ! -r ${ROOTCATALOG} ]] ; then + echo "Creating XML Catalog root ${ROOTCATALOG}" + /usr/bin/xmlcatalog --noout --create ${ROOTCATALOG} + if [[ ! -r ${ROOTCATALOG} ]] ; then + echo "Failed creating ${ROOTCATALOG}, aborting" >&2 + exit 1 + fi + else + echo "Found XML Catalog root ${ROOTCATALOG}" + # clean out existing entries + echo " Cleaning existing ${CATALOG} delegates from ${ROOTCATALOG}" + clean_catalog "file://${CATALOG}" ${ROOTCATALOG} + fi + + if [[ ! -r ${CATALOG} ]] ; then + echo "Creating DocBook XML Catalog ${CATALOG}" + /usr/bin/xmlcatalog --noout --create ${CATALOG} + if [[ ! -r ${CATALOG} ]] ; then + echo "Failed creating ${CATALOG}, aborting" >&2 + exit 1 + fi + else + echo "Found DocBook XML Catalog ${CATALOG}" + fi + + # dtd pointers + echo " Populating ${ROOTCATALOG} with DTD delegates to ${CATALOG}" + xmlcatalog --noout --add "delegatePublic" "-//OASIS//ENTITIES DocBook XML" "file://${CATALOG}" ${ROOTCATALOG} + xmlcatalog --noout --add "delegatePublic" "-//OASIS//DTD DocBook XML" "file://${CATALOG}" ${ROOTCATALOG} + xmlcatalog --noout --add "delegateSystem" "http://www.oasis-open.org/docbook/" "file://${CATALOG}" ${ROOTCATALOG} + xmlcatalog --noout --add "delegateURI" "http://www.oasis-open.org/docbook/" "file://${CATALOG}" ${ROOTCATALOG} + xmlcatalog --noout --add "delegateSystem" "http://docbook.sourceforge.net/release/xsl/" "file://${CATALOG}" ${ROOTCATALOG} + xmlcatalog --noout --add "delegateURI" "http://docbook.sourceforge.net/release/xsl/" "file://${CATALOG}" ${ROOTCATALOG} + + # entities pointer + echo " Populating ${ROOTCATALOG} with ISO entities delegate to ${CATALOG}" + xmlcatalog --noout --add "delegatePublic" "ISO 8879:1986" "file://${CATALOG}" ${ROOTCATALOG} +} + +# +# clean_catalog +# $1 == regex to clean +# $2 == catalog +# +clean_catalog() { + typeset list f regex=$1 catalog=$2 + + list=$(egrep --only-matching "${regex}" "${catalog}" | sort -u) + for f in ${list}; do + xmlcatalog --noout --del "${f}" ${catalog} + done +} + +# +# populate a specific dtd version into the docbook catalog +# $1 == /path/to/docbookx.dtd +# +populate_dtd() { + typeset dtd=$1 docbookdir=${1%/*} dtd_date + typeset v=${docbookdir##*-} + + # sanity check + if [[ ${dtd} != */xml-dtd-*/* ]]; then + echo "Warning: I don't understand \"${dtd}\"" >&2 + return + fi + echo "Found DocBook XML ${v} in ${docbookdir}" + + # Populate the docbook catalog with this version + echo " Populating ${CATALOG} based on ${docbookdir}" + xmlcatalog --noout --add "public" "-//OASIS//ELEMENTS DocBook XML Information Pool V${v}//EN" "file://${docbookdir}/dbpoolx.mod" ${CATALOG} + xmlcatalog --noout --add "public" "-//OASIS//DTD DocBook XML V${v}//EN" "file://${docbookdir}/docbookx.dtd" ${CATALOG} + xmlcatalog --noout --add "public" "-//OASIS//ENTITIES DocBook XML Character Entities V${v}//EN" "file://${docbookdir}/dbcentx.mod" ${CATALOG} + xmlcatalog --noout --add "public" "-//OASIS//ENTITIES DocBook XML Notations V${v}//EN" "file://${docbookdir}/dbnotnx.mod" ${CATALOG} + xmlcatalog --noout --add "public" "-//OASIS//ENTITIES DocBook XML Additional General Entities V${v}//EN" "file://${docbookdir}/dbgenent.mod" ${CATALOG} + xmlcatalog --noout --add "public" "-//OASIS//ELEMENTS DocBook XML Document Hierarchy V${v}//EN" "file://${docbookdir}/dbhierx.mod" ${CATALOG} + xmlcatalog --noout --add "public" "-//OASIS//DTD XML Exchange Table Model 19990315//EN" "file://${docbookdir}/soextblx.dtd" ${CATALOG} + xmlcatalog --noout --add "public" "-//OASIS//DTD DocBook XML CALS Table Model V${v}//EN" "file://${docbookdir}/calstblx.dtd" ${CATALOG} + xmlcatalog --noout --add "rewriteSystem" "http://www.oasis-open.org/docbook/xml/${v}" "file://${docbookdir}" ${CATALOG} + xmlcatalog --noout --add "rewriteURI" "http://www.oasis-open.org/docbook/xml/${v}" "file://${docbookdir}" ${CATALOG} + + # grab the RCS date from docbookx.dtd for comparison purposes + if [[ ! -f ${docbookdir}/ent/iso-lat1.ent ]]; then + echo " No entities available for ${dtd}" + return 0 + fi + dtd_date=$(egrep --only-matching --max-count=1 \ + '[0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}' "${dtd}") + if [[ -z ${dtd_date} ]]; then + echo " Couldn't find RCS date in ${dtd}, ignoring entities" + return 0 + fi + echo " RCS datestamp in ${dtd} is ${dtd_date}" + dtd_date=$(date -d "$dtd_date" +%s) + if [[ -z $LATEST_DTD || $dtd_date -gt $LATEST_DATE ]]; then + LATEST_DATE=${dtd_date} + LATEST_DTD=${dtd} + fi +} + +# +# populate ISO DocBook entities from the most recent DTD +# +populate_entities() { + typeset isodir=${LATEST_DTD%/*}/ent i j + typeset -a entities avail + + # sanity check + if [[ -z ${LATEST_DTD} || ! -d ${isodir} ]]; then + echo "No ISO DocBook entities available for catalog" + return 0 + fi + echo "Using ISO DocBook entities from ${isodir}" + + # here are the entities we know about; + # note these must remain sorted! + entities=( + "iso-amsa.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Arrow Relations//EN" + "iso-amsb.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Binary Operators//EN" + "iso-amsc.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Delimiters//EN" + "iso-amsn.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Negated Relations//EN" + "iso-amso.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Ordinary//EN" + "iso-amsr.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Relations//EN" + "iso-box.ent" "ISO 8879:1986//ENTITIES Box and Line Drawing//EN" + "iso-cyr1.ent" "ISO 8879:1986//ENTITIES Russian Cyrillic//EN" + "iso-cyr2.ent" "ISO 8879:1986//ENTITIES Non-Russian Cyrillic//EN" + "iso-dia.ent" "ISO 8879:1986//ENTITIES Diacritical Marks//EN" + "iso-grk1.ent" "ISO 8879:1986//ENTITIES Greek Letters//EN" + "iso-grk2.ent" "ISO 8879:1986//ENTITIES Monotoniko Greek//EN" + "iso-grk3.ent" "ISO 8879:1986//ENTITIES Greek Symbols//EN" + "iso-grk4.ent" "ISO 8879:1986//ENTITIES Alternative Greek Symbols//EN" + "iso-lat1.ent" "ISO 8879:1986//ENTITIES Added Latin 1//EN" + "iso-lat2.ent" "ISO 8879:1986//ENTITIES Added Latin 2//EN" + "iso-num.ent" "ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN" + "iso-pub.ent" "ISO 8879:1986//ENTITIES Publishing//EN" + "iso-tech.ent" "ISO 8879:1986//ENTITIES General Technical//EN" + ) + + # here are the entities available; assume no spaces in filenames... + avail=($(ls ${isodir} | sort)) + + # double-check the lists + echo " Populating ${CATALOG} with ISO DocBook entities" + i=0 ; j=0 + while [[ ${i} -lt ${#entities[@]} || ${j} -lt ${#avail[@]} ]]; do + if [[ ${i} -ge ${#entities[@]} ]]; then + echo "Warning: Extra ISO entities file: ${avail[j]}" + let j=j+1 + elif [[ ${j} -ge ${#avail[@]} ]]; then + echo "Warning: Entities file not found: ${entities[i]}" + let i=i+2 + elif [[ ${avail[j]} < ${entities[i]} ]]; then + echo "Warning: Extra ISO entities file: ${avail[j]}" + let j=j+1 + elif [[ ${entities[i]} < ${avail[j]} ]]; then + echo "Warning: Entities file not found: ${entities[i]}" + let i=i+2 + elif [[ ${entities[i]} == ${avail[j]} ]]; then + xmlcatalog --noout --add "public" "${entities[i+1]}" \ + "file://${isodir}/${entities[i]}" ${CATALOG} + let j=j+1 + let i=i+2 + else + echo "${0}: Whoah, shouldn't be here, aborting" >&2 + exit 1 + fi + done +} + +# +# populate XSL stylesheets +# +populate_xsl() { + typeset listed avail f + + # Delete current entries from the catalog + clean_catalog "${DOCBOOKDIR}/xsl-stylesheets-[0-9\.]+" $CATALOG + clean_catalog "${DOCBOOKDIR}/xsl-stylesheets-[0-9\.]+" $ROOTCATALOG + + # Find the available XSL stylesheets. In theory there should only + # be one match since these aren't slotted, but restrict to the + # first match anyway... + avail=$(find ${DOCBOOKDIR%/*} -name chunk.xsl | head -n 1) + if [[ -z ${avail} ]]; then + echo "Could not locate chunk.xsl of DocBook XSL stylesheets" >&2 + return 1 + fi + xsldir=${avail%/*/*} + if [[ ! -e ${xsldir}/html/docbook.xsl || ! -e ${xsldir}/common/l10n.xml ]]; then + echo "DocBook XSLT stylesheets are missing files from ${xsldir}" >&2 + return 1 + fi + + # Populate catalog with XSL entries + echo "Found DocBook XSL stylesheets in ${xsldir}" + echo " Populating ${CATALOG} with XSL stylesheets" + for version in current 1.39 1.40 1.41 1.42 1.43 1.44 1.45 1.46 1.47 \ + 1.48 1.49 1.50 ${xsldir##*-} + do + xmlcatalog --noout --add "rewriteSystem" "http://docbook.sourceforge.net/release/xsl/${version}" "file://${xsldir}" ${CATALOG} + xmlcatalog --noout --add "rewriteURI" "http://docbook.sourceforge.net/release/xsl/${version}" "file://${xsldir}" ${CATALOG} + done +} + +# Call the main routine +main |