/[gentoo-src]/build-docbook-catalog/build-docbook-catalog
Gentoo

Diff of /build-docbook-catalog/build-docbook-catalog

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.17 Revision 1.18
1#!/bin/bash 1#!/bin/bash
2# $Header: /var/cvsroot/gentoo-src/build-docbook-catalog/build-docbook-catalog,v 1.17 2012/03/28 19:02:47 vapier Exp $ 2# $Header: /var/cvsroot/gentoo-src/build-docbook-catalog/build-docbook-catalog,v 1.18 2012/03/28 19:27:46 vapier Exp $
3# 3#
4# build-docbook-catalog: populate /etc/xml/docbook based in 4# build-docbook-catalog: populate /etc/xml/docbook based in
5# installed docbook-xml-dtd versions. 5# installed docbook-xml-dtd versions.
6# 6#
7# Copyright 2004-2012 Gentoo Foundation 7# Copyright 2004-2012 Gentoo Foundation
25usage() { 25usage() {
26 cat <<-EOF 26 cat <<-EOF
27 Usage: ${ZERO} [options] 27 Usage: ${ZERO} [options]
28 28
29 Options: 29 Options:
30 -r, --root ROOT path to work on
30 -v, --verbose Be verbose 31 -v, --verbose Be verbose
31 -h, --help This! 32 -h, --help This!
32 EOF 33 EOF
33 [[ $# -gt 0 ]] && eerror "$*" 34 [[ $# -gt 0 ]] && eerror "$*"
34 exit 0 35 exit 0
38# main (called from bottom) 39# main (called from bottom)
39# 40#
40main() { 41main() {
41 local d v opts 42 local d v opts
42 43
43 opts=$(getopt -o hv --long help,verbose -n "${ZERO}" -- "$@") || exit 1 44 opts=$(getopt -o hr:v --long help,root:,verbose -n "${ZERO}" -- "$@") || exit 1
44 eval set -- "${opts}" 45 eval set -- "${opts}"
45 while true; do 46 while true; do
46 case $1 in 47 case $1 in
47 -h|--help) usage ;; 48 -h|--help) usage ;;
49 -r|--root) ROOT=$2 ; shift ;;
48 -v|--verbose) VERBOSE=true ;; 50 -v|--verbose) VERBOSE=true ;;
49 --) break ;; 51 --) break ;;
50 *) usage "options parsing failed on $1!" ;; 52 *) usage "options parsing failed on $1!" ;;
51 esac 53 esac
52 shift 54 shift
53 done 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
54 63
55 create_catalogs # will exit on error 64 create_catalogs # will exit on error
56 for type in xsl xsl-ns xsl-saxon xsl-xalan; do 65 for type in xsl xsl-ns xsl-saxon xsl-xalan; do
57 populate_xsl ${type} 66 populate_xsl ${type}
58 done 67 done
94# fill in the DTDS variable based on installed versions 103# fill in the DTDS variable based on installed versions
95# 104#
96set_dtds() { 105set_dtds() {
97 DTDS= SIMPLE_DTS= 106 DTDS= SIMPLE_DTS=
98 107
108 local d=${ROOT}${DOCBOOKDIR}
99 if [[ -d ${DOCBOOKDIR} ]] ; then 109 if [[ -d ${d} ]] ; then
100 DTDS=$(find "${DOCBOOKDIR}" -path '*/xml-dtd-*/docbookx.dtd') 110 pushd "${d}" >/dev/null || return 1
111 DTDS=$(find xml-dtd-*/ -name docbookx.dtd)
101 SIMPLE_DTDS=$(find "${DOCBOOKDIR}" -path '*/xml-simple-dtd-*/sdocbook.dtd') 112 SIMPLE_DTDS=$(find xml-simple-dtd-*/ -name sdocbook.dtd)
113 popd >/dev/null
102 fi 114 fi
103 115
104 if [[ -z ${DTDS} ]]; then 116 if [[ -z ${DTDS} ]]; then
105 echo "No installed DocBook XML DTDs found" 117 echo "No installed DocBook XML DTDs found"
106 return 1 118 return 1
113# multi_xmlcatalog_add <file> <opts array> 125# multi_xmlcatalog_add <file> <opts array>
114# 126#
115# the opts array is a set of three: what gets passed to --add 127# the opts array is a set of three: what gets passed to --add
116# 128#
117multi_xmlcatalog_add() { 129multi_xmlcatalog_add() {
118 local file=$1 130 local file="${ROOT}$1"
119 shift 131 shift
120 132
121 while [[ $# -gt 0 ]] ; do 133 while [[ $# -gt 0 ]] ; do
122 xmlcatalog --noout --add "$1" "$2" "file://$3" "${file}" 134 xmlcatalog --noout --add "$1" "$2" "file://$3" "${file}"
123 shift 3 135 shift 3
128# create the catalogs root and docbook specific 140# create the catalogs root and docbook specific
129# 141#
130create_catalogs() { 142create_catalogs() {
131 local adds 143 local adds
132 144
133 if [[ ! -d ${ROOTCONFDIR} ]] ; then 145 if [[ ! -d ${ROOT}${ROOTCONFDIR} ]] ; then
134 mkdir -p "${ROOTCONFDIR}" || error "could not create ${ROOTCONFDIR}" 146 mkdir -p "${ROOT}${ROOTCONFDIR}" || error "could not create ${ROOTCONFDIR}"
135 fi 147 fi
136 148
137 if [[ ! -r ${ROOTCATALOG} ]] ; then 149 if [[ ! -r ${ROOT}${ROOTCATALOG} ]] ; then
138 echo "Creating XML Catalog root ${ROOTCATALOG}" 150 echo "Creating XML Catalog root ${ROOTCATALOG}"
139 xmlcatalog --noout --create "${ROOTCATALOG}" 151 xmlcatalog --noout --create "${ROOT}${ROOTCATALOG}"
140 if [[ ! -r ${ROOTCATALOG} ]] ; then 152 if [[ ! -r ${ROOT}${ROOTCATALOG} ]] ; then
141 error "failed creating ${ROOTCATALOG}" 153 error "failed creating ${ROOTCATALOG}"
142 fi 154 fi
143 else 155 else
144 verb "Found XML Catalog root ${ROOTCATALOG}" 156 verb "Found XML Catalog root ${ROOTCATALOG}"
145 # clean out existing entries 157 # clean out existing entries
146 verb " Cleaning existing ${CATALOG} delegates from ${ROOTCATALOG}" 158 verb " Cleaning existing ${CATALOG} delegates from ${ROOTCATALOG}"
147 clean_catalog "file://${CATALOG}" "${ROOTCATALOG}" 159 clean_catalog "file://${CATALOG}" "${ROOTCATALOG}"
148 fi 160 fi
149 161
150 if [[ ! -r ${CATALOG} ]] ; then 162 if [[ ! -r ${ROOT}${CATALOG} ]] ; then
151 echo "Creating DocBook XML Catalog ${CATALOG}" 163 echo "Creating DocBook XML Catalog ${CATALOG}"
152 xmlcatalog --noout --create "${CATALOG}" 164 xmlcatalog --noout --create "${ROOT}${CATALOG}"
153 if [[ ! -r ${CATALOG} ]] ; then 165 if [[ ! -r ${ROOT}${CATALOG} ]] ; then
154 error "failed creating ${CATALOG}" 166 error "failed creating ${CATALOG}"
155 fi 167 fi
156 else 168 else
157 verb "Found DocBook XML Catalog ${CATALOG}" 169 verb "Found DocBook XML Catalog ${CATALOG}"
158 fi 170 fi
180# clean_catalog 192# clean_catalog
181# $1 == regex to clean 193# $1 == regex to clean
182# $2 == catalog 194# $2 == catalog
183# 195#
184clean_catalog() { 196clean_catalog() {
185 local list f regex=$1 catalog=$2 197 local list f regex=$1 catalog=${ROOT}$2
186 198
187 list=$(egrep --only-matching "${regex}" "${catalog}" | sort -u) 199 list=$(egrep --only-matching "${regex}" "${catalog}" | sort -u)
188 for f in ${list}; do 200 for f in ${list}; do
189 xmlcatalog --noout --del "${f}" "${catalog}" 201 xmlcatalog --noout --del "${f}" "${catalog}"
190 done 202 done
191} 203}
192 204
193# 205#
194# populate a specific dtd version into the docbook catalog 206# populate a specific dtd version into the docbook catalog
195# $1 == /path/to/docbookx.dtd 207# $1 == ./subpath/to/docbookx.dtd
196# 208#
197populate_dtd() { 209populate_dtd() {
198 local dtd=$1 docbookdir=${1%/*} dtd_date 210 local dtd=${DOCBOOKDIR}/$1
211 local docbookdir=${dtd%/*}
199 local v=${docbookdir##*-} adds 212 local v=${docbookdir##*-}
213 local adds dtd_date
200 214
201 # sanity check 215 # sanity check
202 if [[ ${dtd} != */xml-dtd-*/* ]]; then 216 if [[ ${dtd} != */xml-dtd-*/* ]]; then
203 echo "Warning: I don't understand \"${dtd}\"" >&2 217 echo "Warning: I don't understand \"${dtd}\"" >&2
204 return 218 return
220 "rewriteURI" "http://www.oasis-open.org/docbook/xml/${v}" "${docbookdir}" 234 "rewriteURI" "http://www.oasis-open.org/docbook/xml/${v}" "${docbookdir}"
221 ) 235 )
222 multi_xmlcatalog_add "${CATALOG}" "${adds[@]}" 236 multi_xmlcatalog_add "${CATALOG}" "${adds[@]}"
223 237
224 # grab the RCS date from docbookx.dtd for comparison purposes 238 # grab the RCS date from docbookx.dtd for comparison purposes
225 if [[ ! -f ${docbookdir}/ent/iso-lat1.ent ]]; then 239 if [[ ! -f ${ROOT}${docbookdir}/ent/iso-lat1.ent ]]; then
226 verb " No entities available for ${dtd}" 240 verb " No entities available for ${dtd}"
227 return 0 241 return 0
228 fi 242 fi
229 dtd_date=$(egrep --only-matching --max-count=1 \ 243 dtd_date=$(egrep --only-matching --max-count=1 \
230 '[0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}' "${dtd}") 244 '[0-9]{4}/[0-9]{2}/[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}' \
245 "${ROOT}${dtd}")
231 if [[ -z ${dtd_date} ]]; then 246 if [[ -z ${dtd_date} ]]; then
232 verb " Couldn't find RCS date in ${dtd}, ignoring entities" 247 verb " Couldn't find RCS date in ${dtd}, ignoring entities"
233 return 0 248 return 0
234 fi 249 fi
235 verb " RCS datestamp in ${dtd} is ${dtd_date}" 250 verb " RCS datestamp in ${dtd} is ${dtd_date}"
240 fi 255 fi
241} 256}
242 257
243# 258#
244# populate a specific simple dtd version into the docbook catalog 259# populate a specific simple dtd version into the docbook catalog
245# $1 == /path/to/sdocbook.dtd 260# $1 == ./subpath/to/sdocbook.dtd
246# 261#
247populate_simple_dtd() { 262populate_simple_dtd() {
263 local dtd=${DOCBOOKDIR}/$1
248 local dtd=$1 docbookdir=${1%/*} 264 local docbookdir=${dtd%/*}
249 local v=${docbookdir##*-} adds 265 local v=${docbookdir##*-}
266 local adds dtd_date
250 267
251 # sanity check 268 # sanity check
252 if [[ ${dtd} != */xml-simple-dtd-*/* ]]; then 269 if [[ ${dtd} != */xml-simple-dtd-*/* ]]; then
253 echo "Warning: I don't understand \"${dtd}\"" >&2 270 echo "Warning: I don't understand \"${dtd}\"" >&2
254 return 271 return
271populate_entities() { 288populate_entities() {
272 local isodir=${LATEST_DTD%/*}/ent i j 289 local isodir=${LATEST_DTD%/*}/ent i j
273 local entities=() avail=() 290 local entities=() avail=()
274 291
275 # sanity check 292 # sanity check
276 if [[ -z ${LATEST_DTD} || ! -d ${isodir} ]]; then 293 if [[ -z ${LATEST_DTD} || ! -d ${ROOT}${isodir} ]]; then
277 echo "No ISO DocBook entities available for catalog" 294 echo "No ISO DocBook entities available for catalog"
278 return 0 295 return 0
279 fi 296 fi
280 echo "Using ISO DocBook entities from ${isodir}" 297 echo "Using ISO DocBook entities from ${isodir}"
281 298
302 "iso-pub.ent" "ISO 8879:1986//ENTITIES Publishing//EN" 319 "iso-pub.ent" "ISO 8879:1986//ENTITIES Publishing//EN"
303 "iso-tech.ent" "ISO 8879:1986//ENTITIES General Technical//EN" 320 "iso-tech.ent" "ISO 8879:1986//ENTITIES General Technical//EN"
304 ) 321 )
305 322
306 # here are the entities available; assume no spaces in filenames... 323 # here are the entities available; assume no spaces in filenames...
307 avail=($(ls "${isodir}" | sort)) 324 avail=($(ls "${ROOT}${isodir}" | sort))
308 325
309 # double-check the lists 326 # double-check the lists
310 verb " Populating ${CATALOG} with ISO DocBook entities" 327 verb " Populating ${CATALOG} with ISO DocBook entities"
311 i=0 ; j=0 328 i=0 ; j=0
312 while [[ ${i} -lt ${#entities[@]} || ${j} -lt ${#avail[@]} ]]; do 329 while [[ ${i} -lt ${#entities[@]} || ${j} -lt ${#avail[@]} ]]; do
322 elif [[ ${entities[i]} < ${avail[j]} ]]; then 339 elif [[ ${entities[i]} < ${avail[j]} ]]; then
323 echo "Warning: Entities file not found: ${entities[i]}" 340 echo "Warning: Entities file not found: ${entities[i]}"
324 let i=i+2 341 let i=i+2
325 elif [[ ${entities[i]} == ${avail[j]} ]]; then 342 elif [[ ${entities[i]} == ${avail[j]} ]]; then
326 xmlcatalog --noout --add "public" "${entities[i+1]}" \ 343 xmlcatalog --noout --add "public" "${entities[i+1]}" \
327 "file://${isodir}/${entities[i]}" "${CATALOG}" 344 "file://${isodir}/${entities[i]}" "${ROOT}${CATALOG}"
328 let j=j+1 345 let j=j+1
329 let i=i+2 346 let i=i+2
330 else 347 else
331 error "${0}: whoah, shouldn't be here" 348 error "${0}: whoah, shouldn't be here"
332 fi 349 fi
346 clean_catalog "${DOCBOOKDIR}/${type}-stylesheets(-[0-9\.]+)?" "${CATALOG}" 363 clean_catalog "${DOCBOOKDIR}/${type}-stylesheets(-[0-9\.]+)?" "${CATALOG}"
347 clean_catalog "${DOCBOOKDIR}/${type}-stylesheets(-[0-9\.]+)?" "${ROOTCATALOG}" 364 clean_catalog "${DOCBOOKDIR}/${type}-stylesheets(-[0-9\.]+)?" "${ROOTCATALOG}"
348 365
349 local xsldir=${DOCBOOKDIR}/${type}-stylesheets 366 local xsldir=${DOCBOOKDIR}/${type}-stylesheets
350 367
351 if [[ ! -d ${xsldir} ]]; then 368 if [[ ! -d ${ROOT}${xsldir} ]] ; then
352 echo "DocBook XSL stylesheets (${type}) not found" >&2 369 echo "DocBook XSL stylesheets (${type}) not found" >&2
353 return 1 370 return 1
354 fi 371 fi
355 372
356 if [[ ! -e ${xsldir}/html/docbook.xsl || ! -e ${xsldir}/common/l10n.xml ]]; then 373 if [[ ! -e ${ROOT}${xsldir}/html/docbook.xsl || ! -e ${ROOT}${xsldir}/common/l10n.xml ]] ; then
357 echo "DocBook XSL stylesheets are missing files from ${xsldir}" >&2 374 echo "DocBook XSL stylesheets are missing files from ${xsldir}" >&2
358 return 1 375 return 1
359 fi 376 fi
360 377
361 # Populate catalog with XSL entries 378 # Populate catalog with XSL entries

Legend:
Removed from v.1.17  
changed lines
  Added in v.1.18

  ViewVC Help
Powered by ViewVC 1.1.20