blob: d1b8c946a2f51d028d3c5573f1235fc9780dab48 [file] [log] [blame]
Daniel Veillard6d1ef172002-05-19 18:26:28 +00001#! /bin/bash
William M. Brack6ca9ec82004-07-31 18:01:53 +00002
3usage()
4{
5 cat <<EOF
6Usage: $pname [OPTION]
7
8Known values for OPTION are:
9 --prefix=DIR change the output directory for catalog files
10 [default $DIR]
11 --show display the output filenames and paths
12 --version=x.y.z change the DocBook version [default $VERSION]
13 --debug display script action information
14 --help display this help and exit
15EOF
16}
17
18setdefault()
19{
20 echo Unable to update root catalog $ROOTCATALOG
Daniel Veillarda4c8d062002-01-19 22:13:51 +000021 ROOTCATALOG=$HOME/xmlcatalog
22 CATALOG=$HOME/dbkxmlcatalog
William M. Brack6ca9ec82004-07-31 18:01:53 +000023 DIR=$HOME
24 CAT=xmlcatalog
25 echo Using $ROOTCATALOG as the root catalog
26 echo Remember to export XML_CATALOG_FILES=$ROOTCATALOG
27 echo
28 prefix=1
29}
30
31fixname()
32{
33#
34# ROOTCATALOG contains the full pathname for the catalog. We will
35# split that into the directory name and the filename, then we will
36# see if the directory exists. If it does not, we will attempt to
37# create it.
38#
39 if test $verbose = 1
40 then
41 echo Checking path $ROOTCATALOG for permissions
42 fi
43# First we split the filename and directory name
44 CAT=`basename $ROOTCATALOG`
45 DIR=`dirname $ROOTCATALOG`
46 if test "$DIR" = ""
47 then
48 echo Unable to isolate directory name from '$ROOTCATALOG' - exiting
49 exit 1
50 fi
51 CATALOG=${DIR}/docbook
52 parent=`dirname $DIR`
53 if test "$parent" == ""
54 then
55 parent=/
56 fi
57 if [ ! -d $DIR ]
58 then
59 if test $verbose = 1
60 then
61 echo Directory $DIR missing - I will try to create it
62 fi
63 if [ ! -w $parent ]
64 then
65 if test $verbose = 1
66 then
67 echo No write permission for directory $parent
68 fi
69 setdefault
70 else
71 newdir=1
72 fi
73 else
74 if [ -f $ROOTCATALOG -a ! -w $ROOTCATALOG ] ||
75 [ -e $ROOTCATALOG -a ! -f $ROOTCATALOG ] ||
76 [ ! -e $ROOTCATALOG -a ! -w $DIR ]
77 then
78 setdefault
79 fi
80 fi
81
82}
83finddbx()
84{
85dtd421=""
86s="//OASIS//DTD DocBook XML V${VERSION}//EN"
87found=`find $1 -name docbookx.dtd -exec grep -l "$s" {} \;`
88for dtd in $found; do
89 docbookdir=`dirname $dtd`
90 echo Found DocBook XML $VERSION DTD in $docbookdir
91#
92# The original script had a check for write permission on the file
93# but I can't see why it should be necessary
94#
95 dtd421=$dtd
96 break
97done
98}
99
100#
101# Preset script control params
102show=0
103prefix=0
104newdir=0
105verbose=0
106#
107# Isolate the script name for messages
108pname=`basename $0`
109VERSION=4.1.2
110
111if test "$XML_CATALOG_FILES" != ""
112then
113 ROOTCATALOG=$XML_CATALOG_FILES
114else
115 ROOTCATALOG=/etc/xml/catalog
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000116fi
117
118#
William M. Brack6ca9ec82004-07-31 18:01:53 +0000119# Interpret script parameters
120while test $# -gt 0; do
121 case "$1" in
122 -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
123 *) optarg= ;;
124 esac
125
126 case "$1" in
127 -p=* | --prefix=*)
128 ROOTCATALOG=$optarg/catalog
129 prefix=1
130 ;;
131
132 -s | --show)
133 show=1
134 ;;
135
136 -v=* | --version=*)
137 VERSION=$optarg
138 ;;
139
140 -d | --debug)
141 verbose=1
142 ;;
143
144 -h | --help)
145 usage
146 exit 0
147 ;;
148
149 * )
150 echo Invalid argument "$1"
151 usage
152 exit 1
153 ;;
154 esac
155 shift
156done
157fixname
158if test $prefix != 0
159then
160 export XML_CATALOG_FILES=$ROOTCATALOG
161fi
162if test $show != 0
163then
164 echo XML Catalog is $ROOTCATALOG
165 echo Docbook Catalog is $CATALOG
166 exit 0
167fi
168if test $newdir!=0
169then
170 mkdir -p $DIR
171 chmod 755 $DIR
172fi
173
174echo Starting run
175#
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000176# create the catalogs root and docbook specific
177#
178if [ ! -r $ROOTCATALOG ] ; then
179 echo creating XML Catalog root $ROOTCATALOG
Daniel Veillard6d1ef172002-05-19 18:26:28 +0000180 xmlcatalog --noout --create $ROOTCATALOG
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000181fi
182if [ ! -r $ROOTCATALOG ] ; then
183 echo Failed creating XML Catalog root $ROOTCATALOG
184 exit 1
185fi
186if [ ! -r $CATALOG ] ; then
187 echo creating DocBook XML Catalog $CATALOG
Daniel Veillard6d1ef172002-05-19 18:26:28 +0000188 xmlcatalog --noout --create $CATALOG
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000189fi
190if [ ! -r $CATALOG ] ; then
191 echo Failed creating DocBook XML Catalog $CATALOG
192 exit 1
193fi
194
195#
196# find the prefix for DocBook DTD
197#
William M. Brack6ca9ec82004-07-31 18:01:53 +0000198finddbx /usr/share/xml
199if [ "$dtd421" = "" ] ; then
200 finddbx $HOME
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000201fi
William M. Brack6ca9ec82004-07-31 18:01:53 +0000202if [ "$dtd421" = "" ] ; then
203 finddbx /usr/local
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000204fi
William M. Brack6ca9ec82004-07-31 18:01:53 +0000205if [ "$dtd421" = "" ] ; then
206 finddbx /usr/share/sgml
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000207fi
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000208
209if [ "$dtd421" = "" ] ; then
William M. Brack6ca9ec82004-07-31 18:01:53 +0000210 echo could not locate version $VERSION of DocBook XML
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000211 exit 1
212fi
213
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000214xmlcatalog --noout --add "public" \
William M. Brack6ca9ec82004-07-31 18:01:53 +0000215 "-//OASIS//ELEMENTS DocBook XML Information Pool V${VERSION}//EN" \
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000216 "file://$docbookdir/dbpoolx.mod" $CATALOG
217xmlcatalog --noout --add "public" \
William M. Brack6ca9ec82004-07-31 18:01:53 +0000218 "-//OASIS//DTD DocBook XML V${VERSION}//EN" \
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000219 "file://$docbookdir/docbookx.dtd" $CATALOG
220xmlcatalog --noout --add "public" \
William M. Brack6ca9ec82004-07-31 18:01:53 +0000221 "-//OASIS//ENTITIES DocBook XML Character Entities V${VERSION}//EN" \
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000222 "file://$docbookdir/dbcentx.mod" $CATALOG
223xmlcatalog --noout --add "public" \
William M. Brack6ca9ec82004-07-31 18:01:53 +0000224 "-//OASIS//ENTITIES DocBook XML Notations V${VERSION}//EN" \
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000225 "file://$docbookdir/dbnotnx.mod" $CATALOG
226xmlcatalog --noout --add "public" \
William M. Brack6ca9ec82004-07-31 18:01:53 +0000227 "-//OASIS//ENTITIES DocBook XML Additional General Entities V${VERSION}//EN" \
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000228 "file://$docbookdir/dbgenent.mod" $CATALOG
229xmlcatalog --noout --add "public" \
William M. Brack6ca9ec82004-07-31 18:01:53 +0000230 "-//OASIS//ELEMENTS DocBook XML Document Hierarchy V${VERSION}//EN" \
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000231 "file://$docbookdir/dbhierx.mod" $CATALOG
232xmlcatalog --noout --add "public" \
233 "-//OASIS//DTD XML Exchange Table Model 19990315//EN" \
234 "file://$docbookdir/soextblx.dtd" $CATALOG
235xmlcatalog --noout --add "public" \
William M. Brack6ca9ec82004-07-31 18:01:53 +0000236 "-//OASIS//DTD DocBook XML CALS Table Model V${VERSION}//EN" \
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000237 "file://$docbookdir/calstblx.dtd" $CATALOG
238xmlcatalog --noout --add "rewriteSystem" \
William M. Brack6ca9ec82004-07-31 18:01:53 +0000239 "http://www.oasis-open.org/docbook/xml/${VERSION}" \
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000240 "file://$docbookdir" $CATALOG
241xmlcatalog --noout --add "rewriteURI" \
William M. Brack6ca9ec82004-07-31 18:01:53 +0000242 "http://www.oasis-open.org/docbook/xml/${VERSION}" \
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000243 "file://$docbookdir" $CATALOG
244
245xmlcatalog --noout --add "delegatePublic" \
246 "-//OASIS//ENTITIES DocBook XML" \
247 "file://$CATALOG" $ROOTCATALOG
248xmlcatalog --noout --add "delegatePublic" \
249 "-//OASIS//DTD DocBook XML" \
250 "file://$CATALOG" $ROOTCATALOG
251xmlcatalog --noout --add "delegateSystem" \
252 "http://www.oasis-open.org/docbook/" \
253 "file://$CATALOG" $ROOTCATALOG
254xmlcatalog --noout --add "delegateURI" \
255 "http://www.oasis-open.org/docbook/" \
256 "file://$CATALOG" $ROOTCATALOG
257
258#
259# find the prefix for ISO DocBook entities
260#
261top=`dirname $docbookdir`
262found=`find $top -name iso-amsb.ent`
263if [ "$found" = "" ] ; then
264 found=`find /usr/share/xml -name iso-amsb.ent`
265fi
266if [ "$found" = "" ] ; then
267 found=`find $HOME -name iso-amsb.ent`
268fi
269if [ "$found" = "" ] ; then
270 found=`find /usr/local -name iso-amsb.ent`
271fi
272if [ "$found" = "" ] ; then
273 found=`find /usr/share/sgml -name iso-amsb.ent`
274fi
275if [ "$found" = "" ] ; then
276 echo could not locate iso-amsb.ent of ISO DocBook entities
277 exit 1
278fi
279
280entxml=""
281for tst in $found; do
282 check=`grep '<!ENTITY ominus."\&#x2296;">' $tst`
283 if [ "$check" != "" ] ; then
284 entxml=$tst
285 break
286 fi
287done
288
289if [ "$entxml" = "" ] ; then
290 echo could not locate ISO DocBook entities
291 exit 1
292fi
293isodir=`dirname $entxml`
294echo Found ISO DocBook entities in $isodir
295
296xmlcatalog --noout --add "public" \
297 "ISO 8879:1986//ENTITIES Publishing//EN" \
298 "file://$isodir/iso-pub.ent" $CATALOG
299xmlcatalog --noout --add "public" \
300 "ISO 8879:1986//ENTITIES Greek Letters//EN" \
301 "file://$isodir/iso-grk1.ent" $CATALOG
302xmlcatalog --noout --add "public" \
303 "ISO 8879:1986//ENTITIES Box and Line Drawing//EN" \
304 "file://$isodir/iso-box.ent" $CATALOG
305xmlcatalog --noout --add "public" \
306 "ISO 8879:1986//ENTITIES Greek Symbols//EN" \
307 "file://$isodir/iso-grk3.ent" $CATALOG
308xmlcatalog --noout --add "public" \
309 "ISO 8879:1986//ENTITIES Added Math Symbols: Negated Relations//EN" \
310 "file://$isodir/iso-amsn.ent" $CATALOG
311xmlcatalog --noout --add "public" \
312 "ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN" \
313 "file://$isodir/iso-num.ent" $CATALOG
314xmlcatalog --noout --add "public" \
315 "ISO 8879:1986//ENTITIES Alternative Greek Symbols//EN" \
316 "file://$isodir/iso-grk4.ent" $CATALOG
317xmlcatalog --noout --add "public" \
318 "ISO 8879:1986//ENTITIES Diacritical Marks//EN" \
319 "file://$isodir/iso-dia.ent" $CATALOG
320xmlcatalog --noout --add "public" \
321 "ISO 8879:1986//ENTITIES Monotoniko Greek//EN" \
322 "file://$isodir/iso-grk2.ent" $CATALOG
323xmlcatalog --noout --add "public" \
324 "ISO 8879:1986//ENTITIES Added Math Symbols: Arrow Relations//EN" \
325 "file://$isodir/iso-amsa.ent" $CATALOG
326xmlcatalog --noout --add "public" \
327 "ISO 8879:1986//ENTITIES Added Math Symbols: Ordinary//EN" \
328 "file://$isodir/iso-amso.ent" $CATALOG
329xmlcatalog --noout --add "public" \
330 "ISO 8879:1986//ENTITIES Russian Cyrillic//EN" \
331 "file://$isodir/iso-cyr1.ent" $CATALOG
332xmlcatalog --noout --add "public" \
333 "ISO 8879:1986//ENTITIES General Technical//EN" \
334 "file://$isodir/iso-tech.ent" $CATALOG
335xmlcatalog --noout --add "public" \
336 "ISO 8879:1986//ENTITIES Added Math Symbols: Delimiters//EN" \
337 "file://$isodir/iso-amsc.ent" $CATALOG
338xmlcatalog --noout --add "public" \
339 "ISO 8879:1986//ENTITIES Added Latin 1//EN" \
340 "file://$isodir/iso-lat1.ent" $CATALOG
341xmlcatalog --noout --add "public" \
342 "ISO 8879:1986//ENTITIES Added Math Symbols: Binary Operators//EN" \
343 "file://$isodir/iso-amsb.ent" $CATALOG
344xmlcatalog --noout --add "public" \
345 "ISO 8879:1986//ENTITIES Added Latin 2//EN" \
346 "file://$isodir/iso-lat2.ent" $CATALOG
347xmlcatalog --noout --add "public" \
348 "ISO 8879:1986//ENTITIES Added Math Symbols: Relations//EN" \
349 "file://$isodir/iso-amsr.ent" $CATALOG
350xmlcatalog --noout --add "public" \
351 "ISO 8879:1986//ENTITIES Non-Russian Cyrillic//EN" \
352 "file://$isodir/iso-cyr2.ent" $CATALOG
353
354xmlcatalog --noout --add "delegatePublic" \
355 "ISO 8879:1986" \
356 "file://$CATALOG" $ROOTCATALOG
357
358#
359# find the prefix for XSLT stylesheets
360#
361top=`dirname $docbookdir`
Daniel Veillard05d39112002-01-30 10:47:44 +0000362found=`find $top -name chunk.xsl`
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000363if [ "$found" = "" ] ; then
Daniel Veillard05d39112002-01-30 10:47:44 +0000364 found=`find /usr/share/xml -name chunk.xsl`
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000365fi
366if [ "$found" = "" ] ; then
Daniel Veillard05d39112002-01-30 10:47:44 +0000367 found=`find $HOME -name chunk.xsl`
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000368fi
369if [ "$found" = "" ] ; then
Daniel Veillard05d39112002-01-30 10:47:44 +0000370 found=`find /usr/local -name chunk.xsl`
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000371fi
372if [ "$found" = "" ] ; then
Daniel Veillard05d39112002-01-30 10:47:44 +0000373 found=`find /usr/share/sgml -name chunk.xsl`
Daniel Veillarda4c8d062002-01-19 22:13:51 +0000374fi
375if [ "$found" = "" ] ; then
376 echo could not locate chunk-common.xsl of DocBook XSLT stylesheets
377 exit 1
378fi
379
380xsldir=""
381for tst in $found; do
382 dir=`dirname $tst`
383 dir=`dirname $dir`
384 if [ -r $dir/html/docbook.xsl -a -r $dir/common/l10n.xml ]; then
385 xsldir=$dir
386 break
387 fi
388done
389
390if [ "$xsldir" = "" ] ; then
391 echo could not locate DocBook XSLT stylesheets
392 exit 1
393fi
394echo Found DocBook XSLT stylesheets in $xsldir
395for version in current 1.39 1.40 1.41 1.42 1.43 1.44 1.45 1.46 1.47 \
396 1.48 1.49 1.50
397do
398 xmlcatalog --noout --add "rewriteSystem" \
399 "http://docbook.sourceforge.net/release/xsl/$version" \
400 "file://$xsldir" $CATALOG
401 xmlcatalog --noout --add "rewriteURI" \
402 "http://docbook.sourceforge.net/release/xsl/$version" \
403 "file://$xsldir" $CATALOG
404done
405
406xmlcatalog --noout --add "delegateSystem" \
407 "http://docbook.sourceforge.net/release/xsl/" \
408 "file://$CATALOG" $ROOTCATALOG
409xmlcatalog --noout --add "delegateURI" \
410 "http://docbook.sourceforge.net/release/xsl/" \
411 "file://$CATALOG" $ROOTCATALOG
412
413#
414#