/[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.21 - (hide annotations) (download)
Mon May 23 15:53:13 2016 UTC (14 months ago) by haubi
Branch: MAIN
CVS Tags: HEAD
Changes since 1.20: +2 -1 lines
Prepend ROOT with "/." when "//" redirects to network (as in Cygwin).

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

  ViewVC Help
Powered by ViewVC 1.1.20