/[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.1 - (show annotations) (download)
Wed Jun 30 02:40:33 2004 UTC (10 years, 10 months ago) by agriffis
Branch: MAIN
see bug 52725

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

  ViewVC Help
Powered by ViewVC 1.1.20