+++ /dev/null
-#!/bin/bash\r
-# $Id: install.sh 7942 2008-03-26 06:08:08Z xmldoc $\r
-# $Source$ #\r
-\r
-# install.sh - Set up user environment for a XML/XSLT distribution\r
-\r
-# This is as an interactive installer for updating your\r
-# environment to use an XML/XSLT distribution such as the DocBook\r
-# XSL Stylesheets. Its main purpose is to configure your\r
-# environment with XML catalog data and schema "locating rules"\r
-# data provided in the XML/XSLT distribution.\r
-#\r
-# Although this installer was created for the DocBook project, it\r
-# is a general-purpose tool that can be used with any XML/XSLT\r
-# distribution that provides XML/SGML catalogs and locating rules.\r
-#\r
-# This script is mainly intended to make things easier for you if\r
-# you want to install a particular XML/XSLT distribution that has\r
-# not (yet) been packaged for your OS distro (Debian, Fedora,\r
-# whatever), or to use "snapshot" or development releases \r
-#\r
-# It works by updating your shell startup file (e.g., .bashrc and\r
-# .cshrc) and .emacs file and by finding or creating a writable\r
-# CatalogManager.properties file to update.\r
-#\r
-# It makes backup copies of any files it touches, and also\r
-# generates a uninstall.sh script for reverting its changes.\r
-#\r
-# In the same directory where it is located, it expects to find\r
-# the following four files:\r
-# - locatingrules.xml\r
-# - catalog.xml\r
-# - catalog\r
-# - .urilist\r
-# And if it's unable to locate a CatalogManager.properties file in\r
-# your environment, it expects to find an "example" one in the\r
-# same directory as itself, which it copies over to your\r
-# ~/.resolver directory.\r
-#\r
-# If the distribution contains any executables, change the value\r
-# of the thisBinDir to a colon-separated list of the pathnames of\r
-# the directories that contain those executables.\r
-\r
-# mydir is the "canonical" absolute pathname for install.sh\r
-mydir=$(cd -P $(dirname $0) && pwd -P) || exit 1\r
-\r
-thisLocatingRules=$mydir/locatingrules.xml\r
-thisXmlCatalog=$mydir/catalog.xml\r
-thisSgmlCatalog=$mydir/catalog\r
-\r
-# .urilist file contains a list of pairs of local pathnames and\r
-# URIs to test for catalog resolution\r
-thisUriList=$mydir/.urilist\r
-exampleCatalogManager=$mydir/.CatalogManager.properties.example\r
-thisCatalogManager=$HOME/.resolver/CatalogManager.properties\r
-\r
-# thisBinDir directory is a colon-separated list of the pathnames\r
-# to all directories that contain executables provided with the\r
-# distribution (for example, the DocBook XSL Stylesheets\r
-# distribution contains a "docbook-xsl-update" convenience script\r
-# for rsync'ing up to the latest docbook-xsl snapshot). The\r
-# install.sh script adds the value of thisBinDir to your PATH\r
-# environment variable\r
-thisBinDir=$mydir/tools/bin\r
-\r
-emit_message() {\r
- echo "$1" 1>&2\r
-}\r
-\r
-if [ ! "${*#--batch}" = "$*" ]; then\r
- batchmode="Yes";\r
-else\r
- batchmode="No";\r
- emit_message\r
- if [ ! "$1" = "--test" ]; then \r
- emit_message "NOTE: For non-interactive installs/uninstalls, use --batch"\r
- if [ ! "$1" = "--uninstall" ]; then\r
- emit_message\r
- fi\r
- fi\r
-fi\r
-\r
-osName="Unidentified"\r
-if uname -s | grep -qi "cygwin"; then\r
- osName="Cygwin"\r
-fi\r
-\r
-classPathSeparator=":"\r
-if [ "$osName" = "Cygwin" ]; then\r
- thisJavaXmlCatalog=$(cygpath -m $thisXmlCatalog)\r
- classPathSeparator=";"\r
-else\r
- thisJavaXmlCatalog=$thisXmlCatalog\r
-fi\r
-\r
-main() {\r
- removeOldFiles\r
- checkRoot\r
- updateCatalogManager\r
- checkForResolver\r
- writeDotFiles\r
- updateUserStartupFiles\r
- updateUserDotEmacs\r
- writeUninstallFile\r
- writeTestFile\r
- printExitMessage\r
-}\r
-\r
-removeOldFiles() {\r
- rm -f $mydir/.profile.incl\r
- rm -f $mydir/.cshrc.incl\r
- rm -f $mydir/.emacs.el\r
-}\r
-\r
-checkRoot() {\r
- if [ $(id -u) == "0" ]; then\r
- cat 1>&2 <<EOF\r
-\r
-WARNING: This install script is meant to be run as a non-root\r
- user, but you are running it as root.\r
-\r
-EOF\r
- read -s -n1 -p "Are you sure you want to continue? [No] "\r
- emit_message "$REPLY"\r
- case $REPLY in\r
- [yY])\r
- emit_message\r
- ;;\r
- *) emit_message "OK, exiting without making changes."\r
- exit\r
- ;;\r
- esac\r
- fi\r
- return 0\r
-}\r
-\r
-updateCatalogManager() {\r
-\r
- # - finds or creates a writable CatalogManager.properties file\r
- #\r
- # - adds the catalog.xml file for this distribution to the\r
- # CatalogManager.properties file found\r
-\r
- if [ -z "$CLASSPATH" ]; then\r
- cat 1>&2 <<EOF\r
-\r
-NOTE: There is no CLASSPATH variable set in your environment.\r
- No attempt was made to find a CatalogManager.properties\r
- file. Using $thisCatalogManager instead\r
-EOF\r
- else\r
- # split CLASSPATH in a list of pathnames by replacing all separator\r
- # characters with spaces\r
- if [ "$osName" = "Cygwin" ]; then\r
- pathnames=$(echo $CLASSPATH | tr ";" " ")\r
- else\r
- pathnames=$(echo $CLASSPATH | tr ":" " ")\r
- fi\r
- for path in $pathnames; do\r
- if [ "$osName" = "Cygwin" ]; then\r
- path=$(cygpath -u $path)\r
- fi\r
- # strip out trailing slash from pathname\r
- path=$(echo $path | sed 's/\/$//')\r
- # find CatalogManager.properties file\r
- if [ -f $path/CatalogManager.properties ];\r
- then\r
- existingCatalogManager=$path/CatalogManager.properties\r
- break\r
- fi\r
- done\r
- fi\r
- # end of CLASSPATH check\r
-\r
- if [ -w "$existingCatalogManager" ]; then\r
- # existing CatalogManager.properties was found and it is\r
- # writable, so use it\r
- myCatalogManager=$existingCatalogManager\r
- else\r
- if [ -f "$existingCatalogManager" ]; then\r
- # a non-writable CatalogManager.properties exists, so emit a\r
- # note saying that it won't be used\r
- cat 1>&2 <<EOF\r
-NOTE: $existingCatalogManager file found,\r
- but you don't have permission to write to it.\r
- Will instead use:\r
- $thisCatalogManager\r
-EOF\r
- else\r
- # CLASSPATH is set, but no CatalogManager.properties found\r
- if [ -n "$CLASSPATH" ]; then\r
- cat 1>&2 <<EOF\r
-NOTE: No CatalogManager.properties found from CLASSPATH.\r
- Will instead use:\r
- $thisCatalogManager\r
-EOF\r
- fi\r
- fi\r
- if [ "$batchmode" = "Yes" ]; then\r
- emit_message\r
- fi\r
- # end of check for existing writable CatalogManager.properties\r
-\r
- if [ -f $thisCatalogManager ]; then\r
- myCatalogManager=$thisCatalogManager\r
- else\r
- REPLY=""\r
- if [ ! "$batchmode" = "Yes" ]; then\r
- emit_message\r
- read -s -n1 -p "Create $thisCatalogManager file? [Yes] "\r
- emit_message "$REPLY"\r
- emit_message\r
- fi\r
- case $REPLY in\r
- [nNqQ])\r
- emitNoChangeMsg\r
- ;;\r
- *)\r
- if [ ! -d "${thisCatalogManager%/*}" ]; then\r
- mkdir -p ${thisCatalogManager%/*}\r
- fi\r
- cp $mydir/.CatalogManager.properties.example $thisCatalogManager || exit 1\r
- emit_message "NOTE: Created the following file:"\r
- emit_message " $thisCatalogManager"\r
- myCatalogManager=$thisCatalogManager\r
- ;;\r
- esac\r
- # end of creating "private" CatalogManager.properties\r
- fi\r
- # end of check for "private" CatalogManager.properties\r
- fi\r
- # end of check finding/creating writable CatalogManager.properties\r
-\r
- if [ -n "$myCatalogManager" ]; then\r
- etcXmlCatalog=\r
- catalogsLine=$(grep "^catalogs=" $myCatalogManager)\r
- if [ -f /etc/xml/catalog ] && [ "$osName" != "Cygwin" ] \\r
- && [ "${catalogsLine#*/etc/xml/catalog*}" = "$catalogsLine" ]; then\r
- cat 1>&2 <<EOF\r
-\r
-WARNING: /etc/xml/catalog exists but was not found in:\r
- $myCatalogManager\r
- If /etc/xml/catalog file has content, you probably\r
- should reference it in:\r
- $myCatalogManager\r
- This installer can automatically add it for you,\r
- but BE WARNED that once it has been added, the\r
- uninstaller for this distribution CANNOT REMOVE IT\r
- automatically during uninstall. If you no longer want\r
- it included, you will need to remove it manually.\r
-\r
-EOF\r
- REPLY=""\r
- if [ ! "$batchmode" = "Yes" ]; then\r
- read -s -n1 -p "Add /etc/xml/catalog to $myCatalogManager? [Yes] "\r
- emit_message "$REPLY"\r
- fi\r
- case $REPLY in\r
- [nNqQ])\r
- emit_message\r
- ;;\r
- *)\r
- etcXmlCatalog=/etc/xml/catalog\r
- ;;\r
- esac\r
- fi\r
-\r
- catalogBackup="$myCatalogManager.$$.bak"\r
- if [ ! -w "${myCatalogManager%/*}" ]; then\r
- emit_message\r
- emit_message "WARNING: ${myCatalogManager%/*} directory is not writable."\r
- emit_message\r
- emitNoChangeMsg\r
- else\r
- REPLY=""\r
- if [ ! "$batchmode" = "Yes" ]; then\r
- emit_message\r
- emit_message "Add $thisJavaXmlCatalog"\r
- read -s -n1 -p "to $myCatalogManager file? [Yes] "\r
- emit_message "$REPLY"\r
- emit_message\r
- fi\r
- case $REPLY in\r
- [nNqQ])\r
- emitNoChangeMsg\r
- ;;\r
- *)\r
- if [ "$catalogsLine" ] ; then\r
- if [ "${catalogsLine#*$thisJavaXmlCatalog*}" != "$catalogsLine" ]; then\r
- emit_message "NOTE: $thisJavaXmlCatalog"\r
- emit_message " already in:"\r
- emit_message " $myCatalogManager"\r
- else\r
- mv $myCatalogManager $catalogBackup || exit 1\r
- sed "s#^catalogs=\(.*\)\$#catalogs=$thisJavaXmlCatalog;\1;$etcXmlCatalog#" $catalogBackup \\r
- | sed 's/;\+/;/' | sed 's/;$//' > $myCatalogManager || exit 1\r
- emit_message "NOTE: Successfully updated the following file:"\r
- emit_message " $myCatalogManager"\r
- emit_message " Backup written to:"\r
- emit_message " $catalogBackup"\r
- fi\r
- else\r
- mv $myCatalogManager $catalogBackup || exit 1\r
- cp $catalogBackup $myCatalogManager\r
- echo "catalogs=$thisJavaXmlCatalog;$etcXmlCatalog" \\r
- | sed 's/;\+/;/' | sed 's/;$//' >> $myCatalogManager || exit 1\r
- emit_message "NOTE: \"catalogs=\" line added to $myCatalogManager."\r
- emit_message " Backup written to $catalogBackup"\r
- fi\r
- ;;\r
- esac\r
- # end of backing up and updating CatalogManager.properties\r
- fi\r
- fi\r
- # end of CatalogManager.properties updates\r
-\r
- if [ "$osName" = "Cygwin" ]; then\r
- myCatalogManager=$(cygpath -m $myCatalogManager)\r
- fi\r
- return 0\r
-}\r
-\r
-writeDotFiles() {\r
- while read; do\r
- echo "$REPLY" >> $mydir/.profile.incl\r
- done <<EOF\r
-# $thisBinDir is not in PATH, so add it\r
-if [ "\${PATH#*$thisBinDir*}" = "\$PATH" ]; then\r
- PATH="$thisBinDir:\$PATH"\r
- export PATH\r
-fi\r
-if [ -z "\$XML_CATALOG_FILES" ]; then\r
- XML_CATALOG_FILES="$thisXmlCatalog"\r
-else\r
- # $thisXmlCatalog is not in XML_CATALOG_FILES, so add it\r
- if [ "\${XML_CATALOG_FILES#*$thisXmlCatalog*}" = "\$XML_CATALOG_FILES" ]; then\r
- XML_CATALOG_FILES="$thisXmlCatalog \$XML_CATALOG_FILES"\r
- fi\r
-fi\r
-# /etc/xml/catalog exists but is not in XML_CATALOG_FILES, so add it\r
-if [ -f /etc/xml/catalog ] && \\r
- [ "\${XML_CATALOG_FILES#*/etc/xml/catalog*}" = "\$XML_CATALOG_FILES" ]; then\r
- XML_CATALOG_FILES="\$XML_CATALOG_FILES /etc/xml/catalog"\r
-fi\r
-export XML_CATALOG_FILES\r
-\r
-if [ -z "\$SGML_CATALOG_FILES" ]; then\r
- SGML_CATALOG_FILES="$thisSgmlCatalog"\r
-else\r
- # $thisSgmlCatalog is not in SGML_CATALOG_FILES, so add it\r
- if [ "\${SGML_CATALOG_FILES#*$thisSgmlCatalog}" = "\$SGML_CATALOG_FILES" ]; then\r
- SGML_CATALOG_FILES="$thisSgmlCatalog:\$SGML_CATALOG_FILES"\r
- fi\r
-fi\r
-# /etc/sgml/catalog exists but is not in SGML_CATALOG_FILES, so add it\r
-if [ -f /etc/sgml/catalog ] && \\r
- [ "\${SGML_CATALOG_FILES#*/etc/sgml/catalog*}" = "\$SGML_CATALOG_FILES" ]; then\r
- SGML_CATALOG_FILES="\$SGML_CATALOG_FILES:/etc/sgml/catalog"\r
-fi\r
-export SGML_CATALOG_FILES\r
-EOF\r
-\r
-while read; do\r
- echo "$REPLY" >> $mydir/.cshrc.incl\r
-done <<EOF\r
-# $thisBinDir is not in PATH, so add it\r
-if ( "\\\`echo \$PATH | grep -v $thisBinDir\\\`" != "" ) then\r
- setenv PATH "$thisBinDir:\$PATH"\r
-endif\r
-if ( ! $\?XML_CATALOG_FILES ) then\r
- setenv XML_CATALOG_FILES "$thisXmlCatalog"\r
-# $thisXmlCatalog is not in XML_CATALOG_FILES, so add it\r
-else if ( "\\\`echo \$XML_CATALOG_FILES | grep -v $thisXmlCatalog\\\`" != "" ) then\r
- setenv XML_CATALOG_FILES "$thisXmlCatalog \$XML_CATALOG_FILES"\r
-endif\r
-endif\r
-# /etc/xml/catalog exists but is not in XML_CATALOG_FILES, so add it\r
-if ( -f /etc/xml/catalog && "\\\`echo \$XML_CATALOG_FILES | grep -v /etc/xml/catalog\\\`" != "" ) then\r
- setenv XML_CATALOG_FILES "\$XML_CATALOG_FILES /etc/xml/catalog"\r
-endif\r
-\r
-endif\r
-if ( ! $\?SGML_CATALOG_FILES ) then\r
- setenv SGML_CATALOG_FILES "$thisSgmlCatalog"\r
-else if ( "\\\`echo \$SGML_CATALOG_FILES | grep -v $thisSgmlCatalog\\\`" != "" ) then\r
- setenv SGML_CATALOG_FILES "$thisSgmlCatalog:\$SGML_CATALOG_FILES"\r
-endif\r
-endif\r
-# /etc/SGML/catalog exists but is not in SGML_CATALOG_FILES, so add it\r
-if ( -f /etc/sgml/catalog && "\\\`echo \$SGML_CATALOG_FILES | grep -v /etc/sgml/catalog\\\`" != "" ) then\r
- setenv SGML_CATALOG_FILES {\$SGML_CATALOG_FILES}:/etc/sgml/catalog\r
-endif\r
-EOF\r
-\r
-if [ -n "$myCatalogManager" ]; then\r
- myCatalogManagerDir=${myCatalogManager%/*}\r
- while read; do\r
- echo "$REPLY" >> $mydir/.profile.incl\r
- done <<EOF\r
-\r
-\r
-if [ -z "\$CLASSPATH" ]; then\r
- CLASSPATH="$myCatalogManagerDir"\r
-else\r
- # $myCatalogManagerDir is not in CLASSPATH, so add it\r
- if [ "\${CLASSPATH#*$myCatalogManagerDir*}" = "\$CLASSPATH" ]; then\r
- CLASSPATH="$myCatalogManagerDir$classPathSeparator\$CLASSPATH"\r
- fi\r
-fi\r
-export CLASSPATH\r
-EOF\r
-\r
- while read; do\r
- echo "$REPLY" >> $mydir/.cshrc.incl\r
- done <<EOF\r
-\r
-\r
-if ( ! $\?CLASSPATH ) then\r
- setenv CLASSPATH "$myCatalogManagerDir"\r
-# $myCatalogManagerDir is not in CLASSPATH, so add it\r
-else if ( "\\\`echo \$CLASSPATH | grep -v $myCatalogManagerDir\\\`" != "" ) then\r
- setenv CLASSPATH "$myCatalogManagerDir$classPathSeparator\$CLASSPATH"\r
-endif\r
-endif\r
-EOF\r
-\r
-fi\r
-\r
-while read; do\r
- echo "$REPLY" >> $mydir/.emacs.el\r
-done <<EOF\r
-(add-hook\r
- 'nxml-mode-hook\r
- (lambda ()\r
- (setq rng-schema-locating-files-default\r
- (append '("$thisLocatingRules")\r
- rng-schema-locating-files-default ))))\r
-EOF\r
-\r
-return 0\r
-}\r
-\r
-updateUserStartupFiles() {\r
- if [ ! "$batchmode" = "Yes" ]; then\r
- cat 1>&2 <<EOF\r
-\r
-NOTE: To source your environment correctly for using the catalog\r
- files in this distribution, you need to update one or more\r
- of your shell startup files. This installer can\r
- automatically make the necessary changes. Or, if you prefer,\r
- you can make the changes manually.\r
-\r
-EOF\r
- else\r
- emit_message\r
- fi\r
-\r
- # if running csh or tcsh, target .cshrc and .tcshrc files for\r
- # update; otherwise, target .bash_* and .profiles\r
-\r
- parent=$(ps -p $PPID | grep "/")\r
- if [ "${parent#*csh}" != "$parent" ] || [ "${parent#*tcsh}" != "$parent" ]; then\r
- myStartupFiles=".cshrc .tcshrc"\r
- appendLine="source $mydir/.cshrc.incl"\r
- else\r
- myStartupFiles=".bash_profile .bash_login .profile .bashrc"\r
- appendLine=". $mydir/.profile.incl"\r
- fi\r
-\r
- for file in $myStartupFiles; do\r
- if [ -f "$HOME/$file" ]; then\r
- dotFileBackup=$HOME/$file.$$.bak\r
- REPLY=""\r
- if [ ! "$batchmode" = "Yes" ]; then\r
- read -s -n1 -p "Update $HOME/$file? [Yes] "\r
- emit_message "$REPLY"\r
- fi\r
- case $REPLY in\r
- [nNqQ])\r
- cat 1>&2 <<EOF\r
-\r
-NOTE: No change made to $HOME/$file. You either need\r
- to add the following line to it, or manually source\r
- the shell environment for this distribution each\r
- time you want use it.\r
-\r
-$appendLine\r
-\r
-EOF\r
- ;;\r
- *)\r
- lineExists="$(grep "$appendLine" $HOME/$file )"\r
- if [ ! "$lineExists" ]; then\r
- mv $HOME/$file $dotFileBackup || exit 1\r
- cp $dotFileBackup $HOME/$file || exit 1\r
- echo "$appendLine" >> $HOME/$file || exit 1\r
- cat 1>&2 <<EOF\r
-NOTE: Successfully updated the following file:\r
- $HOME/$file \r
- Backup written to:\r
- $dotFileBackup\r
-\r
-EOF\r
- else\r
- cat 1>&2 <<EOF\r
-NOTE: The following file already contains information for this\r
- distribution, so I did not update it.\r
- $HOME/$file\r
-\r
-EOF\r
- fi\r
- ;;\r
- esac\r
- fi\r
- done\r
- if [ -z "$dotFileBackup" ]; then\r
- if [ ! "$batchmode" = "Yes" ]; then\r
- emit_message\r
- fi\r
- cat 1>&2 <<EOF\r
-NOTE: No shell startup files updated. You can source the\r
- environment for this distribution manually, each time you\r
- want to use it, by typing the following.\r
-\r
-$appendLine\r
-\r
-EOF\r
- fi\r
-}\r
-\r
-updateUserDotEmacs() {\r
- if [ -f $thisLocatingRules ]; then\r
- cat 1>&2 <<EOF\r
-\r
-NOTE: This distribution includes a "schema locating rules" file\r
- for Emacs/nXML. To use it, you should update either your\r
- .emacs or .emacs.el file. This installer can automatically\r
- make the necessary changes. Or, if you prefer, you can make\r
- the changes manually.\r
-\r
-EOF\r
-\r
- emacsAppendLine="(load-file \"$mydir/.emacs.el\")"\r
- myEmacsFile=\r
- for file in .emacs .emacs.el; do\r
- if [ -f "$HOME/$file" ]; then\r
- myEmacsFile=$HOME/$file\r
- break\r
- fi\r
- done\r
- if [ ! -f "$myEmacsFile" ]; then\r
- REPLY=""\r
- if [ ! "$batchmode" = "Yes" ]; then\r
- read -s -n1 -p "No .emacs or .emacs.el file. Create one? [No] "\r
- emit_message "$REPLY"\r
- emit_message\r
- fi\r
- case $REPLY in\r
- [yY])\r
- myEmacsFile=$HOME/.emacs\r
- touch $myEmacsFile\r
- ;;\r
- *)\r
- cat 1>&2 <<EOF\r
-NOTE: No Emacs changes made. To use this distribution with,\r
- Emacs/nXML, you can create a .emacs file and manually add\r
- the following line to it, or you can run it as a command\r
- within Emacs.\r
-\r
-$emacsAppendLine\r
-\r
-EOF\r
- ;;\r
- esac\r
- fi\r
- if [ -n "$myEmacsFile" ]; then\r
- REPLY=""\r
- if [ ! "$batchmode" = "Yes" ]; then\r
- read -s -n1 -p "Update $myEmacsFile? [Yes] "\r
- emit_message "$REPLY"\r
- emit_message\r
- fi\r
- case $REPLY in\r
- [nNqQ])\r
- cat 1>&2 <<EOF\r
-\r
-NOTE: No change made to $myEmacsFile. To use this distribution\r
- with Emacs/nXML, you can manually add the following line\r
- to your $myEmacsFile, or you can run it as a command\r
- within Emacs.\r
-\r
-$emacsAppendLine\r
-\r
-EOF\r
- ;;\r
- *)\r
- lineExists="$(grep "$emacsAppendLine" $myEmacsFile)"\r
- if [ ! "$lineExists" ]; then\r
- dotEmacsBackup=$myEmacsFile.$$.bak\r
- mv $myEmacsFile $dotEmacsBackup || exit 1\r
- cp $dotEmacsBackup $myEmacsFile || exit 1\r
- echo "$emacsAppendLine" >> $myEmacsFile || exit 1\r
- cat 1>&2 <<EOF\r
-NOTE: Successfully updated the following file:\r
- $myEmacsFile\r
- Backup written to:\r
- $dotEmacsBackup\r
-EOF\r
- else\r
- cat 1>&2 <<EOF\r
-\r
-NOTE: The following file already contains information for this\r
- distribution, so I did not update it.\r
- $myEmacsFile\r
-\r
-EOF\r
- fi\r
- ;;\r
- esac\r
- fi\r
-fi\r
-}\r
-\r
-uninstall() {\r
- if [ ! "$batchmode" = "Yes" ]; then\r
- cat 1>&2 <<EOF\r
-\r
-NOTE: To "uninstall" this distribution, the changes made to your\r
- CatalogManagers.properties, startup files, and/or .emacs\r
- file need to be reverted. This uninstaller can automatically\r
- revert them. Or, if you prefer, you can revert them manually.\r
-\r
-EOF\r
- fi\r
-\r
- if [ "$osName" = "Cygwin" ]; then\r
- thisXmlCatalog=$thisJavaXmlCatalog\r
- fi\r
-\r
- # make "escaped" version of PWD to use with sed and grep\r
- escapedPwd=$(echo $mydir | sed "s#/#\\\\\/#g")\r
-\r
- # check to see if a non-empty value for catalogManager was fed\r
- # to uninstaller.\r
- if [ -n ${1#--catalogManager=} ]; then\r
- myCatalogManager=${1#--catalogManager=}\r
- catalogBackup="$myCatalogManager.$$.bak"\r
- catalogsLine=$(grep "^catalogs=" $myCatalogManager)\r
- if [ "$catalogsLine" ] ; then\r
- if [ "${catalogsLine#*$thisXmlCatalog*}" != "$catalogsLine" ]; then\r
- REPLY=""\r
- if [ ! "$batchmode" = "Yes" ]; then\r
- read -s -n1 -p "Revert $myCatalogManager? [Yes] "\r
- emit_message "$REPLY"\r
- fi\r
- case $REPLY in\r
- [nNqQ]*)\r
- cat 1>&2 <<EOF\r
-\r
-NOTE: No change made to $myCatalogManager. You need to manually\r
- remove the following path from the "catalog=" line.\r
-\r
- $thisXmlCatalog\r
-\r
-EOF\r
- ;;\r
- *)\r
- mv $myCatalogManager $catalogBackup || exit 1\r
- sed "s#^catalogs=\(.*\)$thisXmlCatalog\(.*\)\$#catalogs=\1\2#" $catalogBackup \\r
- | sed 's/;\+/;/' | sed 's/;$//' | sed 's/=;/=/' > $myCatalogManager || exit 1\r
- cat 1>&2 <<EOF\r
-NOTE: Successfully updated the following file:\r
- $myCatalogManager\r
- Backup written to:\r
- $catalogBackup\r
-\r
-EOF\r
- ;;\r
- esac\r
- else\r
- emit_message "NOTE: No data for this distribution found in:"\r
- emit_message " $myCatalogManager"\r
- emit_message\r
- fi\r
- else\r
- cat 1>&2 <<EOF\r
-NOTE: No data for this distribution was found in the following\r
- file, so I did not revert it.\r
- $myCatalogManager\r
-EOF\r
- fi\r
- fi\r
-\r
- if [ -n "$myEmacsFile" ]; then \r
- # check to see if a non-empty value for --dotEmacs file was fed\r
- # to uninstaller.\r
- if [ -n ${2#--dotEmacs=} ]; then\r
- myEmacsFile=${2#--dotEmacs=}\r
- revertLine="(load-file \"$escapedPwd\/\.emacs\.el\")"\r
- loadLine="$(grep "$revertLine" "$myEmacsFile")"\r
- if [ -n "$loadLine" ]; then\r
- emit_message\r
- REPLY=""\r
- if [ ! "$batchmode" = "Yes" ]; then\r
- read -s -n1 -p "Revert $myEmacsFile? [Yes] "\r
- emit_message "$REPLY"\r
- fi\r
- case $REPLY in\r
- [nNqQ]*)\r
- cat 1>&2 <<EOF\r
-\r
-NOTE: No change made to $myEmacsFile. You need to manually\r
-remove the following line.\r
-\r
-(load-file \"$mydir/.emacs.el\")\r
-\r
-EOF\r
- ;;\r
- *)\r
- dotEmacsBackup=$myEmacsFile.$$.bak\r
- sed -e "/$revertLine/d" -i".$$.bak" $myEmacsFile || exit 1\r
- cat 1>&2 <<EOF\r
-NOTE: successfully reverted the following file:\r
- $myEmacsFile\r
- Backup written to:\r
- $dotEmacsBackup\r
-\r
-EOF\r
- ;;\r
- esac\r
- else\r
- emit_message "NOTE: No data for this distribution found in:"\r
- emit_message " $myEmacsFile"\r
- fi\r
- fi\r
- fi\r
-\r
- # check all startup files\r
- myStartupFiles=".bash_profile .bash_login .profile .bashrc .cshrc .tcshrc"\r
- for file in $myStartupFiles; do\r
- if [ -e "$HOME/$file" ]; then\r
- case $file in\r
- .tcshrc|.cshrc)\r
- revertLine="source $mydir/.cshrc.incl"\r
- revertLineEsc="source $escapedPwd\/\.cshrc\.incl"\r
- ;;\r
- *)\r
- revertLine=". $mydir/.profile.incl"\r
- revertLineEsc="\. $escapedPwd\/\.profile\.incl"\r
- ;;\r
- esac\r
- lineExists="$(grep "$revertLineEsc" $HOME/$file )"\r
- if [ "$lineExists" ]; then\r
- REPLY=""\r
- if [ ! "$batchmode" = "Yes" ]; then\r
- read -s -n1 -p "Update $HOME/$file? [Yes] "\r
- emit_message "$REPLY"\r
- fi\r
- case $REPLY in\r
- [nNqQ]*)\r
- cat 1>&2 <<EOF\r
-\r
-NOTE: No change made to $HOME/$file. You need to manually remove\r
- the following line from it.\r
-\r
- $revertLine\r
-\r
-EOF\r
- ;;\r
- *)\r
- dotFileBackup=$HOME/$file.$$.bak\r
- sed -e "/$revertLineEsc/d" -i".$$.bak" $HOME/$file || exit 1\r
- cat 1>&2 <<EOF\r
-NOTE: Successfully updated the following file:\r
- $HOME/$file\r
- Backup written to:\r
- $dotFileBackup\r
-\r
-EOF\r
- ;;\r
- esac\r
- else\r
- emit_message "NOTE: No data for this distribution found in:"\r
- emit_message " $HOME/$file"\r
- emit_message\r
- fi\r
- fi\r
- done\r
- removeOldFiles\r
- emit_message "Done. Deleted uninstall.sh file."\r
- rm -f $mydir/test.sh || exit 1\r
- rm -f $mydir/uninstall.sh || exit 1\r
-}\r
-\r
-writeUninstallFile() {\r
- uninstallFile=$mydir/uninstall.sh\r
- echo '#!/bin/bash' > $uninstallFile || exit 1\r
- echo 'mydir=$(cd -P $(dirname $0) && pwd -P)' >> $uninstallFile || exit 1\r
- echo "\$mydir/install.sh \\" >> $uninstallFile || exit 1\r
- echo " --uninstall \\" >> $uninstallFile || exit 1\r
- echo " --catalogManager=$myCatalogManager \\" >> $uninstallFile || exit 1\r
- echo " --dotEmacs='$myEmacsFile' \\" >> $uninstallFile || exit 1\r
- echo ' $@' >> $uninstallFile || exit 1\r
- chmod 755 $uninstallFile || exit 1\r
-}\r
-\r
-writeTestFile() {\r
- testFile=$mydir/test.sh\r
- echo "#!/bin/bash" > $testFile || exit 1\r
- echo 'mydir=$(cd -P $(dirname $0) && pwd -P)' >> $testFile || exit 1\r
- echo '$mydir/install.sh --test' >> $testFile || exit 1\r
- chmod 755 $testFile || exit 1\r
-}\r
-\r
-printExitMessage() {\r
- cat 1>&2 <<EOF\r
-To source your shell environment for this distribution, type the\r
-following:\r
-\r
-$appendLine\r
-\r
-EOF\r
-}\r
-\r
-checkForResolver() {\r
- resolverResponse="$(java org.apache.xml.resolver.apps.resolver uri -u foo 2>/dev/null)"\r
- if [ -z "$resolverResponse" ]; then\r
- cat 1>&2 <<EOF\r
-\r
-NOTE: Your environment does not seem to contain the Apache XML\r
- Commons Resolver; without that, you can't use XML catalogs\r
- with Java applications. For more information, see the "How\r
- to use a catalog file" section in Bob Stayton's "DocBook\r
- XSL: The Complete Guide"\r
-\r
- http://sagehill.net/docbookxsl/UseCatalog.html\r
-\r
-EOF\r
- fi\r
-}\r
-\r
-emitNoChangeMsg() {\r
- cat 1>&2 <<EOF\r
-\r
-NOTE: No changes were made to CatalogManagers.properties. To\r
- provide your Java tools with XML catalog information for\r
- this distribution, you will need to make the appropriate\r
- changes manually.\r
-\r
-EOF\r
-}\r
-\r
-testCatalogs() {\r
- if [ ! -f "$thisXmlCatalog" ]; then\r
- cat 1>&2 <<EOF\r
-\r
-FATAL: $thisXmlCatalog file needed but not found. Stopping.\r
-EOF\r
- exit\r
- fi\r
-\r
- if [ -z "$XML_CATALOG_FILES" ]; then\r
- emit_message\r
- emit_message "WARNING: XML_CATALOG_FILES not set. Not testing with xmlcatalog."\r
- else\r
- xmlCatalogResponse="$(xmlcatalog 2>/dev/null)"\r
- if [ -z "$xmlCatalogResponse" ]; then\r
- cat 1>&2 <<EOF\r
-\r
-WARNING: Cannot locate the "xmlcatalog" command. Make sure that\r
- you have libxml2 and its associated utilities installed.\r
-\r
- http://xmlsoft.org/\r
-\r
-EOF\r
- else\r
- emit_message "Testing with xmlcatalog..."\r
- # read in pathname-uri pairs from .urilist file\r
- while read pair; do\r
- if [ ! "${pair%* *}" = "." ]; then\r
- path=$mydir/${pair%* *}\r
- else\r
- path=$mydir/\r
- fi\r
- uri=${pair#* *}\r
- emit_message\r
- emit_message " Tested: $uri"\r
- for catalog in $XML_CATALOG_FILES; do\r
- response="$(xmlcatalog $catalog $uri| grep -v "No entry")"\r
- if [ -n "$response" ]; then\r
- if [ "$response" = "$path" ]; then\r
- emit_message " Result: $path"\r
- break\r
- else\r
- emit_message " Result: FAILED"\r
- fi\r
- fi\r
- done\r
- done < $mydir/.urilist\r
- fi\r
- fi\r
-\r
- if [ -z "$CLASSPATH" ]; then\r
- emit_message\r
- emit_message "NOTE: CLASSPATH not set. Not testing with Apache XML Commons Resolver."\r
- else\r
- if [ "$(checkForResolver)" ]; then\r
- checkForResolver\r
- else\r
- emit_message\r
- emit_message "Testing with Apache XML Commons Resolver..."\r
- # read in pathname-uri pairs from .urilist file\r
- while read pair; do\r
- if [ ! "${pair%* *}" = "." ]; then\r
- path=$mydir/${pair%* *}\r
- else\r
- path=$mydir/\r
- fi\r
- uri=${pair#* *}\r
- emit_message\r
- emit_message " Tested: $uri"\r
- if [ ${uri%.dtd} != $uri ]; then\r
- response="$(java org.apache.xml.resolver.apps.resolver system -s $uri | grep "Result")"\r
- else\r
- response="$(java org.apache.xml.resolver.apps.resolver uri -u $uri | grep "Result")"\r
- fi\r
- if [ "$response" ]; then\r
- if [ "${response#*$path}" != "$response" ]; then\r
- emit_message " Result: $path"\r
- else\r
- emit_message " Result: FAILED"\r
- fi\r
- echo\r
- fi\r
- done < $mydir/.urilist\r
- fi\r
- fi\r
-}\r
-\r
-# get opts and execute appropriate function\r
-case $1 in\r
- *-uninstall)\r
- uninstall $2 $3 $4\r
- ;;\r
- *-test)\r
- testCatalogs\r
- ;;\r
- *)\r
- main\r
- ;;\r
-esac\r
-\r
-# Copyright\r
-# ---------\r
-# Copyright 2005-2007 Michael(tm) Smith <smith@sideshowbarker.net>\r
-# \r
-# Permission is hereby granted, free of charge, to any person\r
-# obtaining a copy of this software and associated documentation\r
-# files (the "Software"), to deal in the Software without\r
-# restriction, including without limitation the rights to use, copy,\r
-# modify, merge, publish, distribute, sublicense, and/or sell copies\r
-# of the Software, and to permit persons to whom the Software is\r
-# furnished to do so, subject to the following conditions:\r
-# \r
-# The above copyright notice and this permission notice shall be\r
-# included in all copies or substantial portions of the Software.\r
-# \r
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
-# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
-# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
-# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\r
-# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\r
-# WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\r
-# DEALINGS IN THE SOFTWARE.\r
-\r
-# vim: number\r