/[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.3 - (hide annotations) (download)
Mon Sep 22 13:43:02 2008 UTC (6 years, 3 months ago) by flameeyes
Branch: MAIN
Changes since 1.2: +24 -18 lines
Extend build-docbook-catalog to support different types of xsl stylesheets (which include xsl-ns for Docbook 5).

Be ready to support xsl-xalan and xsl-saxon even if they are not
available in Portage too.

Also, assume that the directories are unversioned, as the new ebuilds
don't version them anymore.

The script could be deprecated, for what concerns XSL stylesheets, by
using an eclass instead.

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

  ViewVC Help
Powered by ViewVC 1.1.20