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

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 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 -r, --root ROOT path to work on
31 -v, --verbose Be verbose
32 -h, --help This!
33 EOF
34 [[ $# -gt 0 ]] && eerror "$*"
35 exit 0
36 }
37
38 #
39 # main (called from bottom)
40 #
41 main() {
42 local d v opts
43
44 opts=$(getopt -o hr:v --long help,root:,verbose -n "${ZERO}" -- "$@") || exit 1
45 eval set -- "${opts}"
46 while true; do
47 case $1 in
48 -h|--help) usage ;;
49 -r|--root) ROOT=$2 ; shift ;;
50 -v|--verbose) VERBOSE=true ;;
51 --) break ;;
52 *) usage "options parsing failed on $1!" ;;
53 esac
54 shift
55 done
56
57 : ${ROOT:=/}
58 [[ ${ROOT} != */ ]] && ROOT="${ROOT}/"
59 [[ ${ROOT} != /* ]] && ROOT="${PWD}${ROOT}"
60 if [[ ${ROOT} != "/" ]] ; then
61 echo "Working on root ${ROOT}"
62 fi
63
64 create_catalogs # will exit on error
65 for type in xsl xsl-ns xsl-saxon xsl-xalan; do
66 populate_xsl ${type}
67 done
68
69 # Clean out old dtds from catalog
70 verb "Cleaning out old DocBook XML versions from ${CATALOG} and ${ROOTCATALOG}"
71 clean_catalog "${DOCBOOKDIR}/xml\(-simple\)*-dtd-[^/\"']*/[^/\"']*" "${CATALOG}"
72 clean_catalog "${DOCBOOKDIR}/xml\(-simple\)*-dtd-[^/\"']*/[^/\"']*" "${ROOTCATALOG}"
73
74 if set_dtds; then
75 for d in ${DTDS}; do
76 populate_dtd ${d}
77 done
78 for d in ${SIMPLE_DTDS}; do
79 populate_simple_dtd ${d}
80 done
81 populate_entities
82 fi
83
84 exit 0
85 }
86
87 #
88 # verbose echo -- only echo if called with --verbose
89 #
90 verb() {
91 ${VERBOSE} && echo "$*"
92 }
93
94 #
95 # show an error and abort
96 #
97 error() {
98 printf '%s: %b, aborting\n' "${ZERO}" "$*" 1>&2
99 exit 1
100 }
101
102 #
103 # fill in the DTDS variable based on installed versions
104 #
105 set_dtds() {
106 DTDS= SIMPLE_DTS=
107
108 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 fi
115
116 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 # 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 local file="${ROOT}$1"
131 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 # create the catalogs root and docbook specific
141 #
142 create_catalogs() {
143 local adds
144
145 if [[ ! -d ${ROOT}${ROOTCONFDIR} ]] ; then
146 mkdir -p "${ROOT}${ROOTCONFDIR}" || error "could not create ${ROOTCONFDIR}"
147 fi
148
149 if [[ ! -r ${ROOT}${ROOTCATALOG} ]] ; then
150 echo "Creating XML Catalog root ${ROOTCATALOG}"
151 xmlcatalog --noout --create "${ROOT}${ROOTCATALOG}"
152 if [[ ! -r ${ROOT}${ROOTCATALOG} ]] ; then
153 error "failed creating ${ROOTCATALOG}"
154 fi
155 else
156 verb "Found XML Catalog root ${ROOTCATALOG}"
157 # clean out existing entries
158 verb " Cleaning existing ${CATALOG} delegates from ${ROOTCATALOG}"
159 clean_catalog "file://${CATALOG}" "${ROOTCATALOG}"
160 fi
161
162 if [[ ! -r ${ROOT}${CATALOG} ]] ; then
163 echo "Creating DocBook XML Catalog ${CATALOG}"
164 xmlcatalog --noout --create "${ROOT}${CATALOG}"
165 if [[ ! -r ${ROOT}${CATALOG} ]] ; then
166 error "failed creating ${CATALOG}"
167 fi
168 else
169 verb "Found DocBook XML Catalog ${CATALOG}"
170 fi
171
172 # dtd pointers
173 verb " Populating ${ROOTCATALOG} with DTD delegates to ${CATALOG}"
174 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
183 # entities pointer
184 verb " Populating ${ROOTCATALOG} with ISO entities delegate to ${CATALOG}"
185 adds=(
186 "delegatePublic" "ISO 8879:1986" "${CATALOG}"
187 )
188 multi_xmlcatalog_add "${ROOTCATALOG}" "${adds[@]}"
189 }
190
191 #
192 # clean_catalog
193 # $1 == regex to clean
194 # $2 == catalog
195 #
196 clean_catalog() {
197 local list f regex=$1 catalog=${ROOT}$2
198
199 list=$(egrep --only-matching "${regex}" "${catalog}" | sort -u)
200 for f in ${list}; do
201 xmlcatalog --noout --del "${f}" "${catalog}"
202 done
203 }
204
205 #
206 # populate a specific dtd version into the docbook catalog
207 # $1 == ./subpath/to/docbookx.dtd
208 #
209 populate_dtd() {
210 local dtd=${DOCBOOKDIR}/$1
211 local docbookdir=${dtd%/*}
212 local v=${docbookdir##*-}
213 local adds dtd_date
214
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 verb " Populating ${CATALOG} based on ${docbookdir}"
224 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
238 # grab the RCS date from docbookx.dtd for comparison purposes
239 if [[ ! -f ${ROOT}${docbookdir}/ent/iso-lat1.ent ]]; then
240 verb " No entities available for ${dtd}"
241 return 0
242 fi
243 dtd_date=$(egrep --only-matching --max-count=1 \
244 '[0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}' \
245 "${ROOT}${dtd}")
246 if [[ -z ${dtd_date} ]]; then
247 verb " Couldn't find RCS date in ${dtd}, ignoring entities"
248 return 0
249 fi
250 verb " RCS datestamp in ${dtd} is ${dtd_date}"
251 dtd_date=$(date -d "${dtd_date}" +%s)
252 if [[ ${dtd_date} -gt ${LATEST_DATE:-0} ]] ; then
253 LATEST_DATE=${dtd_date}
254 LATEST_DTD=${dtd}
255 fi
256 }
257
258 #
259 # populate a specific simple dtd version into the docbook catalog
260 # $1 == ./subpath/to/sdocbook.dtd
261 #
262 populate_simple_dtd() {
263 local dtd=${DOCBOOKDIR}/$1
264 local docbookdir=${dtd%/*}
265 local v=${docbookdir##*-}
266 local adds dtd_date
267
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 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 }
284
285 #
286 # populate ISO DocBook entities from the most recent DTD
287 #
288 populate_entities() {
289 local isodir=${LATEST_DTD%/*}/ent i j
290 local entities=() avail=()
291
292 # sanity check
293 if [[ -z ${LATEST_DTD} || ! -d ${ROOT}${isodir} ]]; then
294 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 avail=($(ls "${ROOT}${isodir}" | sort))
325
326 # double-check the lists
327 verb " Populating ${CATALOG} with ISO DocBook entities"
328 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 "file://${isodir}/${entities[i]}" "${ROOT}${CATALOG}"
345 let j=j+1
346 let i=i+2
347 else
348 error "${0}: whoah, shouldn't be here"
349 fi
350 done
351 }
352
353 #
354 # populate XSL stylesheets
355 #
356 populate_xsl() {
357 local f adds
358
359 # 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 clean_catalog "${DOCBOOKDIR}/${type}-stylesheets(-[0-9\.]+)?" "${CATALOG}"
364 clean_catalog "${DOCBOOKDIR}/${type}-stylesheets(-[0-9\.]+)?" "${ROOTCATALOG}"
365
366 local xsldir=${DOCBOOKDIR}/${type}-stylesheets
367
368 if [[ ! -d ${ROOT}${xsldir} ]] ; then
369 echo "DocBook XSL stylesheets (${type}) not found" >&2
370 return 1
371 fi
372
373 if [[ ! -e ${ROOT}${xsldir}/html/docbook.xsl || ! -e ${ROOT}${xsldir}/common/l10n.xml ]] ; then
374 echo "DocBook XSL stylesheets are missing files from ${xsldir}" >&2
375 return 1
376 fi
377
378 # Populate catalog with XSL entries
379 echo "Found DocBook XSL stylesheets (${type}) in ${xsldir}"
380
381 verb " Populating ${ROOTCATALOG} with XSL delegations"
382 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
388 verb " Populating ${CATALOG} with XSL stylesheets"
389 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 }
395
396 # Call the main routine
397 main "$@"

  ViewVC Help
Powered by ViewVC 1.1.20