• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#! /bin/bash
2
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
21    ROOTCATALOG=$HOME/xmlcatalog
22    CATALOG=$HOME/dbkxmlcatalog
23    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
116fi
117
118#
119# 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#
176# create the catalogs root and docbook specific
177#
178if [ ! -r $ROOTCATALOG ] ; then
179   echo creating XML Catalog root $ROOTCATALOG
180   xmlcatalog --noout --create $ROOTCATALOG
181fi
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
188   xmlcatalog --noout --create $CATALOG
189fi
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#
198finddbx /usr/share/xml
199if [ "$dtd421" = "" ] ; then
200    finddbx $HOME
201fi
202if [ "$dtd421" = "" ] ; then
203    finddbx /usr/local
204fi
205if [ "$dtd421" = "" ] ; then
206    finddbx /usr/share/sgml
207fi
208
209if [ "$dtd421" = "" ] ; then
210    echo could not locate version $VERSION of DocBook XML
211    exit 1
212fi
213
214xmlcatalog --noout --add "public" \
215    "-//OASIS//ELEMENTS DocBook XML Information Pool V${VERSION}//EN" \
216    "file://$docbookdir/dbpoolx.mod" $CATALOG
217xmlcatalog --noout --add "public" \
218    "-//OASIS//DTD DocBook XML V${VERSION}//EN" \
219    "file://$docbookdir/docbookx.dtd" $CATALOG
220xmlcatalog --noout --add "public" \
221    "-//OASIS//ENTITIES DocBook XML Character Entities V${VERSION}//EN" \
222    "file://$docbookdir/dbcentx.mod" $CATALOG
223xmlcatalog --noout --add "public" \
224    "-//OASIS//ENTITIES DocBook XML Notations V${VERSION}//EN" \
225    "file://$docbookdir/dbnotnx.mod" $CATALOG
226xmlcatalog --noout --add "public" \
227    "-//OASIS//ENTITIES DocBook XML Additional General Entities V${VERSION}//EN" \
228    "file://$docbookdir/dbgenent.mod" $CATALOG
229xmlcatalog --noout --add "public" \
230    "-//OASIS//ELEMENTS DocBook XML Document Hierarchy V${VERSION}//EN" \
231    "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" \
236    "-//OASIS//DTD DocBook XML CALS Table Model V${VERSION}//EN" \
237    "file://$docbookdir/calstblx.dtd" $CATALOG
238xmlcatalog --noout --add "rewriteSystem" \
239    "http://www.oasis-open.org/docbook/xml/${VERSION}" \
240    "file://$docbookdir" $CATALOG
241xmlcatalog --noout --add "rewriteURI" \
242    "http://www.oasis-open.org/docbook/xml/${VERSION}" \
243    "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`
362found=`find $top -name chunk.xsl`
363if [ "$found" = "" ] ; then
364    found=`find /usr/share/xml -name chunk.xsl`
365fi
366if [ "$found" = "" ] ; then
367    found=`find $HOME -name chunk.xsl`
368fi
369if [ "$found" = "" ] ; then
370    found=`find /usr/local -name chunk.xsl`
371fi
372if [ "$found" = "" ] ; then
373    found=`find /usr/share/sgml -name chunk.xsl`
374fi
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#
415