/[gentoo-src]/build-docbook-catalog/build-docbook-catalog
Gentoo

Contents of /build-docbook-catalog/build-docbook-catalog

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations) (download)
Thu Jul 22 22:35:18 2004 UTC (10 years, 1 month ago) by agriffis
Branch: MAIN
Changes since 1.1: +34 -15 lines
quiet down the script unless --verbose is specified

1 agriffis 1.1 #!/bin/bash
2 agriffis 1.2 # $Header: /var/cvsroot/gentoo-src/build-docbook-catalog/build-docbook-catalog,v 1.1 2004/06/30 02:40:33 agriffis Exp $
3 agriffis 1.1 #
4     # build-docbook-catalog: populate /etc/xml/docbook based in
5     # installed docbook-xml-dtd versions.
6     #
7     # Copyright 2004 Gentoo Foundation
8     # Distributed under the terms of the GNU General Public License v2
9     # written by Aron Griffis
10     #
11    
12     ROOTCATALOG=/etc/xml/catalog
13     CATALOG=/etc/xml/docbook
14     DOCBOOKDIR=/usr/share/sgml/docbook
15     DTDS=
16     LATEST_DTD=
17     LATEST_DATE=
18 agriffis 1.2 VERBOSE=false
19     ZERO=${0##*/}
20 agriffis 1.1
21     #
22     # main (called from bottom)
23     #
24     main() {
25 agriffis 1.2 typeset d v opts
26    
27     opts=$(getopt -o v --long verbose -n "$ZERO" -- "$@") || exit 1
28     eval set -- "$opts"
29     while true; do
30     case "$1" in
31     -v|--verbose) VERBOSE=true ; shift ;;
32     --) shift ; break ;;
33     *) echo "Options parsing failed on $1!" >&2 ; exit 1 ;;
34     esac
35     done
36 agriffis 1.1
37     create_catalogs # will exit on error
38     populate_xsl
39    
40     # Clean out old dtds from catalog
41 agriffis 1.2 verb "Cleaning out old DocBook XML versions from ${CATALOG} and ${ROOTCATALOG}"
42 agriffis 1.1 clean_catalog "${DOCBOOKDIR}/xml-dtd-[^/\"']*/[^/\"']*" ${CATALOG}
43     clean_catalog "${DOCBOOKDIR}/xml-dtd-[^/\"']*/[^/\"']*" ${ROOTCATALOG}
44    
45     if set_dtds; then
46     for d in ${DTDS}; do
47     populate_dtd ${d}
48     done
49     populate_entities
50     fi
51    
52     exit 0
53     }
54    
55 agriffis 1.2 #
56     # verbose echo -- only echo if called with --verbose
57     #
58     verb() {
59     $VERBOSE && echo "$*"
60     }
61    
62 agriffis 1.1 #
63     # fill in the DTDS variable based on installed versions
64     #
65     set_dtds() {
66     DTDS=$(find ${DOCBOOKDIR} -path '*/xml-dtd-*/docbookx.dtd')
67     if [[ -z ${DTDS} ]]; then
68     echo "No installed DocBook XML DTDs found"
69     return 1
70     else
71     return 0
72     fi
73     }
74    
75     #
76     # create the catalogs root and docbook specific
77     #
78     create_catalogs() {
79     if [[ ! -r ${ROOTCATALOG} ]] ; then
80     echo "Creating XML Catalog root ${ROOTCATALOG}"
81     /usr/bin/xmlcatalog --noout --create ${ROOTCATALOG}
82     if [[ ! -r ${ROOTCATALOG} ]] ; then
83     echo "Failed creating ${ROOTCATALOG}, aborting" >&2
84     exit 1
85     fi
86     else
87 agriffis 1.2 verb "Found XML Catalog root ${ROOTCATALOG}"
88 agriffis 1.1 # clean out existing entries
89 agriffis 1.2 verb " Cleaning existing ${CATALOG} delegates from ${ROOTCATALOG}"
90 agriffis 1.1 clean_catalog "file://${CATALOG}" ${ROOTCATALOG}
91     fi
92    
93     if [[ ! -r ${CATALOG} ]] ; then
94     echo "Creating DocBook XML Catalog ${CATALOG}"
95     /usr/bin/xmlcatalog --noout --create ${CATALOG}
96     if [[ ! -r ${CATALOG} ]] ; then
97     echo "Failed creating ${CATALOG}, aborting" >&2
98     exit 1
99     fi
100     else
101 agriffis 1.2 verb "Found DocBook XML Catalog ${CATALOG}"
102 agriffis 1.1 fi
103    
104     # dtd pointers
105 agriffis 1.2 verb " Populating ${ROOTCATALOG} with DTD delegates to ${CATALOG}"
106 agriffis 1.1 xmlcatalog --noout --add "delegatePublic" "-//OASIS//ENTITIES DocBook XML" "file://${CATALOG}" ${ROOTCATALOG}
107     xmlcatalog --noout --add "delegatePublic" "-//OASIS//DTD DocBook XML" "file://${CATALOG}" ${ROOTCATALOG}
108     xmlcatalog --noout --add "delegateSystem" "http://www.oasis-open.org/docbook/" "file://${CATALOG}" ${ROOTCATALOG}
109     xmlcatalog --noout --add "delegateURI" "http://www.oasis-open.org/docbook/" "file://${CATALOG}" ${ROOTCATALOG}
110     xmlcatalog --noout --add "delegateSystem" "http://docbook.sourceforge.net/release/xsl/" "file://${CATALOG}" ${ROOTCATALOG}
111     xmlcatalog --noout --add "delegateURI" "http://docbook.sourceforge.net/release/xsl/" "file://${CATALOG}" ${ROOTCATALOG}
112    
113     # entities pointer
114 agriffis 1.2 verb " Populating ${ROOTCATALOG} with ISO entities delegate to ${CATALOG}"
115 agriffis 1.1 xmlcatalog --noout --add "delegatePublic" "ISO 8879:1986" "file://${CATALOG}" ${ROOTCATALOG}
116     }
117    
118     #
119     # clean_catalog
120     # $1 == regex to clean
121     # $2 == catalog
122     #
123     clean_catalog() {
124     typeset list f regex=$1 catalog=$2
125    
126     list=$(egrep --only-matching "${regex}" "${catalog}" | sort -u)
127     for f in ${list}; do
128     xmlcatalog --noout --del "${f}" ${catalog}
129     done
130     }
131    
132     #
133     # populate a specific dtd version into the docbook catalog
134     # $1 == /path/to/docbookx.dtd
135     #
136     populate_dtd() {
137     typeset dtd=$1 docbookdir=${1%/*} dtd_date
138     typeset v=${docbookdir##*-}
139    
140     # sanity check
141     if [[ ${dtd} != */xml-dtd-*/* ]]; then
142     echo "Warning: I don't understand \"${dtd}\"" >&2
143     return
144     fi
145     echo "Found DocBook XML ${v} in ${docbookdir}"
146    
147     # Populate the docbook catalog with this version
148 agriffis 1.2 verb " Populating ${CATALOG} based on ${docbookdir}"
149 agriffis 1.1 xmlcatalog --noout --add "public" "-//OASIS//ELEMENTS DocBook XML Information Pool V${v}//EN" "file://${docbookdir}/dbpoolx.mod" ${CATALOG}
150     xmlcatalog --noout --add "public" "-//OASIS//DTD DocBook XML V${v}//EN" "file://${docbookdir}/docbookx.dtd" ${CATALOG}
151     xmlcatalog --noout --add "public" "-//OASIS//ENTITIES DocBook XML Character Entities V${v}//EN" "file://${docbookdir}/dbcentx.mod" ${CATALOG}
152     xmlcatalog --noout --add "public" "-//OASIS//ENTITIES DocBook XML Notations V${v}//EN" "file://${docbookdir}/dbnotnx.mod" ${CATALOG}
153     xmlcatalog --noout --add "public" "-//OASIS//ENTITIES DocBook XML Additional General Entities V${v}//EN" "file://${docbookdir}/dbgenent.mod" ${CATALOG}
154     xmlcatalog --noout --add "public" "-//OASIS//ELEMENTS DocBook XML Document Hierarchy V${v}//EN" "file://${docbookdir}/dbhierx.mod" ${CATALOG}
155     xmlcatalog --noout --add "public" "-//OASIS//DTD XML Exchange Table Model 19990315//EN" "file://${docbookdir}/soextblx.dtd" ${CATALOG}
156     xmlcatalog --noout --add "public" "-//OASIS//DTD DocBook XML CALS Table Model V${v}//EN" "file://${docbookdir}/calstblx.dtd" ${CATALOG}
157     xmlcatalog --noout --add "rewriteSystem" "http://www.oasis-open.org/docbook/xml/${v}" "file://${docbookdir}" ${CATALOG}
158     xmlcatalog --noout --add "rewriteURI" "http://www.oasis-open.org/docbook/xml/${v}" "file://${docbookdir}" ${CATALOG}
159    
160     # grab the RCS date from docbookx.dtd for comparison purposes
161     if [[ ! -f ${docbookdir}/ent/iso-lat1.ent ]]; then
162 agriffis 1.2 verb " No entities available for ${dtd}"
163 agriffis 1.1 return 0
164     fi
165     dtd_date=$(egrep --only-matching --max-count=1 \
166     '[0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}' "${dtd}")
167     if [[ -z ${dtd_date} ]]; then
168 agriffis 1.2 verb " Couldn't find RCS date in ${dtd}, ignoring entities"
169 agriffis 1.1 return 0
170     fi
171 agriffis 1.2 verb " RCS datestamp in ${dtd} is ${dtd_date}"
172 agriffis 1.1 dtd_date=$(date -d "$dtd_date" +%s)
173     if [[ -z $LATEST_DTD || $dtd_date -gt $LATEST_DATE ]]; then
174     LATEST_DATE=${dtd_date}
175     LATEST_DTD=${dtd}
176     fi
177     }
178    
179     #
180     # populate ISO DocBook entities from the most recent DTD
181     #
182     populate_entities() {
183     typeset isodir=${LATEST_DTD%/*}/ent i j
184     typeset -a entities avail
185    
186     # sanity check
187     if [[ -z ${LATEST_DTD} || ! -d ${isodir} ]]; then
188     echo "No ISO DocBook entities available for catalog"
189     return 0
190     fi
191     echo "Using ISO DocBook entities from ${isodir}"
192    
193     # here are the entities we know about;
194     # note these must remain sorted!
195     entities=(
196     "iso-amsa.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Arrow Relations//EN"
197     "iso-amsb.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Binary Operators//EN"
198     "iso-amsc.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Delimiters//EN"
199     "iso-amsn.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Negated Relations//EN"
200     "iso-amso.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Ordinary//EN"
201     "iso-amsr.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Relations//EN"
202     "iso-box.ent" "ISO 8879:1986//ENTITIES Box and Line Drawing//EN"
203     "iso-cyr1.ent" "ISO 8879:1986//ENTITIES Russian Cyrillic//EN"
204     "iso-cyr2.ent" "ISO 8879:1986//ENTITIES Non-Russian Cyrillic//EN"
205     "iso-dia.ent" "ISO 8879:1986//ENTITIES Diacritical Marks//EN"
206     "iso-grk1.ent" "ISO 8879:1986//ENTITIES Greek Letters//EN"
207     "iso-grk2.ent" "ISO 8879:1986//ENTITIES Monotoniko Greek//EN"
208     "iso-grk3.ent" "ISO 8879:1986//ENTITIES Greek Symbols//EN"
209     "iso-grk4.ent" "ISO 8879:1986//ENTITIES Alternative Greek Symbols//EN"
210     "iso-lat1.ent" "ISO 8879:1986//ENTITIES Added Latin 1//EN"
211     "iso-lat2.ent" "ISO 8879:1986//ENTITIES Added Latin 2//EN"
212     "iso-num.ent" "ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN"
213     "iso-pub.ent" "ISO 8879:1986//ENTITIES Publishing//EN"
214     "iso-tech.ent" "ISO 8879:1986//ENTITIES General Technical//EN"
215     )
216    
217     # here are the entities available; assume no spaces in filenames...
218     avail=($(ls ${isodir} | sort))
219    
220     # double-check the lists
221 agriffis 1.2 verb " Populating ${CATALOG} with ISO DocBook entities"
222 agriffis 1.1 i=0 ; j=0
223     while [[ ${i} -lt ${#entities[@]} || ${j} -lt ${#avail[@]} ]]; do
224     if [[ ${i} -ge ${#entities[@]} ]]; then
225     echo "Warning: Extra ISO entities file: ${avail[j]}"
226     let j=j+1
227     elif [[ ${j} -ge ${#avail[@]} ]]; then
228     echo "Warning: Entities file not found: ${entities[i]}"
229     let i=i+2
230     elif [[ ${avail[j]} < ${entities[i]} ]]; then
231     echo "Warning: Extra ISO entities file: ${avail[j]}"
232     let j=j+1
233     elif [[ ${entities[i]} < ${avail[j]} ]]; then
234     echo "Warning: Entities file not found: ${entities[i]}"
235     let i=i+2
236     elif [[ ${entities[i]} == ${avail[j]} ]]; then
237     xmlcatalog --noout --add "public" "${entities[i+1]}" \
238     "file://${isodir}/${entities[i]}" ${CATALOG}
239     let j=j+1
240     let i=i+2
241     else
242     echo "${0}: Whoah, shouldn't be here, aborting" >&2
243     exit 1
244     fi
245     done
246     }
247    
248     #
249     # populate XSL stylesheets
250     #
251     populate_xsl() {
252     typeset listed avail f
253    
254     # Delete current entries from the catalog
255     clean_catalog "${DOCBOOKDIR}/xsl-stylesheets-[0-9\.]+" $CATALOG
256     clean_catalog "${DOCBOOKDIR}/xsl-stylesheets-[0-9\.]+" $ROOTCATALOG
257    
258     # Find the available XSL stylesheets. In theory there should only
259     # be one match since these aren't slotted, but restrict to the
260     # first match anyway...
261     avail=$(find ${DOCBOOKDIR%/*} -name chunk.xsl | head -n 1)
262     if [[ -z ${avail} ]]; then
263     echo "Could not locate chunk.xsl of DocBook XSL stylesheets" >&2
264     return 1
265     fi
266     xsldir=${avail%/*/*}
267     if [[ ! -e ${xsldir}/html/docbook.xsl || ! -e ${xsldir}/common/l10n.xml ]]; then
268     echo "DocBook XSLT stylesheets are missing files from ${xsldir}" >&2
269     return 1
270     fi
271    
272     # Populate catalog with XSL entries
273     echo "Found DocBook XSL stylesheets in ${xsldir}"
274 agriffis 1.2 verb " Populating ${CATALOG} with XSL stylesheets"
275 agriffis 1.1 for version in current 1.39 1.40 1.41 1.42 1.43 1.44 1.45 1.46 1.47 \
276     1.48 1.49 1.50 ${xsldir##*-}
277     do
278     xmlcatalog --noout --add "rewriteSystem" "http://docbook.sourceforge.net/release/xsl/${version}" "file://${xsldir}" ${CATALOG}
279     xmlcatalog --noout --add "rewriteURI" "http://docbook.sourceforge.net/release/xsl/${version}" "file://${xsldir}" ${CATALOG}
280     done
281     }
282    
283     # Call the main routine
284 agriffis 1.2 main "$@"

  ViewVC Help
Powered by ViewVC 1.1.20