/[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.10 - (show annotations) (download)
Tue Mar 27 22:39:03 2012 UTC (2 years, 5 months ago) by vapier
Branch: MAIN
Changes since 1.9: +11 -11 lines
use `local` rather than `typeset` to better match current Gentoo style

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

  ViewVC Help
Powered by ViewVC 1.1.20