install.sh 28 KB

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