/[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.16 - (show annotations) (download)
Wed Mar 28 18:46:29 2012 UTC (2 years, 7 months ago) by vapier
Branch: MAIN
Changes since 1.15: +8 -8 lines
be consistent in variable style: ${foo} rather than $foo

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

  ViewVC Help
Powered by ViewVC 1.1.20