]> git.evergreen-ils.org Git - working/Evergreen.git/blob - stylesheets/evergreen_docbook_files/docbook-xsl-1.75.2/install.sh
Add stylesheets for our evergreen docbook site.
[working/Evergreen.git] / stylesheets / evergreen_docbook_files / docbook-xsl-1.75.2 / install.sh
1 #!/bin/bash\r
2 # $Id: install.sh 7942 2008-03-26 06:08:08Z xmldoc $\r
3 # $Source$ #\r
4 \r
5 # install.sh - Set up user environment for a XML/XSLT distribution\r
6 \r
7 # This is as an interactive installer for updating your\r
8 # environment to use an XML/XSLT distribution such as the DocBook\r
9 # XSL Stylesheets. Its main purpose is to configure your\r
10 # environment with XML catalog data and schema "locating rules"\r
11 # data provided in the XML/XSLT distribution.\r
12 #\r
13 # Although this installer was created for the DocBook project, it\r
14 # is a general-purpose tool that can be used with any XML/XSLT\r
15 # distribution that provides XML/SGML catalogs and locating rules.\r
16 #\r
17 # This script is mainly intended to make things easier for you if\r
18 # you want to install a particular XML/XSLT distribution that has\r
19 # not (yet) been packaged for your OS distro (Debian, Fedora,\r
20 # whatever), or to use "snapshot" or development releases \r
21 #\r
22 # It works by updating your shell startup file (e.g., .bashrc and\r
23 # .cshrc) and .emacs file and by finding or creating a writable\r
24 # CatalogManager.properties file to update.\r
25 #\r
26 # It makes backup copies of any files it touches, and also\r
27 # generates a uninstall.sh script for reverting its changes.\r
28 #\r
29 # In the same directory where it is located, it expects to find\r
30 # the following four files:\r
31 #   - locatingrules.xml\r
32 #   - catalog.xml\r
33 #   - catalog\r
34 #   - .urilist\r
35 # And if it's unable to locate a CatalogManager.properties file in\r
36 # your environment, it expects to find an "example" one in the\r
37 # same directory as itself, which it copies over to your\r
38 # ~/.resolver directory.\r
39 #\r
40 # If the distribution contains any executables, change the value\r
41 # of the thisBinDir to a colon-separated list of the pathnames of\r
42 # the directories that contain those executables.\r
43 \r
44 # mydir is the "canonical" absolute pathname for install.sh\r
45 mydir=$(cd -P $(dirname $0) && pwd -P) || exit 1\r
46 \r
47 thisLocatingRules=$mydir/locatingrules.xml\r
48 thisXmlCatalog=$mydir/catalog.xml\r
49 thisSgmlCatalog=$mydir/catalog\r
50 \r
51 # .urilist file contains a list of pairs of local pathnames and\r
52 # URIs to test for catalog resolution\r
53 thisUriList=$mydir/.urilist\r
54 exampleCatalogManager=$mydir/.CatalogManager.properties.example\r
55 thisCatalogManager=$HOME/.resolver/CatalogManager.properties\r
56 \r
57 # thisBinDir directory is a colon-separated list of the pathnames\r
58 # to all directories that contain executables provided with the\r
59 # distribution (for example, the DocBook XSL Stylesheets\r
60 # distribution contains a "docbook-xsl-update" convenience script\r
61 # for rsync'ing up to the latest docbook-xsl snapshot). The\r
62 # install.sh script adds the value of thisBinDir to your PATH\r
63 # environment variable\r
64 thisBinDir=$mydir/tools/bin\r
65 \r
66 emit_message() {\r
67   echo "$1" 1>&2\r
68 }\r
69 \r
70 if [ ! "${*#--batch}" = "$*" ]; then\r
71   batchmode="Yes";\r
72 else\r
73   batchmode="No";\r
74   emit_message\r
75   if [ ! "$1" = "--test" ]; then \r
76     emit_message "NOTE: For non-interactive installs/uninstalls, use --batch"\r
77     if [ ! "$1" = "--uninstall" ]; then\r
78       emit_message\r
79     fi\r
80   fi\r
81 fi\r
82 \r
83 osName="Unidentified"\r
84 if uname -s | grep -qi "cygwin"; then\r
85   osName="Cygwin"\r
86 fi\r
87 \r
88 classPathSeparator=":"\r
89 if [ "$osName" = "Cygwin" ]; then\r
90   thisJavaXmlCatalog=$(cygpath -m $thisXmlCatalog)\r
91   classPathSeparator=";"\r
92 else\r
93   thisJavaXmlCatalog=$thisXmlCatalog\r
94 fi\r
95 \r
96 main() {\r
97   removeOldFiles\r
98   checkRoot\r
99   updateCatalogManager\r
100   checkForResolver\r
101   writeDotFiles\r
102   updateUserStartupFiles\r
103   updateUserDotEmacs\r
104   writeUninstallFile\r
105   writeTestFile\r
106   printExitMessage\r
107 }\r
108 \r
109 removeOldFiles() {\r
110   rm -f $mydir/.profile.incl\r
111   rm -f $mydir/.cshrc.incl\r
112   rm -f $mydir/.emacs.el\r
113 }\r
114 \r
115 checkRoot() {\r
116   if [ $(id -u)  == "0" ]; then\r
117     cat 1>&2 <<EOF\r
118 \r
119 WARNING: This install script is meant to be run as a non-root\r
120          user, but you are running it as root.\r
121 \r
122 EOF\r
123     read -s -n1 -p "Are you sure you want to continue? [No] "\r
124     emit_message "$REPLY"\r
125     case $REPLY in\r
126       [yY])\r
127       emit_message\r
128       ;;\r
129       *) emit_message "OK, exiting without making changes."\r
130       exit\r
131       ;;\r
132     esac\r
133   fi\r
134   return 0\r
135 }\r
136 \r
137 updateCatalogManager() {\r
138 \r
139   #  - finds or creates a writable CatalogManager.properties file\r
140   #\r
141   #  - adds the catalog.xml file for this distribution to the\r
142   #    CatalogManager.properties file found\r
143 \r
144   if [ -z "$CLASSPATH" ]; then\r
145     cat 1>&2 <<EOF\r
146 \r
147 NOTE: There is no CLASSPATH variable set in your environment.\r
148       No attempt was made to find a CatalogManager.properties\r
149       file.  Using $thisCatalogManager instead\r
150 EOF\r
151   else\r
152     # split CLASSPATH in a list of pathnames by replacing all separator\r
153     # characters with spaces\r
154     if [ "$osName" = "Cygwin" ]; then\r
155       pathnames=$(echo $CLASSPATH | tr ";" " ")\r
156     else\r
157       pathnames=$(echo $CLASSPATH | tr ":" " ")\r
158     fi\r
159     for path in $pathnames; do\r
160     if [ "$osName" = "Cygwin" ]; then\r
161       path=$(cygpath -u $path)\r
162     fi\r
163       # strip out trailing slash from pathname\r
164       path=$(echo $path | sed 's/\/$//')\r
165       # find CatalogManager.properties file\r
166       if [ -f $path/CatalogManager.properties ];\r
167       then\r
168         existingCatalogManager=$path/CatalogManager.properties\r
169         break\r
170       fi\r
171     done\r
172   fi\r
173   # end of CLASSPATH check\r
174 \r
175   if [ -w "$existingCatalogManager" ]; then\r
176     # existing CatalogManager.properties was found and it is\r
177     # writable, so use it\r
178     myCatalogManager=$existingCatalogManager\r
179   else\r
180     if [ -f "$existingCatalogManager" ]; then\r
181       # a non-writable CatalogManager.properties exists, so emit a\r
182       # note saying that it won't be used\r
183       cat 1>&2 <<EOF\r
184 NOTE: $existingCatalogManager file found,\r
185       but you don't have permission to write to it.\r
186       Will instead use:\r
187       $thisCatalogManager\r
188 EOF\r
189     else\r
190       # CLASSPATH is set, but no CatalogManager.properties found\r
191       if [ -n "$CLASSPATH" ]; then\r
192         cat 1>&2 <<EOF\r
193 NOTE: No CatalogManager.properties found from CLASSPATH.\r
194       Will instead use:\r
195       $thisCatalogManager\r
196 EOF\r
197       fi\r
198     fi\r
199     if [ "$batchmode" = "Yes" ]; then\r
200       emit_message\r
201     fi\r
202     # end of check for existing writable CatalogManager.properties\r
203 \r
204     if [ -f $thisCatalogManager ]; then\r
205       myCatalogManager=$thisCatalogManager\r
206     else\r
207       REPLY=""\r
208       if [ ! "$batchmode" = "Yes" ]; then\r
209         emit_message\r
210         read -s -n1 -p "Create $thisCatalogManager file? [Yes] "\r
211         emit_message "$REPLY"\r
212         emit_message\r
213       fi\r
214       case $REPLY in\r
215         [nNqQ])\r
216         emitNoChangeMsg\r
217         ;;\r
218         *)\r
219         if [ ! -d "${thisCatalogManager%/*}" ]; then\r
220           mkdir -p ${thisCatalogManager%/*}\r
221         fi\r
222         cp $mydir/.CatalogManager.properties.example $thisCatalogManager || exit 1\r
223         emit_message "NOTE: Created the following file:"\r
224         emit_message "      $thisCatalogManager"\r
225         myCatalogManager=$thisCatalogManager\r
226         ;;\r
227       esac\r
228       # end of creating "private" CatalogManager.properties\r
229     fi\r
230     # end of check for "private" CatalogManager.properties\r
231   fi\r
232   # end of check finding/creating writable CatalogManager.properties\r
233 \r
234   if [ -n "$myCatalogManager" ]; then\r
235     etcXmlCatalog=\r
236     catalogsLine=$(grep "^catalogs=" $myCatalogManager)\r
237     if [ -f /etc/xml/catalog ] && [ "$osName" != "Cygwin" ] \\r
238       && [ "${catalogsLine#*/etc/xml/catalog*}" = "$catalogsLine" ]; then\r
239       cat 1>&2 <<EOF\r
240 \r
241 WARNING: /etc/xml/catalog exists but was not found in:\r
242          $myCatalogManager\r
243          If /etc/xml/catalog file has content, you probably\r
244          should reference it in:\r
245          $myCatalogManager\r
246          This installer can automatically add it for you,\r
247          but BE WARNED that once it has been added, the\r
248          uninstaller for this distribution CANNOT REMOVE IT\r
249          automatically during uninstall. If you no longer want\r
250          it included, you will need to remove it manually.\r
251 \r
252 EOF\r
253       REPLY=""\r
254       if [ ! "$batchmode" = "Yes" ]; then\r
255         read -s -n1 -p "Add /etc/xml/catalog to $myCatalogManager? [Yes] "\r
256         emit_message "$REPLY"\r
257       fi\r
258       case $REPLY in\r
259         [nNqQ])\r
260         emit_message\r
261         ;;\r
262         *)\r
263         etcXmlCatalog=/etc/xml/catalog\r
264         ;;\r
265       esac\r
266     fi\r
267 \r
268     catalogBackup="$myCatalogManager.$$.bak"\r
269     if [ ! -w "${myCatalogManager%/*}" ]; then\r
270       emit_message\r
271       emit_message "WARNING: ${myCatalogManager%/*} directory is not writable."\r
272       emit_message\r
273       emitNoChangeMsg\r
274     else\r
275       REPLY=""\r
276       if [ ! "$batchmode" = "Yes" ]; then\r
277         emit_message\r
278         emit_message "Add $thisJavaXmlCatalog"\r
279         read -s -n1 -p "to $myCatalogManager file? [Yes] "\r
280         emit_message "$REPLY"\r
281         emit_message\r
282       fi\r
283       case $REPLY in\r
284         [nNqQ])\r
285         emitNoChangeMsg\r
286         ;;\r
287         *)\r
288         if [ "$catalogsLine" ] ; then\r
289           if [ "${catalogsLine#*$thisJavaXmlCatalog*}" != "$catalogsLine" ]; then\r
290             emit_message "NOTE: $thisJavaXmlCatalog"\r
291             emit_message "      already in:"\r
292             emit_message "      $myCatalogManager"\r
293           else\r
294             mv $myCatalogManager $catalogBackup || exit 1\r
295             sed "s#^catalogs=\(.*\)\$#catalogs=$thisJavaXmlCatalog;\1;$etcXmlCatalog#" $catalogBackup \\r
296             | sed 's/;\+/;/' | sed 's/;$//' > $myCatalogManager || exit 1\r
297             emit_message "NOTE: Successfully updated the following file:"\r
298             emit_message "      $myCatalogManager"\r
299             emit_message "      Backup written to:"\r
300             emit_message "      $catalogBackup"\r
301           fi\r
302         else\r
303           mv $myCatalogManager $catalogBackup || exit 1\r
304           cp $catalogBackup $myCatalogManager\r
305           echo "catalogs=$thisJavaXmlCatalog;$etcXmlCatalog" \\r
306           | sed 's/;\+/;/' | sed 's/;$//' >> $myCatalogManager || exit 1\r
307           emit_message "NOTE: \"catalogs=\" line added to $myCatalogManager."\r
308           emit_message "      Backup written to $catalogBackup"\r
309         fi\r
310         ;;\r
311       esac\r
312       # end of backing up and updating CatalogManager.properties\r
313     fi\r
314   fi\r
315   # end of CatalogManager.properties updates\r
316 \r
317   if [ "$osName" = "Cygwin" ]; then\r
318     myCatalogManager=$(cygpath -m $myCatalogManager)\r
319   fi\r
320   return 0\r
321 }\r
322 \r
323 writeDotFiles() {\r
324   while read; do\r
325     echo "$REPLY" >> $mydir/.profile.incl\r
326   done <<EOF\r
327 # $thisBinDir is not in PATH, so add it\r
328 if [ "\${PATH#*$thisBinDir*}" = "\$PATH" ]; then\r
329   PATH="$thisBinDir:\$PATH"\r
330   export PATH\r
331 fi\r
332 if [ -z "\$XML_CATALOG_FILES" ]; then\r
333   XML_CATALOG_FILES="$thisXmlCatalog"\r
334 else\r
335   # $thisXmlCatalog is not in XML_CATALOG_FILES, so add it\r
336   if [ "\${XML_CATALOG_FILES#*$thisXmlCatalog*}" = "\$XML_CATALOG_FILES" ]; then\r
337     XML_CATALOG_FILES="$thisXmlCatalog \$XML_CATALOG_FILES"\r
338   fi\r
339 fi\r
340 # /etc/xml/catalog exists but is not in XML_CATALOG_FILES, so add it\r
341 if [ -f /etc/xml/catalog ] && \\r
342   [ "\${XML_CATALOG_FILES#*/etc/xml/catalog*}" = "\$XML_CATALOG_FILES" ]; then\r
343   XML_CATALOG_FILES="\$XML_CATALOG_FILES /etc/xml/catalog"\r
344 fi\r
345 export XML_CATALOG_FILES\r
346 \r
347 if [ -z "\$SGML_CATALOG_FILES" ]; then\r
348   SGML_CATALOG_FILES="$thisSgmlCatalog"\r
349 else\r
350   # $thisSgmlCatalog is not in SGML_CATALOG_FILES, so add it\r
351   if [ "\${SGML_CATALOG_FILES#*$thisSgmlCatalog}" = "\$SGML_CATALOG_FILES" ]; then\r
352     SGML_CATALOG_FILES="$thisSgmlCatalog:\$SGML_CATALOG_FILES"\r
353   fi\r
354 fi\r
355 # /etc/sgml/catalog exists but is not in SGML_CATALOG_FILES, so add it\r
356 if [ -f /etc/sgml/catalog ] && \\r
357   [ "\${SGML_CATALOG_FILES#*/etc/sgml/catalog*}" = "\$SGML_CATALOG_FILES" ]; then\r
358   SGML_CATALOG_FILES="\$SGML_CATALOG_FILES:/etc/sgml/catalog"\r
359 fi\r
360 export SGML_CATALOG_FILES\r
361 EOF\r
362 \r
363 while read; do\r
364   echo "$REPLY" >> $mydir/.cshrc.incl\r
365 done <<EOF\r
366 # $thisBinDir is not in PATH, so add it\r
367 if ( "\\\`echo \$PATH | grep -v $thisBinDir\\\`" != "" ) then\r
368   setenv PATH "$thisBinDir:\$PATH"\r
369 endif\r
370 if ( ! $\?XML_CATALOG_FILES ) then\r
371   setenv XML_CATALOG_FILES "$thisXmlCatalog"\r
372 # $thisXmlCatalog is not in XML_CATALOG_FILES, so add it\r
373 else if ( "\\\`echo \$XML_CATALOG_FILES | grep -v $thisXmlCatalog\\\`" != "" ) then\r
374   setenv XML_CATALOG_FILES "$thisXmlCatalog \$XML_CATALOG_FILES"\r
375 endif\r
376 endif\r
377 # /etc/xml/catalog exists but is not in XML_CATALOG_FILES, so add it\r
378 if ( -f /etc/xml/catalog && "\\\`echo \$XML_CATALOG_FILES | grep -v /etc/xml/catalog\\\`" != "" ) then\r
379   setenv XML_CATALOG_FILES "\$XML_CATALOG_FILES /etc/xml/catalog"\r
380 endif\r
381 \r
382 endif\r
383 if ( ! $\?SGML_CATALOG_FILES ) then\r
384   setenv SGML_CATALOG_FILES "$thisSgmlCatalog"\r
385 else if ( "\\\`echo \$SGML_CATALOG_FILES | grep -v $thisSgmlCatalog\\\`" != "" ) then\r
386   setenv SGML_CATALOG_FILES "$thisSgmlCatalog:\$SGML_CATALOG_FILES"\r
387 endif\r
388 endif\r
389 # /etc/SGML/catalog exists but is not in SGML_CATALOG_FILES, so add it\r
390 if ( -f /etc/sgml/catalog && "\\\`echo \$SGML_CATALOG_FILES | grep -v /etc/sgml/catalog\\\`" != "" ) then\r
391   setenv SGML_CATALOG_FILES {\$SGML_CATALOG_FILES}:/etc/sgml/catalog\r
392 endif\r
393 EOF\r
394 \r
395 if [ -n "$myCatalogManager" ]; then\r
396   myCatalogManagerDir=${myCatalogManager%/*}\r
397   while read; do\r
398     echo "$REPLY" >> $mydir/.profile.incl\r
399   done <<EOF\r
400 \r
401 \r
402 if [ -z "\$CLASSPATH" ]; then\r
403   CLASSPATH="$myCatalogManagerDir"\r
404 else\r
405   # $myCatalogManagerDir is not in CLASSPATH, so add it\r
406   if [ "\${CLASSPATH#*$myCatalogManagerDir*}" = "\$CLASSPATH" ]; then\r
407     CLASSPATH="$myCatalogManagerDir$classPathSeparator\$CLASSPATH"\r
408   fi\r
409 fi\r
410 export CLASSPATH\r
411 EOF\r
412 \r
413   while read; do\r
414     echo "$REPLY" >> $mydir/.cshrc.incl\r
415   done <<EOF\r
416 \r
417 \r
418 if ( ! $\?CLASSPATH ) then\r
419   setenv CLASSPATH "$myCatalogManagerDir"\r
420 # $myCatalogManagerDir is not in CLASSPATH, so add it\r
421 else if ( "\\\`echo \$CLASSPATH | grep -v $myCatalogManagerDir\\\`" != "" ) then\r
422   setenv CLASSPATH "$myCatalogManagerDir$classPathSeparator\$CLASSPATH"\r
423 endif\r
424 endif\r
425 EOF\r
426 \r
427 fi\r
428 \r
429 while read; do\r
430   echo "$REPLY" >> $mydir/.emacs.el\r
431 done <<EOF\r
432 (add-hook\r
433   'nxml-mode-hook\r
434   (lambda ()\r
435     (setq rng-schema-locating-files-default\r
436           (append '("$thisLocatingRules")\r
437                   rng-schema-locating-files-default ))))\r
438 EOF\r
439 \r
440 return 0\r
441 }\r
442 \r
443 updateUserStartupFiles() {\r
444   if [ ! "$batchmode" = "Yes" ]; then\r
445   cat 1>&2 <<EOF\r
446 \r
447 NOTE: To source your environment correctly for using the catalog\r
448       files in this distribution, you need to update one or more\r
449       of your shell startup files. This installer can\r
450       automatically make the necessary changes. Or, if you prefer,\r
451       you can make the changes manually.\r
452 \r
453 EOF\r
454   else\r
455     emit_message\r
456   fi\r
457 \r
458   # if running csh or tcsh, target .cshrc and .tcshrc files for\r
459   # update; otherwise, target .bash_* and .profiles\r
460 \r
461   parent=$(ps -p $PPID | grep "/")\r
462   if [ "${parent#*csh}" != "$parent" ] || [ "${parent#*tcsh}" != "$parent" ]; then\r
463     myStartupFiles=".cshrc .tcshrc"\r
464     appendLine="source $mydir/.cshrc.incl"\r
465   else\r
466     myStartupFiles=".bash_profile .bash_login .profile .bashrc"\r
467     appendLine=". $mydir/.profile.incl"\r
468   fi\r
469 \r
470   for file in $myStartupFiles; do\r
471     if [ -f "$HOME/$file" ]; then\r
472       dotFileBackup=$HOME/$file.$$.bak\r
473       REPLY=""\r
474       if [ ! "$batchmode" = "Yes" ]; then\r
475         read -s -n1 -p "Update $HOME/$file? [Yes] "\r
476         emit_message "$REPLY"\r
477       fi\r
478       case $REPLY in\r
479         [nNqQ])\r
480         cat 1>&2 <<EOF\r
481 \r
482 NOTE: No change made to $HOME/$file. You either need\r
483       to add the following line to it, or manually source\r
484       the shell environment for this distribution each\r
485       time you want use it.\r
486 \r
487 $appendLine\r
488 \r
489 EOF\r
490         ;;\r
491         *)\r
492         lineExists="$(grep "$appendLine" $HOME/$file )"\r
493         if [ ! "$lineExists" ]; then\r
494           mv $HOME/$file $dotFileBackup     || exit 1\r
495           cp $dotFileBackup $HOME/$file     || exit 1\r
496           echo "$appendLine" >> $HOME/$file || exit 1\r
497           cat 1>&2 <<EOF\r
498 NOTE: Successfully updated the following file:\r
499       $HOME/$file \r
500       Backup written to:\r
501       $dotFileBackup\r
502 \r
503 EOF\r
504         else\r
505           cat 1>&2 <<EOF\r
506 NOTE: The following file already contains information for this\r
507       distribution, so I did not update it.\r
508       $HOME/$file\r
509 \r
510 EOF\r
511         fi\r
512         ;;\r
513       esac\r
514     fi\r
515   done\r
516   if [ -z "$dotFileBackup" ]; then\r
517     if [ ! "$batchmode" = "Yes" ]; then\r
518       emit_message\r
519     fi\r
520     cat 1>&2 <<EOF\r
521 NOTE: No shell startup files updated. You can source the\r
522       environment for this distribution manually, each time you\r
523       want to use it, by typing the following.\r
524 \r
525 $appendLine\r
526 \r
527 EOF\r
528   fi\r
529 }\r
530 \r
531 updateUserDotEmacs() {\r
532   if [ -f $thisLocatingRules ]; then\r
533   cat 1>&2 <<EOF\r
534 \r
535 NOTE: This distribution includes a "schema locating rules" file\r
536       for Emacs/nXML.  To use it, you should update either your\r
537       .emacs or .emacs.el file.  This installer can automatically\r
538       make the necessary changes. Or, if you prefer, you can make\r
539       the changes manually.\r
540 \r
541 EOF\r
542 \r
543   emacsAppendLine="(load-file \"$mydir/.emacs.el\")"\r
544   myEmacsFile=\r
545   for file in .emacs .emacs.el; do\r
546     if [ -f "$HOME/$file" ]; then\r
547       myEmacsFile=$HOME/$file\r
548       break\r
549     fi\r
550   done\r
551   if [ ! -f "$myEmacsFile" ]; then\r
552     REPLY=""\r
553     if [ ! "$batchmode" = "Yes" ]; then\r
554       read -s -n1 -p "No .emacs or .emacs.el file. Create one? [No] "\r
555       emit_message "$REPLY"\r
556       emit_message\r
557     fi\r
558     case $REPLY in\r
559       [yY])\r
560       myEmacsFile=$HOME/.emacs\r
561       touch $myEmacsFile\r
562       ;;\r
563       *)\r
564       cat 1>&2 <<EOF\r
565 NOTE: No Emacs changes made. To use this distribution with,\r
566       Emacs/nXML, you can create a .emacs file and manually add\r
567       the following line to it, or you can run it as a command\r
568       within Emacs.\r
569 \r
570 $emacsAppendLine\r
571 \r
572 EOF\r
573       ;;\r
574     esac\r
575   fi\r
576   if [ -n "$myEmacsFile" ]; then\r
577     REPLY=""\r
578     if [ ! "$batchmode" = "Yes" ]; then\r
579       read -s -n1 -p  "Update $myEmacsFile? [Yes] "\r
580       emit_message "$REPLY"\r
581       emit_message\r
582     fi\r
583     case $REPLY in\r
584       [nNqQ])\r
585       cat 1>&2 <<EOF\r
586 \r
587 NOTE: No change made to $myEmacsFile. To use this distribution\r
588       with Emacs/nXML, you can manually add the following line\r
589       to your $myEmacsFile, or you can run it as a command\r
590       within Emacs.\r
591 \r
592 $emacsAppendLine\r
593 \r
594 EOF\r
595       ;;\r
596       *)\r
597       lineExists="$(grep "$emacsAppendLine" $myEmacsFile)"\r
598       if [ ! "$lineExists" ]; then\r
599         dotEmacsBackup=$myEmacsFile.$$.bak\r
600         mv $myEmacsFile $dotEmacsBackup    || exit 1\r
601         cp $dotEmacsBackup $myEmacsFile    || exit 1\r
602         echo "$emacsAppendLine" >> $myEmacsFile || exit 1\r
603         cat 1>&2 <<EOF\r
604 NOTE: Successfully updated the following file:\r
605       $myEmacsFile\r
606       Backup written to:\r
607       $dotEmacsBackup\r
608 EOF\r
609       else\r
610         cat 1>&2 <<EOF\r
611 \r
612 NOTE: The following file already contains information for this\r
613       distribution, so I did not update it.\r
614       $myEmacsFile\r
615 \r
616 EOF\r
617       fi\r
618       ;;\r
619     esac\r
620   fi\r
621 fi\r
622 }\r
623 \r
624 uninstall() {\r
625   if [ ! "$batchmode" = "Yes" ]; then\r
626   cat 1>&2 <<EOF\r
627 \r
628 NOTE: To "uninstall" this distribution, the changes made to your\r
629       CatalogManagers.properties, startup files, and/or .emacs\r
630       file need to be reverted. This uninstaller can automatically\r
631       revert them.  Or, if you prefer, you can revert them manually.\r
632 \r
633 EOF\r
634   fi\r
635 \r
636   if [ "$osName" = "Cygwin" ]; then\r
637     thisXmlCatalog=$thisJavaXmlCatalog\r
638   fi\r
639 \r
640   # make "escaped" version of PWD to use with sed and grep\r
641   escapedPwd=$(echo $mydir | sed "s#/#\\\\\/#g")\r
642 \r
643   # check to see if a non-empty value for catalogManager was fed\r
644   # to uninstaller.\r
645   if [ -n ${1#--catalogManager=} ]; then\r
646     myCatalogManager=${1#--catalogManager=}\r
647     catalogBackup="$myCatalogManager.$$.bak"\r
648     catalogsLine=$(grep "^catalogs=" $myCatalogManager)\r
649     if [ "$catalogsLine" ] ; then\r
650       if [ "${catalogsLine#*$thisXmlCatalog*}" != "$catalogsLine" ]; then\r
651         REPLY=""\r
652         if [ ! "$batchmode" = "Yes" ]; then\r
653           read -s -n1 -p "Revert $myCatalogManager? [Yes] "\r
654           emit_message "$REPLY"\r
655         fi\r
656         case $REPLY in\r
657           [nNqQ]*)\r
658           cat 1>&2 <<EOF\r
659 \r
660 NOTE: No change made to $myCatalogManager. You need to manually\r
661       remove the following path from the "catalog=" line.\r
662 \r
663           $thisXmlCatalog\r
664 \r
665 EOF\r
666           ;;\r
667           *)\r
668           mv $myCatalogManager $catalogBackup || exit 1\r
669           sed "s#^catalogs=\(.*\)$thisXmlCatalog\(.*\)\$#catalogs=\1\2#" $catalogBackup \\r
670           | sed 's/;\+/;/' | sed 's/;$//' | sed 's/=;/=/' > $myCatalogManager || exit 1\r
671           cat 1>&2 <<EOF\r
672 NOTE: Successfully updated the following file:\r
673       $myCatalogManager\r
674       Backup written to:\r
675       $catalogBackup\r
676 \r
677 EOF\r
678           ;;\r
679         esac\r
680       else\r
681         emit_message "NOTE: No data for this distribution found in:"\r
682         emit_message "       $myCatalogManager"\r
683         emit_message\r
684       fi\r
685     else\r
686       cat 1>&2 <<EOF\r
687 NOTE: No data for this distribution was found in the following\r
688       file, so I did not revert it.\r
689       $myCatalogManager\r
690 EOF\r
691     fi\r
692   fi\r
693 \r
694   if [ -n "$myEmacsFile" ]; then \r
695     # check to see if a non-empty value for --dotEmacs file was fed\r
696     # to uninstaller.\r
697     if [ -n ${2#--dotEmacs=} ]; then\r
698       myEmacsFile=${2#--dotEmacs=}\r
699       revertLine="(load-file \"$escapedPwd\/\.emacs\.el\")"\r
700       loadLine="$(grep "$revertLine" "$myEmacsFile")"\r
701       if [ -n "$loadLine" ]; then\r
702         emit_message\r
703         REPLY=""\r
704         if [ ! "$batchmode" = "Yes" ]; then\r
705           read -s -n1 -p "Revert $myEmacsFile? [Yes] "\r
706           emit_message "$REPLY"\r
707         fi\r
708         case $REPLY in\r
709           [nNqQ]*)\r
710           cat 1>&2 <<EOF\r
711 \r
712 NOTE: No change made to $myEmacsFile. You need to manually\r
713 remove the following line.\r
714 \r
715 (load-file \"$mydir/.emacs.el\")\r
716 \r
717 EOF\r
718           ;;\r
719           *)\r
720           dotEmacsBackup=$myEmacsFile.$$.bak\r
721           sed -e "/$revertLine/d" -i".$$.bak" $myEmacsFile  || exit 1\r
722           cat 1>&2 <<EOF\r
723 NOTE: successfully reverted the following file:\r
724       $myEmacsFile\r
725       Backup written to:\r
726       $dotEmacsBackup\r
727 \r
728 EOF\r
729           ;;\r
730         esac\r
731       else\r
732         emit_message "NOTE: No data for this distribution found in:"\r
733         emit_message "      $myEmacsFile"\r
734       fi\r
735     fi\r
736   fi\r
737 \r
738   # check all startup files\r
739   myStartupFiles=".bash_profile .bash_login .profile .bashrc .cshrc .tcshrc"\r
740   for file in $myStartupFiles; do\r
741     if [ -e "$HOME/$file" ]; then\r
742       case $file in\r
743         .tcshrc|.cshrc)\r
744         revertLine="source $mydir/.cshrc.incl"\r
745         revertLineEsc="source $escapedPwd\/\.cshrc\.incl"\r
746         ;;\r
747         *)\r
748         revertLine=". $mydir/.profile.incl"\r
749         revertLineEsc="\. $escapedPwd\/\.profile\.incl"\r
750         ;;\r
751       esac\r
752       lineExists="$(grep "$revertLineEsc" $HOME/$file )"\r
753       if [ "$lineExists" ]; then\r
754         REPLY=""\r
755         if [ ! "$batchmode" = "Yes" ]; then\r
756           read -s -n1 -p "Update $HOME/$file? [Yes] "\r
757           emit_message "$REPLY"\r
758         fi\r
759         case $REPLY in\r
760           [nNqQ]*)\r
761           cat 1>&2 <<EOF\r
762 \r
763 NOTE: No change made to $HOME/$file. You need to manually remove\r
764       the following line from it.\r
765 \r
766  $revertLine\r
767 \r
768 EOF\r
769           ;;\r
770           *)\r
771           dotFileBackup=$HOME/$file.$$.bak\r
772           sed -e "/$revertLineEsc/d" -i".$$.bak" $HOME/$file  || exit 1\r
773           cat 1>&2 <<EOF\r
774 NOTE: Successfully updated the following file:\r
775       $HOME/$file\r
776       Backup written to:\r
777       $dotFileBackup\r
778 \r
779 EOF\r
780           ;;\r
781         esac\r
782       else\r
783         emit_message "NOTE: No data for this distribution found in:"\r
784         emit_message "      $HOME/$file"\r
785         emit_message\r
786       fi\r
787     fi\r
788   done\r
789   removeOldFiles\r
790   emit_message "Done. Deleted uninstall.sh file."\r
791   rm -f $mydir/test.sh      || exit 1\r
792   rm -f $mydir/uninstall.sh || exit 1\r
793 }\r
794 \r
795 writeUninstallFile() {\r
796   uninstallFile=$mydir/uninstall.sh\r
797   echo '#!/bin/bash'                               > $uninstallFile || exit 1\r
798   echo 'mydir=$(cd -P $(dirname $0) && pwd -P)'   >> $uninstallFile || exit 1\r
799   echo "\$mydir/install.sh \\"                    >> $uninstallFile || exit 1\r
800   echo "  --uninstall \\"                         >> $uninstallFile || exit 1\r
801   echo "  --catalogManager=$myCatalogManager \\"  >> $uninstallFile || exit 1\r
802   echo "  --dotEmacs='$myEmacsFile' \\"           >> $uninstallFile || exit 1\r
803   echo '  $@'                                     >> $uninstallFile || exit 1\r
804   chmod 755 $uninstallFile || exit 1\r
805 }\r
806 \r
807 writeTestFile() {\r
808   testFile=$mydir/test.sh\r
809   echo "#!/bin/bash"                                > $testFile || exit 1\r
810   echo 'mydir=$(cd -P $(dirname $0) && pwd -P)'    >> $testFile || exit 1\r
811   echo '$mydir/install.sh --test'                  >> $testFile || exit 1\r
812   chmod 755 $testFile || exit 1\r
813 }\r
814 \r
815 printExitMessage() {\r
816   cat 1>&2 <<EOF\r
817 To source your shell environment for this distribution, type the\r
818 following:\r
819 \r
820 $appendLine\r
821 \r
822 EOF\r
823 }\r
824 \r
825 checkForResolver() {\r
826   resolverResponse="$(java org.apache.xml.resolver.apps.resolver uri -u foo 2>/dev/null)"\r
827   if [ -z "$resolverResponse" ]; then\r
828     cat 1>&2 <<EOF\r
829 \r
830 NOTE: Your environment does not seem to contain the Apache XML\r
831       Commons Resolver; without that, you can't use XML catalogs\r
832       with Java applications. For more information, see the "How\r
833       to use a catalog file" section in Bob Stayton's "DocBook\r
834       XSL: The Complete Guide"\r
835 \r
836       http://sagehill.net/docbookxsl/UseCatalog.html\r
837 \r
838 EOF\r
839   fi\r
840 }\r
841 \r
842 emitNoChangeMsg() {\r
843   cat 1>&2 <<EOF\r
844 \r
845 NOTE: No changes were made to CatalogManagers.properties. To\r
846       provide your Java tools with XML catalog information for\r
847       this distribution, you will need to make the appropriate\r
848       changes manually.\r
849 \r
850 EOF\r
851 }\r
852 \r
853 testCatalogs() {\r
854   if [ ! -f "$thisXmlCatalog" ]; then\r
855     cat 1>&2 <<EOF\r
856 \r
857 FATAL: $thisXmlCatalog file needed but not found. Stopping.\r
858 EOF\r
859   exit\r
860   fi\r
861 \r
862   if [ -z "$XML_CATALOG_FILES" ]; then\r
863     emit_message\r
864     emit_message "WARNING: XML_CATALOG_FILES not set. Not testing with xmlcatalog."\r
865   else\r
866     xmlCatalogResponse="$(xmlcatalog 2>/dev/null)"\r
867     if [ -z "$xmlCatalogResponse" ]; then\r
868     cat 1>&2 <<EOF\r
869 \r
870 WARNING: Cannot locate the "xmlcatalog" command. Make sure that\r
871          you have libxml2 and its associated utilities installed.\r
872 \r
873          http://xmlsoft.org/\r
874 \r
875 EOF\r
876     else\r
877       emit_message "Testing with xmlcatalog..."\r
878       # read in pathname-uri pairs from .urilist file\r
879       while read pair; do\r
880         if [ ! "${pair%* *}" = "." ]; then\r
881           path=$mydir/${pair%* *}\r
882         else\r
883           path=$mydir/\r
884         fi\r
885         uri=${pair#* *}\r
886         emit_message\r
887         emit_message "  Tested: $uri"\r
888         for catalog in $XML_CATALOG_FILES; do\r
889           response="$(xmlcatalog $catalog $uri| grep -v "No entry")"\r
890           if [ -n "$response" ]; then\r
891             if [ "$response" = "$path" ]; then\r
892               emit_message "  Result: $path"\r
893               break\r
894             else\r
895               emit_message "  Result: FAILED"\r
896             fi\r
897           fi\r
898         done\r
899       done < $mydir/.urilist\r
900     fi\r
901   fi\r
902 \r
903   if [ -z "$CLASSPATH" ]; then\r
904     emit_message\r
905     emit_message "NOTE: CLASSPATH not set. Not testing with Apache XML Commons Resolver."\r
906   else\r
907     if [ "$(checkForResolver)" ]; then\r
908       checkForResolver\r
909     else\r
910       emit_message\r
911       emit_message "Testing with Apache XML Commons Resolver..."\r
912       # read in pathname-uri pairs from .urilist file\r
913       while read pair; do\r
914         if [ ! "${pair%* *}" = "." ]; then\r
915           path=$mydir/${pair%* *}\r
916         else\r
917           path=$mydir/\r
918         fi\r
919         uri=${pair#* *}\r
920         emit_message\r
921         emit_message "  Tested: $uri"\r
922         if [ ${uri%.dtd} != $uri ]; then\r
923           response="$(java org.apache.xml.resolver.apps.resolver system -s $uri | grep "Result")"\r
924         else\r
925           response="$(java org.apache.xml.resolver.apps.resolver uri -u $uri | grep "Result")"\r
926         fi\r
927         if [ "$response" ]; then\r
928           if [ "${response#*$path}" != "$response" ]; then\r
929             emit_message "  Result: $path"\r
930           else\r
931             emit_message "  Result: FAILED"\r
932           fi\r
933           echo\r
934         fi\r
935       done < $mydir/.urilist\r
936     fi\r
937   fi\r
938 }\r
939 \r
940 # get opts and execute appropriate function\r
941 case $1 in\r
942   *-uninstall)\r
943   uninstall $2 $3 $4\r
944   ;;\r
945   *-test)\r
946   testCatalogs\r
947   ;;\r
948   *)\r
949   main\r
950   ;;\r
951 esac\r
952 \r
953 # Copyright\r
954 # ---------\r
955 # Copyright 2005-2007 Michael(tm) Smith <smith@sideshowbarker.net>\r
956\r
957 # Permission is hereby granted, free of charge, to any person\r
958 # obtaining a copy of this software and associated documentation\r
959 # files (the "Software"), to deal in the Software without\r
960 # restriction, including without limitation the rights to use, copy,\r
961 # modify, merge, publish, distribute, sublicense, and/or sell copies\r
962 # of the Software, and to permit persons to whom the Software is\r
963 # furnished to do so, subject to the following conditions:\r
964\r
965 # The above copyright notice and this permission notice shall be\r
966 # included in all copies or substantial portions of the Software.\r
967\r
968 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
969 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
970 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
971 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\r
972 # HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\r
973 # WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
974 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
975 # DEALINGS IN THE SOFTWARE.\r
976 \r
977 # vim: number\r