/[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.8 - (hide annotations) (download)
Tue Mar 27 21:23:00 2012 UTC (2 years, 8 months ago) by vapier
Branch: MAIN
Changes since 1.7: +14 -9 lines
add an error() helper

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

  ViewVC Help
Powered by ViewVC 1.1.20