/[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.5 - (show annotations) (download)
Sun Aug 23 16:06:03 2009 UTC (5 years, 3 months ago) by flameeyes
Branch: MAIN
Changes since 1.4: +4 -3 lines
Improve support for local resolver, patch by Jiri Tyr in bug #194485.

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

  ViewVC Help
Powered by ViewVC 1.1.20