/[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.11 - (hide annotations) (download)
Tue Mar 27 22:41:10 2012 UTC (2 years, 6 months ago) by vapier
Branch: MAIN
Changes since 1.10: +7 -2 lines
check to see if DOCBOOKDIR exists before running `find` to avoid ugly errors with missing dirs

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

  ViewVC Help
Powered by ViewVC 1.1.20