Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 137 lines (124 sloc) 3.817 kb
b963502 @dscape first working version
authored
1 #!/bin/bash
2 #
3 # Copyright 2010 Mark Logic Corporation. All Rights Reserved.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 # The use of the Apache License does not indicate that this project is
18 # affiliated with the Apache Software Foundation.
19 . /lib/lsb/init-functions
20 . /etc/sysconfig/MarkLogic
21 usage="Usage: $0 [OPTION]...
22 This script is to be used to uninstall apps that were installed using
23 ml-install
24
25 Options:
26 -D Turns debug on
27 -u Set the user
28 -p Set the password
29 -N Set the application name
30 -b Script (.xqy) to be run before the uninstaller is invoked
31 -a Script (.xqy) to be run after the uninstaller is invoked."
32
33 function debug_echo () {
34 if [ ! -z "$debug" ]; then
35 for line in "$@"
36 do
37 echo "$(date) - [MarkLogic] $line"
38 done
39 fi }
40
41 function debug_exec () {
42 if [ ! -z "$debug" ]; then
43 debug_echo "$1"
44 inst=&$1
45 else
46 inst=&$1 > /dev/null 2>&1
47 fi }
48
49 user=""
50 pass=""
51 appname=""
52 bxqy=""
53 axqy=""
54 debug=""
55
56 scriptpath=`cd $(dirname $0);pwd`
57 libname="lib-installer"
58 libfolder="$scriptpath/$libname"
59
60 while getopts "hu:p:N:b:a:l:D" opts
61 do case "$opts" in
62 l) libfolder="$OPTARG";;
63 u) user="$OPTARG";;
64 p) pass="$OPTARG";;
65 N) appname="$OPTARG";;
66 b) bxqy="$OPTARG";;
67 a) axqy="$OPTARG";;
68 D) debug="1";;
69 h) echo >&2 "$usage"
70 exit 1;;
71 ?) echo >&2 "$usage"
72 exit 1;;
73 esac
74 done
75
76 shift $(($OPTIND - 1))
77
78 if [ "$#" -ne 0 ]; then
79 echo "Wrong number of arguments"
80 echo $usage
81 exit 1
82 fi
83
84 if [ -z "$user" ]; then
85 echo -n "[MarkLogic] Username: "
86 read user > /dev/null 2>&1
87 fi
88 if [ -z "$pass" ]; then
89 echo -n "[MarkLogic] Password for $user: "
90 read -s pass > /dev/null 2>&1
91 echo
92 fi
93 if [ -z "$appname" ]; then
94 echo -n "[MarkLogic] Application Name: "
95 read appname > /dev/null 2>&1
96 fi
97
98 debug_echo "Lib Folder: $libfolder" \
99 "Lib Name: $libname" \
100 "Where is: $scriptpath" \
101 "User: $user" \
102 "Application Name: $appname" \
103 "Before Commit: $bxqy" \
104 "After Commit: $axqy"
105
106 instsysdir="$MARKLOGIC_INSTALL_DIR/Docs/$libname"
107 instappdir="$MARKLOGIC_INSTALL_DIR/Apps/usr"
108
109 echo "Lazy Panda is now un-installing app $appname"
110 echo " ( that makes him a sad panda )"
111 echo " . Registering the Installer with MarkLogic Server"
112 debug_exec "sudo rm -rf $instsysdir"
113 debug_exec "sudo cp -r $libfolder/ $instsysdir"
114 if [ ! -z "$bxqy" ]; then
115 echo " . Installing Pre-commit triggers ($bxqy)"
116 debug_exec "sudo cp $bxqy $instsysdir/hooks/uninstall/precommit.xqy"
117 fi
118 if [ ! -z "$axqy" ]; then
119 echo " . Installing Pos-commit triggers ($axqy)"
120 debug_exec "sudo cp $axqy $instsysdir/hooks/uninstall/poscommit.xqy"
121 fi
122 echo " . Un-registering the application with MarkLogic Server"
123 debug_exec "curl --anyauth http://$user:$pass@localhost:8000/$libname/uninstall.xqy?app=$appname"
124 # lazy way to avoi curl: (52) Empty reply from server
125 # this is a known bug.. needs investigation
126 # probably because server restarts after removing an appserver
127 sleep 10
128 debug_exec "curl --anyauth http://$user:$pass@localhost:8000/$libname/uninstall.xqy?app=$appname"
129 echo " . Taking a nap"
130 sleep 5
131 echo " . Removing the app from disk"
132 debug_exec "sudo rm -rf $instappdir/$appname"
133 echo " . Removing the installer from disk"
134 debug_exec "sudo rm -rf $instsysdir"
135 echo " . Installation Complete"
136 echo "The End! (panda says bye)"
Something went wrong with that request. Please try again.