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