/ libxml2 / doc / buildDocBookCatalog
buildDocBookCatalog
  1  #! /bin/bash
  2  
  3  usage()
  4  {
  5      cat <<EOF
  6  Usage: $pname [OPTION]
  7  
  8  Known 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
 15  EOF
 16  }
 17  
 18  setdefault()
 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  
 31  fixname()
 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  }
 83  finddbx()
 84  {
 85  dtd421=""
 86  s="//OASIS//DTD DocBook XML V${VERSION}//EN"
 87  found=`find $1 -name docbookx.dtd -exec grep -l "$s" {} \;`
 88  for 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
 97  done
 98  }
 99  
100  #
101  # Preset script control params
102  show=0
103  prefix=0
104  newdir=0
105  verbose=0
106  #
107  # Isolate the script name for messages
108  pname=`basename $0`
109  VERSION=4.1.2
110  
111  if test "$XML_CATALOG_FILES" != ""
112  then
113      ROOTCATALOG=$XML_CATALOG_FILES
114  else
115      ROOTCATALOG=/etc/xml/catalog
116  fi
117  
118  #
119  # Interpret script parameters
120  while 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
156  done
157  fixname
158  if test $prefix != 0
159  then
160      export XML_CATALOG_FILES=$ROOTCATALOG
161  fi
162  if test $show != 0
163  then
164      echo XML Catalog is $ROOTCATALOG
165      echo Docbook Catalog is $CATALOG
166      exit 0
167  fi
168  if test $newdir!=0
169  then
170      mkdir -p $DIR
171      chmod 755 $DIR
172  fi
173  
174  echo Starting run
175  #
176  # create the catalogs root and docbook specific
177  #
178  if [ ! -r $ROOTCATALOG ] ; then
179     echo creating XML Catalog root $ROOTCATALOG
180     xmlcatalog --noout --create $ROOTCATALOG
181  fi
182  if [ ! -r $ROOTCATALOG ] ; then
183     echo Failed creating XML Catalog root $ROOTCATALOG
184     exit 1
185  fi
186  if [ ! -r $CATALOG ] ; then
187     echo creating DocBook XML Catalog $CATALOG
188     xmlcatalog --noout --create $CATALOG
189  fi
190  if [ ! -r $CATALOG ] ; then
191     echo Failed creating DocBook XML Catalog $CATALOG
192     exit 1
193  fi
194  
195  #
196  # find the prefix for DocBook DTD
197  #
198  finddbx /usr/share/xml
199  if [ "$dtd421" = "" ] ; then
200      finddbx $HOME
201  fi
202  if [ "$dtd421" = "" ] ; then
203      finddbx /usr/local
204  fi
205  if [ "$dtd421" = "" ] ; then
206      finddbx /usr/share/sgml
207  fi
208  
209  if [ "$dtd421" = "" ] ; then
210      echo could not locate version $VERSION of DocBook XML
211      exit 1
212  fi
213  
214  xmlcatalog --noout --add "public" \
215      "-//OASIS//ELEMENTS DocBook XML Information Pool V${VERSION}//EN" \
216      "file://$docbookdir/dbpoolx.mod" $CATALOG
217  xmlcatalog --noout --add "public" \
218      "-//OASIS//DTD DocBook XML V${VERSION}//EN" \
219      "file://$docbookdir/docbookx.dtd" $CATALOG
220  xmlcatalog --noout --add "public" \
221      "-//OASIS//ENTITIES DocBook XML Character Entities V${VERSION}//EN" \
222      "file://$docbookdir/dbcentx.mod" $CATALOG
223  xmlcatalog --noout --add "public" \
224      "-//OASIS//ENTITIES DocBook XML Notations V${VERSION}//EN" \
225      "file://$docbookdir/dbnotnx.mod" $CATALOG
226  xmlcatalog --noout --add "public" \
227      "-//OASIS//ENTITIES DocBook XML Additional General Entities V${VERSION}//EN" \
228      "file://$docbookdir/dbgenent.mod" $CATALOG
229  xmlcatalog --noout --add "public" \
230      "-//OASIS//ELEMENTS DocBook XML Document Hierarchy V${VERSION}//EN" \
231      "file://$docbookdir/dbhierx.mod" $CATALOG
232  xmlcatalog --noout --add "public" \
233      "-//OASIS//DTD XML Exchange Table Model 19990315//EN" \
234      "file://$docbookdir/soextblx.dtd" $CATALOG
235  xmlcatalog --noout --add "public" \
236      "-//OASIS//DTD DocBook XML CALS Table Model V${VERSION}//EN" \
237      "file://$docbookdir/calstblx.dtd" $CATALOG
238  xmlcatalog --noout --add "rewriteSystem" \
239      "http://www.oasis-open.org/docbook/xml/${VERSION}" \
240      "file://$docbookdir" $CATALOG
241  xmlcatalog --noout --add "rewriteURI" \
242      "http://www.oasis-open.org/docbook/xml/${VERSION}" \
243      "file://$docbookdir" $CATALOG
244  
245  xmlcatalog --noout --add "delegatePublic" \
246      "-//OASIS//ENTITIES DocBook XML" \
247      "file://$CATALOG" $ROOTCATALOG
248  xmlcatalog --noout --add "delegatePublic" \
249      "-//OASIS//DTD DocBook XML" \
250      "file://$CATALOG" $ROOTCATALOG
251  xmlcatalog --noout --add "delegateSystem" \
252      "http://www.oasis-open.org/docbook/" \
253      "file://$CATALOG" $ROOTCATALOG
254  xmlcatalog --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  #
261  top=`dirname $docbookdir`
262  found=`find $top -name iso-amsb.ent`
263  if [ "$found" = "" ] ; then
264      found=`find /usr/share/xml -name iso-amsb.ent`
265  fi
266  if [ "$found" = "" ] ; then
267      found=`find $HOME -name iso-amsb.ent`
268  fi
269  if [ "$found" = "" ] ; then
270      found=`find /usr/local -name iso-amsb.ent`
271  fi
272  if [ "$found" = "" ] ; then
273      found=`find /usr/share/sgml -name iso-amsb.ent`
274  fi
275  if [ "$found" = "" ] ; then
276      echo could not locate iso-amsb.ent of ISO DocBook entities
277      exit 1
278  fi
279  
280  entxml=""
281  for tst in $found; do
282      check=`grep '<!ENTITY ominus."\&#x2296;">' $tst`
283      if [ "$check" != "" ] ; then
284          entxml=$tst
285          break
286      fi
287  done
288  
289  if [ "$entxml" = "" ] ; then
290      echo could not locate ISO DocBook entities
291      exit 1
292  fi
293  isodir=`dirname $entxml`
294  echo Found ISO DocBook entities in $isodir
295  
296  xmlcatalog --noout --add "public" \
297      "ISO 8879:1986//ENTITIES Publishing//EN" \
298      "file://$isodir/iso-pub.ent" $CATALOG
299  xmlcatalog --noout --add "public" \
300      "ISO 8879:1986//ENTITIES Greek Letters//EN" \
301      "file://$isodir/iso-grk1.ent" $CATALOG
302  xmlcatalog --noout --add "public" \
303      "ISO 8879:1986//ENTITIES Box and Line Drawing//EN" \
304      "file://$isodir/iso-box.ent" $CATALOG
305  xmlcatalog --noout --add "public" \
306      "ISO 8879:1986//ENTITIES Greek Symbols//EN" \
307      "file://$isodir/iso-grk3.ent" $CATALOG
308  xmlcatalog --noout --add "public" \
309      "ISO 8879:1986//ENTITIES Added Math Symbols: Negated Relations//EN" \
310      "file://$isodir/iso-amsn.ent" $CATALOG
311  xmlcatalog --noout --add "public" \
312      "ISO 8879:1986//ENTITIES Numeric and Special Graphic//EN" \
313      "file://$isodir/iso-num.ent" $CATALOG
314  xmlcatalog --noout --add "public" \
315      "ISO 8879:1986//ENTITIES Alternative Greek Symbols//EN" \
316      "file://$isodir/iso-grk4.ent" $CATALOG
317  xmlcatalog --noout --add "public" \
318      "ISO 8879:1986//ENTITIES Diacritical Marks//EN" \
319      "file://$isodir/iso-dia.ent" $CATALOG
320  xmlcatalog --noout --add "public" \
321      "ISO 8879:1986//ENTITIES Monotoniko Greek//EN" \
322      "file://$isodir/iso-grk2.ent" $CATALOG
323  xmlcatalog --noout --add "public" \
324      "ISO 8879:1986//ENTITIES Added Math Symbols: Arrow Relations//EN" \
325      "file://$isodir/iso-amsa.ent" $CATALOG
326  xmlcatalog --noout --add "public" \
327      "ISO 8879:1986//ENTITIES Added Math Symbols: Ordinary//EN" \
328      "file://$isodir/iso-amso.ent" $CATALOG
329  xmlcatalog --noout --add "public" \
330      "ISO 8879:1986//ENTITIES Russian Cyrillic//EN" \
331      "file://$isodir/iso-cyr1.ent" $CATALOG
332  xmlcatalog --noout --add "public" \
333      "ISO 8879:1986//ENTITIES General Technical//EN" \
334      "file://$isodir/iso-tech.ent" $CATALOG
335  xmlcatalog --noout --add "public" \
336      "ISO 8879:1986//ENTITIES Added Math Symbols: Delimiters//EN" \
337      "file://$isodir/iso-amsc.ent" $CATALOG
338  xmlcatalog --noout --add "public" \
339      "ISO 8879:1986//ENTITIES Added Latin 1//EN" \
340      "file://$isodir/iso-lat1.ent" $CATALOG
341  xmlcatalog --noout --add "public" \
342      "ISO 8879:1986//ENTITIES Added Math Symbols: Binary Operators//EN" \
343      "file://$isodir/iso-amsb.ent" $CATALOG
344  xmlcatalog --noout --add "public" \
345      "ISO 8879:1986//ENTITIES Added Latin 2//EN" \
346      "file://$isodir/iso-lat2.ent" $CATALOG
347  xmlcatalog --noout --add "public" \
348      "ISO 8879:1986//ENTITIES Added Math Symbols: Relations//EN" \
349      "file://$isodir/iso-amsr.ent" $CATALOG
350  xmlcatalog --noout --add "public" \
351      "ISO 8879:1986//ENTITIES Non-Russian Cyrillic//EN" \
352      "file://$isodir/iso-cyr2.ent" $CATALOG
353  
354  xmlcatalog --noout --add "delegatePublic" \
355      "ISO 8879:1986" \
356      "file://$CATALOG" $ROOTCATALOG
357  
358  #
359  # find the prefix for XSLT stylesheets
360  #
361  top=`dirname $docbookdir`
362  found=`find $top -name chunk.xsl`
363  if [ "$found" = "" ] ; then
364      found=`find /usr/share/xml -name chunk.xsl`
365  fi
366  if [ "$found" = "" ] ; then
367      found=`find $HOME -name chunk.xsl`
368  fi
369  if [ "$found" = "" ] ; then
370      found=`find /usr/local -name chunk.xsl`
371  fi
372  if [ "$found" = "" ] ; then
373      found=`find /usr/share/sgml -name chunk.xsl`
374  fi
375  if [ "$found" = "" ] ; then
376      echo could not locate chunk-common.xsl of DocBook XSLT stylesheets
377      exit 1
378  fi
379  
380  xsldir=""
381  for 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
388  done
389  
390  if [ "$xsldir" = "" ] ; then
391      echo could not locate DocBook XSLT stylesheets
392      exit 1
393  fi
394  echo Found DocBook XSLT stylesheets in $xsldir
395  for 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
397  do
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
404  done
405  
406  xmlcatalog --noout --add "delegateSystem" \
407      "http://docbook.sourceforge.net/release/xsl/" \
408      "file://$CATALOG" $ROOTCATALOG
409  xmlcatalog --noout --add "delegateURI" \
410      "http://docbook.sourceforge.net/release/xsl/" \
411      "file://$CATALOG" $ROOTCATALOG
412  
413  #
414  #