/[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.20 - (hide annotations) (download)
Sat Sep 28 02:30:06 2013 UTC (10 months, 3 weeks ago) by ottxor
Branch: MAIN
CVS Tags: HEAD
Changes since 1.19: +13 -6 lines
merge prefix patches

1 agriffis 1.1 #!/bin/bash
2 ottxor 1.20 # $Header: /var/cvsroot/gentoo-src/build-docbook-catalog/build-docbook-catalog,v 1.19 2012/03/28 19:34:46 vapier Exp $
3 agriffis 1.1 #
4     # build-docbook-catalog: populate /etc/xml/docbook based in
5     # installed docbook-xml-dtd versions.
6     #
7 vapier 1.8 # Copyright 2004-2012 Gentoo Foundation
8 agriffis 1.1 # Distributed under the terms of the GNU General Public License v2
9     # written by Aron Griffis
10     #
11    
12 ottxor 1.20 EPREFIX=
13     ROOTCONFDIR="${EPREFIX}"/etc/xml
14 vapier 1.13 ROOTCATALOG=${ROOTCONFDIR}/catalog
15     CATALOG=${ROOTCONFDIR}/docbook
16 ottxor 1.20 DOCBOOKDIR="${EPREFIX}"/usr/share/sgml/docbook
17 agriffis 1.1 DTDS=
18     LATEST_DTD=
19     LATEST_DATE=
20 agriffis 1.2 VERBOSE=false
21     ZERO=${0##*/}
22 ottxor 1.20 GETOPT=getopt
23 agriffis 1.1
24     #
25 vapier 1.9 # usage!
26     #
27     usage() {
28     cat <<-EOF
29     Usage: ${ZERO} [options]
30    
31     Options:
32 vapier 1.18 -r, --root ROOT path to work on
33 vapier 1.9 -v, --verbose Be verbose
34     -h, --help This!
35     EOF
36     [[ $# -gt 0 ]] && eerror "$*"
37     exit 0
38     }
39    
40     #
41 agriffis 1.1 # main (called from bottom)
42     #
43     main() {
44 vapier 1.10 local d v opts
45 agriffis 1.2
46 ottxor 1.20 opts=$(${GETOPT} -o hr:v --long help,root:,verbose -n "${ZERO}" -- "$@") || exit 1
47 vapier 1.16 eval set -- "${opts}"
48 agriffis 1.2 while true; do
49 vapier 1.16 case $1 in
50 vapier 1.9 -h|--help) usage ;;
51 vapier 1.18 -r|--root) ROOT=$2 ; shift ;;
52 vapier 1.9 -v|--verbose) VERBOSE=true ;;
53     --) break ;;
54     *) usage "options parsing failed on $1!" ;;
55 agriffis 1.2 esac
56 vapier 1.9 shift
57 agriffis 1.2 done
58 agriffis 1.1
59 vapier 1.18 : ${ROOT:=/}
60     [[ ${ROOT} != */ ]] && ROOT="${ROOT}/"
61     [[ ${ROOT} != /* ]] && ROOT="${PWD}${ROOT}"
62     if [[ ${ROOT} != "/" ]] ; then
63     echo "Working on root ${ROOT}"
64     fi
65    
66 vapier 1.19 if [[ ! -d ${ROOT}${ROOTCONFDIR} ]] ; then
67     mkdir -p "${ROOT}${ROOTCONFDIR}" || error "could not create ${ROOTCONFDIR}"
68     fi
69    
70 ottxor 1.20 local lock="${ROOT}${ROOTCONFDIR}"/build-docbook-catalog-lock
71 vapier 1.19 (
72     # Lock the dir to avoid trashing other runs that might
73     # be running parallel.
74 ottxor 1.20 touch "${lock}".$$ && \
75     until ln "${lock}".$$ "${lock}" 2>/dev/null; do sleep 1; done && \
76     rm "${lock}".$$
77     [[ -f ${lock}.$$ ]] && error "unable to lock ${ROOTCONFDIR}"
78 vapier 1.19
79 agriffis 1.1 create_catalogs # will exit on error
80 flameeyes 1.3 for type in xsl xsl-ns xsl-saxon xsl-xalan; do
81 vapier 1.16 populate_xsl ${type}
82 flameeyes 1.3 done
83 agriffis 1.1
84     # Clean out old dtds from catalog
85 agriffis 1.2 verb "Cleaning out old DocBook XML versions from ${CATALOG} and ${ROOTCATALOG}"
86 vapier 1.15 clean_catalog "${DOCBOOKDIR}/xml\(-simple\)*-dtd-[^/\"']*/[^/\"']*" "${CATALOG}"
87     clean_catalog "${DOCBOOKDIR}/xml\(-simple\)*-dtd-[^/\"']*/[^/\"']*" "${ROOTCATALOG}"
88 agriffis 1.1
89     if set_dtds; then
90     for d in ${DTDS}; do
91     populate_dtd ${d}
92     done
93 flameeyes 1.6 for d in ${SIMPLE_DTDS}; do
94     populate_simple_dtd ${d}
95     done
96 agriffis 1.1 populate_entities
97     fi
98    
99 ottxor 1.20 )
100     rm "${lock}"
101 vapier 1.19
102 agriffis 1.1 exit 0
103     }
104    
105 vapier 1.7 #
106 agriffis 1.2 # verbose echo -- only echo if called with --verbose
107     #
108     verb() {
109 vapier 1.16 ${VERBOSE} && echo "$*"
110 agriffis 1.2 }
111    
112 agriffis 1.1 #
113 vapier 1.8 # show an error and abort
114     #
115     error() {
116     printf '%s: %b, aborting\n' "${ZERO}" "$*" 1>&2
117     exit 1
118     }
119    
120     #
121 agriffis 1.1 # fill in the DTDS variable based on installed versions
122 vapier 1.7 #
123 agriffis 1.1 set_dtds() {
124 vapier 1.11 DTDS= SIMPLE_DTS=
125    
126 vapier 1.18 local d=${ROOT}${DOCBOOKDIR}
127     if [[ -d ${d} ]] ; then
128     pushd "${d}" >/dev/null || return 1
129     DTDS=$(find xml-dtd-*/ -name docbookx.dtd)
130     SIMPLE_DTDS=$(find xml-simple-dtd-*/ -name sdocbook.dtd)
131     popd >/dev/null
132 vapier 1.11 fi
133    
134 agriffis 1.1 if [[ -z ${DTDS} ]]; then
135     echo "No installed DocBook XML DTDs found"
136     return 1
137     else
138     return 0
139     fi
140     }
141    
142     #
143 vapier 1.14 # multi_xmlcatalog_add <file> <opts array>
144     #
145     # the opts array is a set of three: what gets passed to --add
146     #
147     multi_xmlcatalog_add() {
148 vapier 1.18 local file="${ROOT}$1"
149 vapier 1.14 shift
150    
151     while [[ $# -gt 0 ]] ; do
152     xmlcatalog --noout --add "$1" "$2" "file://$3" "${file}"
153     shift 3
154     done
155     }
156    
157     #
158 agriffis 1.1 # create the catalogs root and docbook specific
159     #
160     create_catalogs() {
161 vapier 1.14 local adds
162    
163 vapier 1.18 if [[ ! -r ${ROOT}${ROOTCATALOG} ]] ; then
164 agriffis 1.1 echo "Creating XML Catalog root ${ROOTCATALOG}"
165 vapier 1.18 xmlcatalog --noout --create "${ROOT}${ROOTCATALOG}"
166     if [[ ! -r ${ROOT}${ROOTCATALOG} ]] ; then
167 vapier 1.8 error "failed creating ${ROOTCATALOG}"
168 agriffis 1.1 fi
169     else
170 agriffis 1.2 verb "Found XML Catalog root ${ROOTCATALOG}"
171 agriffis 1.1 # clean out existing entries
172 agriffis 1.2 verb " Cleaning existing ${CATALOG} delegates from ${ROOTCATALOG}"
173 vapier 1.15 clean_catalog "file://${CATALOG}" "${ROOTCATALOG}"
174 agriffis 1.1 fi
175    
176 vapier 1.18 if [[ ! -r ${ROOT}${CATALOG} ]] ; then
177 agriffis 1.1 echo "Creating DocBook XML Catalog ${CATALOG}"
178 vapier 1.18 xmlcatalog --noout --create "${ROOT}${CATALOG}"
179     if [[ ! -r ${ROOT}${CATALOG} ]] ; then
180 vapier 1.8 error "failed creating ${CATALOG}"
181 agriffis 1.1 fi
182     else
183 agriffis 1.2 verb "Found DocBook XML Catalog ${CATALOG}"
184 agriffis 1.1 fi
185    
186     # dtd pointers
187 agriffis 1.2 verb " Populating ${ROOTCATALOG} with DTD delegates to ${CATALOG}"
188 vapier 1.14 adds=(
189     "delegatePublic" "-//OASIS//ENTITIES DocBook" "${CATALOG}"
190     "delegatePublic" "-//OASIS//ELEMENTS DocBook" "${CATALOG}"
191     "delegatePublic" "-//OASIS//DTD DocBook" "${CATALOG}"
192     "delegateSystem" "http://www.oasis-open.org/docbook/" "${CATALOG}"
193     "delegateURI" "http://www.oasis-open.org/docbook/" "${CATALOG}"
194     )
195     multi_xmlcatalog_add "${ROOTCATALOG}" "${adds[@]}"
196 agriffis 1.1
197     # entities pointer
198 agriffis 1.2 verb " Populating ${ROOTCATALOG} with ISO entities delegate to ${CATALOG}"
199 vapier 1.14 adds=(
200     "delegatePublic" "ISO 8879:1986" "${CATALOG}"
201     )
202     multi_xmlcatalog_add "${ROOTCATALOG}" "${adds[@]}"
203 agriffis 1.1 }
204    
205     #
206     # clean_catalog
207     # $1 == regex to clean
208     # $2 == catalog
209     #
210     clean_catalog() {
211 vapier 1.18 local list f regex=$1 catalog=${ROOT}$2
212 agriffis 1.1
213     list=$(egrep --only-matching "${regex}" "${catalog}" | sort -u)
214     for f in ${list}; do
215 vapier 1.15 xmlcatalog --noout --del "${f}" "${catalog}"
216 agriffis 1.1 done
217     }
218    
219 vapier 1.7 #
220 agriffis 1.1 # populate a specific dtd version into the docbook catalog
221 vapier 1.18 # $1 == ./subpath/to/docbookx.dtd
222 agriffis 1.1 #
223     populate_dtd() {
224 vapier 1.18 local dtd=${DOCBOOKDIR}/$1
225     local docbookdir=${dtd%/*}
226     local v=${docbookdir##*-}
227     local adds dtd_date
228 agriffis 1.1
229     # sanity check
230     if [[ ${dtd} != */xml-dtd-*/* ]]; then
231     echo "Warning: I don't understand \"${dtd}\"" >&2
232     return
233     fi
234     echo "Found DocBook XML ${v} in ${docbookdir}"
235    
236     # Populate the docbook catalog with this version
237 agriffis 1.2 verb " Populating ${CATALOG} based on ${docbookdir}"
238 vapier 1.14 adds=(
239     "public" "-//OASIS//ELEMENTS DocBook XML Information Pool V${v}//EN" "${docbookdir}/dbpoolx.mod"
240     "public" "-//OASIS//DTD DocBook XML V${v}//EN" "${docbookdir}/docbookx.dtd"
241     "public" "-//OASIS//ENTITIES DocBook XML Character Entities V${v}//EN" "${docbookdir}/dbcentx.mod"
242     "public" "-//OASIS//ENTITIES DocBook XML Notations V${v}//EN" "${docbookdir}/dbnotnx.mod"
243     "public" "-//OASIS//ENTITIES DocBook XML Additional General Entities V${v}//EN" "${docbookdir}/dbgenent.mod"
244     "public" "-//OASIS//ELEMENTS DocBook XML Document Hierarchy V${v}//EN" "${docbookdir}/dbhierx.mod"
245     "public" "-//OASIS//DTD XML Exchange Table Model 19990315//EN" "${docbookdir}/soextblx.dtd"
246     "public" "-//OASIS//DTD DocBook XML CALS Table Model V${v}//EN" "${docbookdir}/calstblx.dtd"
247     "rewriteSystem" "http://www.oasis-open.org/docbook/xml/${v}" "${docbookdir}"
248     "rewriteURI" "http://www.oasis-open.org/docbook/xml/${v}" "${docbookdir}"
249     )
250     multi_xmlcatalog_add "${CATALOG}" "${adds[@]}"
251 agriffis 1.1
252     # grab the RCS date from docbookx.dtd for comparison purposes
253 vapier 1.18 if [[ ! -f ${ROOT}${docbookdir}/ent/iso-lat1.ent ]]; then
254 agriffis 1.2 verb " No entities available for ${dtd}"
255 agriffis 1.1 return 0
256     fi
257     dtd_date=$(egrep --only-matching --max-count=1 \
258 vapier 1.18 '[0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}' \
259     "${ROOT}${dtd}")
260 agriffis 1.1 if [[ -z ${dtd_date} ]]; then
261 agriffis 1.2 verb " Couldn't find RCS date in ${dtd}, ignoring entities"
262 agriffis 1.1 return 0
263     fi
264 agriffis 1.2 verb " RCS datestamp in ${dtd} is ${dtd_date}"
265 vapier 1.16 dtd_date=$(date -d "${dtd_date}" +%s)
266     if [[ ${dtd_date} -gt ${LATEST_DATE:-0} ]] ; then
267 agriffis 1.1 LATEST_DATE=${dtd_date}
268     LATEST_DTD=${dtd}
269     fi
270     }
271    
272 vapier 1.7 #
273 flameeyes 1.6 # populate a specific simple dtd version into the docbook catalog
274 vapier 1.18 # $1 == ./subpath/to/sdocbook.dtd
275 flameeyes 1.6 #
276     populate_simple_dtd() {
277 vapier 1.18 local dtd=${DOCBOOKDIR}/$1
278     local docbookdir=${dtd%/*}
279     local v=${docbookdir##*-}
280     local adds dtd_date
281 flameeyes 1.6
282     # sanity check
283     if [[ ${dtd} != */xml-simple-dtd-*/* ]]; then
284     echo "Warning: I don't understand \"${dtd}\"" >&2
285     return
286     fi
287     echo "Found Simplified DocBook XML ${v} in ${docbookdir}"
288    
289     # Populate the docbook catalog with this version
290     verb " Populating ${CATALOG} based on ${docbookdir}"
291 vapier 1.14 adds=(
292     "public" "-//OASIS//DTD Simplified DocBook XML V${v}//EN" "${docbookdir}/sdocbook.dtd"
293     "rewriteSystem" "http://www.oasis-open.org/docbook/xml/simple/${v}" "${docbookdir}"
294     "rewriteURI" "http://www.oasis-open.org/docbook/xml/simple/${v}" "${docbookdir}"
295     )
296     multi_xmlcatalog_add "${CATALOG}" "${adds[@]}"
297 flameeyes 1.6 }
298    
299 agriffis 1.1 #
300     # populate ISO DocBook entities from the most recent DTD
301     #
302     populate_entities() {
303 vapier 1.10 local isodir=${LATEST_DTD%/*}/ent i j
304     local entities=() avail=()
305 agriffis 1.1
306     # sanity check
307 vapier 1.18 if [[ -z ${LATEST_DTD} || ! -d ${ROOT}${isodir} ]]; then
308 agriffis 1.1 echo "No ISO DocBook entities available for catalog"
309     return 0
310     fi
311     echo "Using ISO DocBook entities from ${isodir}"
312    
313     # here are the entities we know about;
314     # note these must remain sorted!
315     entities=(
316     "iso-amsa.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Arrow Relations//EN"
317     "iso-amsb.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Binary Operators//EN"
318     "iso-amsc.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Delimiters//EN"
319     "iso-amsn.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Negated Relations//EN"
320     "iso-amso.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Ordinary//EN"
321     "iso-amsr.ent" "ISO 8879:1986//ENTITIES Added Math Symbols: Relations//EN"
322     "iso-box.ent" "ISO 8879:1986//ENTITIES Box and Line Drawing//EN"
323     "iso-cyr1.ent" "ISO 8879:1986//ENTITIES Russian Cyrillic//EN"
324     "iso-cyr2.ent" "ISO 8879:1986//ENTITIES Non-Russian Cyrillic//EN"
325     "iso-dia.ent" "ISO 8879:1986//ENTITIES Diacritical Marks//EN"
326     "iso-grk1.ent" "ISO 8879:1986//ENTITIES Greek Letters//EN"
327     "iso-grk2.ent" "ISO 8879:1986//ENTITIES Monotoniko Greek//EN"
328     "iso-grk3.ent" "ISO 8879:1986//ENTITIES Greek Symbols//EN"
329     "iso-grk4.ent" "ISO 8879:1986//ENTITIES Alternative Greek Symbols//EN"
330     "iso-lat1.ent" "ISO 8879:1986//ENTITIES Added Latin 1//EN"
331     "iso-lat2.ent" "ISO 8879:1986//ENTITIES Added Latin 2//EN"
332     "iso-num.ent" "ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN"
333     "iso-pub.ent" "ISO 8879:1986//ENTITIES Publishing//EN"
334     "iso-tech.ent" "ISO 8879:1986//ENTITIES General Technical//EN"
335     )
336    
337     # here are the entities available; assume no spaces in filenames...
338 vapier 1.18 avail=($(ls "${ROOT}${isodir}" | sort))
339 agriffis 1.1
340     # double-check the lists
341 agriffis 1.2 verb " Populating ${CATALOG} with ISO DocBook entities"
342 agriffis 1.1 i=0 ; j=0
343     while [[ ${i} -lt ${#entities[@]} || ${j} -lt ${#avail[@]} ]]; do
344     if [[ ${i} -ge ${#entities[@]} ]]; then
345     echo "Warning: Extra ISO entities file: ${avail[j]}"
346     let j=j+1
347     elif [[ ${j} -ge ${#avail[@]} ]]; then
348     echo "Warning: Entities file not found: ${entities[i]}"
349     let i=i+2
350     elif [[ ${avail[j]} < ${entities[i]} ]]; then
351     echo "Warning: Extra ISO entities file: ${avail[j]}"
352     let j=j+1
353     elif [[ ${entities[i]} < ${avail[j]} ]]; then
354     echo "Warning: Entities file not found: ${entities[i]}"
355     let i=i+2
356     elif [[ ${entities[i]} == ${avail[j]} ]]; then
357     xmlcatalog --noout --add "public" "${entities[i+1]}" \
358 vapier 1.18 "file://${isodir}/${entities[i]}" "${ROOT}${CATALOG}"
359 agriffis 1.1 let j=j+1
360     let i=i+2
361     else
362 vapier 1.8 error "${0}: whoah, shouldn't be here"
363 agriffis 1.1 fi
364     done
365     }
366    
367     #
368     # populate XSL stylesheets
369     #
370     populate_xsl() {
371 vapier 1.14 local f adds
372 agriffis 1.1
373 flameeyes 1.3 # This is either xsl, xsl-ns, xsl-saxon or xsl-xalan
374     local type=$1
375    
376     # Delete current entries from the catalog (delete legacy versioned entries too)
377 vapier 1.15 clean_catalog "${DOCBOOKDIR}/${type}-stylesheets(-[0-9\.]+)?" "${CATALOG}"
378     clean_catalog "${DOCBOOKDIR}/${type}-stylesheets(-[0-9\.]+)?" "${ROOTCATALOG}"
379 flameeyes 1.3
380 vapier 1.17 local xsldir=${DOCBOOKDIR}/${type}-stylesheets
381 flameeyes 1.3
382 vapier 1.18 if [[ ! -d ${ROOT}${xsldir} ]] ; then
383 flameeyes 1.3 echo "DocBook XSL stylesheets (${type}) not found" >&2
384 agriffis 1.1 return 1
385     fi
386 flameeyes 1.3
387 vapier 1.18 if [[ ! -e ${ROOT}${xsldir}/html/docbook.xsl || ! -e ${ROOT}${xsldir}/common/l10n.xml ]] ; then
388 flameeyes 1.3 echo "DocBook XSL stylesheets are missing files from ${xsldir}" >&2
389 agriffis 1.1 return 1
390     fi
391    
392     # Populate catalog with XSL entries
393 flameeyes 1.3 echo "Found DocBook XSL stylesheets (${type}) in ${xsldir}"
394 flameeyes 1.4
395     verb " Populating ${ROOTCATALOG} with XSL delegations"
396 vapier 1.14 adds=(
397     "delegateSystem" "http://docbook.sourceforge.net/release/${type}/" "${CATALOG}"
398     "delegateURI" "http://docbook.sourceforge.net/release/${type}/" "${CATALOG}"
399     )
400     multi_xmlcatalog_add "${ROOTCATALOG}" "${adds[@]}"
401 flameeyes 1.4
402 agriffis 1.2 verb " Populating ${CATALOG} with XSL stylesheets"
403 vapier 1.14 adds=(
404     "rewriteSystem" "http://docbook.sourceforge.net/release/${type}/current" "${xsldir}"
405     "rewriteURI" "http://docbook.sourceforge.net/release/${type}/current" "${xsldir}"
406     )
407     multi_xmlcatalog_add "${CATALOG}" "${adds[@]}"
408 agriffis 1.1 }
409    
410     # Call the main routine
411 agriffis 1.2 main "$@"

  ViewVC Help
Powered by ViewVC 1.1.20