/[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.13 - (show annotations) (download)
Tue Mar 27 22:46:32 2012 UTC (2 years, 6 months ago) by vapier
Branch: MAIN
Changes since 1.12: +7 -2 lines
attempt to create /etc/xml if it does not exist so `rm -rf /etc/xml && build-docbook-catalog` works

1 #!/bin/bash
2 # $Header: /var/cvsroot/gentoo-src/build-docbook-catalog/build-docbook-catalog,v 1.11 2012/03/27 22:41:10 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 # create the catalogs root and docbook specific
114 #
115 create_catalogs() {
116 if [[ ! -d ${ROOTCONFDIR} ]] ; then
117 mkdir -p "${ROOTCONFDIR}" || error "could not create ${ROOTCONFDIR}"
118 fi
119
120 if [[ ! -r ${ROOTCATALOG} ]] ; then
121 echo "Creating XML Catalog root ${ROOTCATALOG}"
122 xmlcatalog --noout --create ${ROOTCATALOG}
123 if [[ ! -r ${ROOTCATALOG} ]] ; then
124 error "failed creating ${ROOTCATALOG}"
125 fi
126 else
127 verb "Found XML Catalog root ${ROOTCATALOG}"
128 # clean out existing entries
129 verb " Cleaning existing ${CATALOG} delegates from ${ROOTCATALOG}"
130 clean_catalog "file://${CATALOG}" ${ROOTCATALOG}
131 fi
132
133 if [[ ! -r ${CATALOG} ]] ; then
134 echo "Creating DocBook XML Catalog ${CATALOG}"
135 xmlcatalog --noout --create ${CATALOG}
136 if [[ ! -r ${CATALOG} ]] ; then
137 error "failed creating ${CATALOG}"
138 fi
139 else
140 verb "Found DocBook XML Catalog ${CATALOG}"
141 fi
142
143 # dtd pointers
144 verb " Populating ${ROOTCATALOG} with DTD delegates to ${CATALOG}"
145 xmlcatalog --noout --add "delegatePublic" "-//OASIS//ENTITIES DocBook" "file://${CATALOG}" ${ROOTCATALOG}
146 xmlcatalog --noout --add "delegatePublic" "-//OASIS//ELEMENTS DocBook" "file://${CATALOG}" ${ROOTCATALOG}
147 xmlcatalog --noout --add "delegatePublic" "-//OASIS//DTD DocBook" "file://${CATALOG}" ${ROOTCATALOG}
148 xmlcatalog --noout --add "delegateSystem" "http://www.oasis-open.org/docbook/" "file://${CATALOG}" ${ROOTCATALOG}
149 xmlcatalog --noout --add "delegateURI" "http://www.oasis-open.org/docbook/" "file://${CATALOG}" ${ROOTCATALOG}
150
151 # entities pointer
152 verb " Populating ${ROOTCATALOG} with ISO entities delegate to ${CATALOG}"
153 xmlcatalog --noout --add "delegatePublic" "ISO 8879:1986" "file://${CATALOG}" ${ROOTCATALOG}
154 }
155
156 #
157 # clean_catalog
158 # $1 == regex to clean
159 # $2 == catalog
160 #
161 clean_catalog() {
162 local list f regex=$1 catalog=$2
163
164 list=$(egrep --only-matching "${regex}" "${catalog}" | sort -u)
165 for f in ${list}; do
166 xmlcatalog --noout --del "${f}" ${catalog}
167 done
168 }
169
170 #
171 # populate a specific dtd version into the docbook catalog
172 # $1 == /path/to/docbookx.dtd
173 #
174 populate_dtd() {
175 local dtd=$1 docbookdir=${1%/*} dtd_date
176 local v=${docbookdir##*-}
177
178 # sanity check
179 if [[ ${dtd} != */xml-dtd-*/* ]]; then
180 echo "Warning: I don't understand \"${dtd}\"" >&2
181 return
182 fi
183 echo "Found DocBook XML ${v} in ${docbookdir}"
184
185 # Populate the docbook catalog with this version
186 verb " Populating ${CATALOG} based on ${docbookdir}"
187 xmlcatalog --noout --add "public" "-//OASIS//ELEMENTS DocBook XML Information Pool V${v}//EN" "file://${docbookdir}/dbpoolx.mod" ${CATALOG}
188 xmlcatalog --noout --add "public" "-//OASIS//DTD DocBook XML V${v}//EN" "file://${docbookdir}/docbookx.dtd" ${CATALOG}
189 xmlcatalog --noout --add "public" "-//OASIS//ENTITIES DocBook XML Character Entities V${v}//EN" "file://${docbookdir}/dbcentx.mod" ${CATALOG}
190 xmlcatalog --noout --add "public" "-//OASIS//ENTITIES DocBook XML Notations V${v}//EN" "file://${docbookdir}/dbnotnx.mod" ${CATALOG}
191 xmlcatalog --noout --add "public" "-//OASIS//ENTITIES DocBook XML Additional General Entities V${v}//EN" "file://${docbookdir}/dbgenent.mod" ${CATALOG}
192 xmlcatalog --noout --add "public" "-//OASIS//ELEMENTS DocBook XML Document Hierarchy V${v}//EN" "file://${docbookdir}/dbhierx.mod" ${CATALOG}
193 xmlcatalog --noout --add "public" "-//OASIS//DTD XML Exchange Table Model 19990315//EN" "file://${docbookdir}/soextblx.dtd" ${CATALOG}
194 xmlcatalog --noout --add "public" "-//OASIS//DTD DocBook XML CALS Table Model V${v}//EN" "file://${docbookdir}/calstblx.dtd" ${CATALOG}
195 xmlcatalog --noout --add "rewriteSystem" "http://www.oasis-open.org/docbook/xml/${v}" "file://${docbookdir}" ${CATALOG}
196 xmlcatalog --noout --add "rewriteURI" "http://www.oasis-open.org/docbook/xml/${v}" "file://${docbookdir}" ${CATALOG}
197
198 # grab the RCS date from docbookx.dtd for comparison purposes
199 if [[ ! -f ${docbookdir}/ent/iso-lat1.ent ]]; then
200 verb " No entities available for ${dtd}"
201 return 0
202 fi
203 dtd_date=$(egrep --only-matching --max-count=1 \
204 '[0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}' "${dtd}")
205 if [[ -z ${dtd_date} ]]; then
206 verb " Couldn't find RCS date in ${dtd}, ignoring entities"
207 return 0
208 fi
209 verb " RCS datestamp in ${dtd} is ${dtd_date}"
210 dtd_date=$(date -d "$dtd_date" +%s)
211 if [[ -z $LATEST_DTD || $dtd_date -gt $LATEST_DATE ]]; then
212 LATEST_DATE=${dtd_date}
213 LATEST_DTD=${dtd}
214 fi
215 }
216
217 #
218 # populate a specific simple dtd version into the docbook catalog
219 # $1 == /path/to/sdocbook.dtd
220 #
221 populate_simple_dtd() {
222 local dtd=$1 docbookdir=${1%/*}
223 local v=${docbookdir##*-}
224
225 # sanity check
226 if [[ ${dtd} != */xml-simple-dtd-*/* ]]; then
227 echo "Warning: I don't understand \"${dtd}\"" >&2
228 return
229 fi
230 echo "Found Simplified DocBook XML ${v} in ${docbookdir}"
231
232 # Populate the docbook catalog with this version
233 verb " Populating ${CATALOG} based on ${docbookdir}"
234 xmlcatalog --noout --add "public" "-//OASIS//DTD Simplified DocBook XML V${v}//EN" "file://${docbookdir}/sdocbook.dtd" ${CATALOG}
235 xmlcatalog --noout --add "rewriteSystem" "http://www.oasis-open.org/docbook/xml/simple/${v}" "file://${docbookdir}" ${CATALOG}
236 xmlcatalog --noout --add "rewriteURI" "http://www.oasis-open.org/docbook/xml/simple/${v}" "file://${docbookdir}" ${CATALOG}
237 }
238
239 #
240 # populate ISO DocBook entities from the most recent DTD
241 #
242 populate_entities() {
243 local isodir=${LATEST_DTD%/*}/ent i j
244 local entities=() avail=()
245
246 # sanity check
247 if [[ -z ${LATEST_DTD} || ! -d ${isodir} ]]; then
248 echo "No ISO DocBook entities available for catalog"
249 return 0
250 fi
251 echo "Using ISO DocBook entities from ${isodir}"
252
253 # here are the entities we know about;
254 # note these must remain sorted!
255 entities=(
256 "iso-amsa.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Arrow Relations//EN"
257 "iso-amsb.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Binary Operators//EN"
258 "iso-amsc.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Delimiters//EN"
259 "iso-amsn.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Negated Relations//EN"
260 "iso-amso.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Ordinary//EN"
261 "iso-amsr.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Relations//EN"
262 "iso-box.ent" "ISO 8879:1986//ENTITIES Box and Line Drawing//EN"
263 "iso-cyr1.ent" "ISO 8879:1986//ENTITIES Russian Cyrillic//EN"
264 "iso-cyr2.ent" "ISO 8879:1986//ENTITIES Non-Russian Cyrillic//EN"
265 "iso-dia.ent" "ISO 8879:1986//ENTITIES Diacritical Marks//EN"
266 "iso-grk1.ent" "ISO 8879:1986//ENTITIES Greek Letters//EN"
267 "iso-grk2.ent" "ISO 8879:1986//ENTITIES Monotoniko Greek//EN"
268 "iso-grk3.ent" "ISO 8879:1986//ENTITIES Greek Symbols//EN"
269 "iso-grk4.ent" "ISO 8879:1986//ENTITIES Alternative Greek Symbols//EN"
270 "iso-lat1.ent" "ISO 8879:1986//ENTITIES Added Latin 1//EN"
271 "iso-lat2.ent" "ISO 8879:1986//ENTITIES Added Latin 2//EN"
272 "iso-num.ent" "ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN"
273 "iso-pub.ent" "ISO 8879:1986//ENTITIES Publishing//EN"
274 "iso-tech.ent" "ISO 8879:1986//ENTITIES General Technical//EN"
275 )
276
277 # here are the entities available; assume no spaces in filenames...
278 avail=($(ls ${isodir} | sort))
279
280 # double-check the lists
281 verb " Populating ${CATALOG} with ISO DocBook entities"
282 i=0 ; j=0
283 while [[ ${i} -lt ${#entities[@]} || ${j} -lt ${#avail[@]} ]]; do
284 if [[ ${i} -ge ${#entities[@]} ]]; then
285 echo "Warning: Extra ISO entities file: ${avail[j]}"
286 let j=j+1
287 elif [[ ${j} -ge ${#avail[@]} ]]; then
288 echo "Warning: Entities file not found: ${entities[i]}"
289 let i=i+2
290 elif [[ ${avail[j]} < ${entities[i]} ]]; then
291 echo "Warning: Extra ISO entities file: ${avail[j]}"
292 let j=j+1
293 elif [[ ${entities[i]} < ${avail[j]} ]]; then
294 echo "Warning: Entities file not found: ${entities[i]}"
295 let i=i+2
296 elif [[ ${entities[i]} == ${avail[j]} ]]; then
297 xmlcatalog --noout --add "public" "${entities[i+1]}" \
298 "file://${isodir}/${entities[i]}" ${CATALOG}
299 let j=j+1
300 let i=i+2
301 else
302 error "${0}: whoah, shouldn't be here"
303 fi
304 done
305 }
306
307 #
308 # populate XSL stylesheets
309 #
310 populate_xsl() {
311 local f
312
313 # This is either xsl, xsl-ns, xsl-saxon or xsl-xalan
314 local type=$1
315
316 # Delete current entries from the catalog (delete legacy versioned entries too)
317 clean_catalog "${DOCBOOKDIR}/${type}-stylesheets(-[0-9\.]+)?" $CATALOG
318 clean_catalog "${DOCBOOKDIR}/${type}-stylesheets(-[0-9\.]+)?" $ROOTCATALOG
319
320 local xsldir=/usr/share/sgml/docbook/${type}-stylesheets
321
322 if [[ ! -d ${xsldir} ]]; then
323 echo "DocBook XSL stylesheets (${type}) not found" >&2
324 return 1
325 fi
326
327 if [[ ! -e ${xsldir}/html/docbook.xsl || ! -e ${xsldir}/common/l10n.xml ]]; then
328 echo "DocBook XSL stylesheets are missing files from ${xsldir}" >&2
329 return 1
330 fi
331
332 # Populate catalog with XSL entries
333 echo "Found DocBook XSL stylesheets (${type}) in ${xsldir}"
334
335 verb " Populating ${ROOTCATALOG} with XSL delegations"
336 xmlcatalog --noout --add "delegateSystem" "http://docbook.sourceforge.net/release/${type}/" "file://${CATALOG}" ${ROOTCATALOG}
337 xmlcatalog --noout --add "delegateURI" "http://docbook.sourceforge.net/release/${type}/" "file://${CATALOG}" ${ROOTCATALOG}
338
339 verb " Populating ${CATALOG} with XSL stylesheets"
340 xmlcatalog --noout --add "rewriteSystem" "http://docbook.sourceforge.net/release/${type}/current" "file://${xsldir}" ${CATALOG}
341 xmlcatalog --noout --add "rewriteURI" "http://docbook.sourceforge.net/release/${type}/current" "file://${xsldir}" ${CATALOG}
342 }
343
344 # Call the main routine
345 main "$@"

  ViewVC Help
Powered by ViewVC 1.1.20