/[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.18 - (hide annotations) (download)
Wed Mar 28 19:27:46 2012 UTC (2 years, 5 months ago) by vapier
Branch: MAIN
Changes since 1.17: +45 -28 lines
add $ROOT support #389243 by Zdenek Behan

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

  ViewVC Help
Powered by ViewVC 1.1.20