3 #This program is free software; you can redistribute it and/or modify
4 #it under the terms of the GNU General Public License as published by
5 #the Free Software Foundation; either version 2 of the License, or
6 #(at your option) any later version.
9 # authors: Amalu Obinna <amaluobinna@aol.com>
10 # Brady Miller <brady.g.miller@gmail.com>
12 # Un-install script steps:
13 # 1) Warn and confirm the user wants to remove the package (mandatory)
14 # 2) Collect the MySQL root user password (mandatory)
15 # 3) Remove openemr MySQL database(s)
16 # 4) Remove openemr MySQL user(s)
17 # 5) Remove OpenEMR etc directory
18 # 6) Remove rest of OpenEMR web directory
19 # 7) Remove tmp directory
20 # 8) Remove OpenEMR apache configuration
23 # summary of how this script can be called:
25 # * <old-prerm> `upgrade' <new-version>
26 # * <new-prerm> `failed-upgrade' <old-version>
27 # * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
28 # * <deconfigured's-prerm> `deconfigure' `in-favour'
29 # <package-being-installed> <version> `removing'
30 # <conflicting-package> <version>
31 # for details, see http://www.debian.org/doc/debian-policy/ or
32 # the debian-policy package
34 # Source debconf library.
35 .
/usr
/share
/debconf
/confmodule
41 LOGDIR
=/var
/log
/openemr
43 CONFIGDIR
=/etc
/openemr
44 CONFIG
=$CONFIGDIR/openemr.conf
45 TMPDIR
=/tmp
/openemr-tmp
48 SITEDIR
=$OPENEMR/sites
50 #Standardized echo function to send to only log file
51 # requires one parameter (string)
53 echo "`date`: $1" >> $LOG
56 #Standardized exit function to be used when unable to uninstall the
58 # requires one parameter (string with reason for exiting)
60 echo "`date`: $1" >> $LOG
61 echo "`date`: EXITING.........." >> $LOG
65 #function to check mysql for selected databases
66 # 1st param is password, 2nd param database, 3rd param is host (optional), 4th param is user (optional)
79 if [ "`mysql -u "$USE" -h "$HOST" --password="$1" -e 'show databases' 2>/dev/null | awk '{ print $1}' | grep "^
$2$
"`" == "$2" ]; then
86 #function to collect variables from config files
87 # 1st param is variable name, 2nd param is filename
89 echo `grep -i "^[[:space:]]*$1[[:space:]=]" $2 | cut -d \= -f 2 | cut -d \; -f 1 | sed "s/[ '\"]//gi"`
92 #function to prompt for input
93 # 1st param is name, 2nd param is priority, 3rd param is where result gets sent back in
97 db_fset
"$1" seen false
98 db_input
"$2" "$1" || true
101 local input_value
="$RET"
103 db_fset
"$1" seen false
105 eval $__result="'$input_value'"
108 #Confirm that user really wants to uninstall
109 prompt_input openemr
/confirm_remove critical ret_result
110 if [ "$ret_result" == "no" ]; then
111 unable_exit
"You have chosen to not uninstall the OpenEMR package."
114 #collect the mysql root password
116 if check_mysql
"$MPASS" "mysql"; then
117 log_only
"Passed the mysql check loop"
119 #the blank initial mysql password didn't work, so prompt for password
120 # (will give 3 chances to provide correct password)
123 prompt_input openemr
/mysql_p_remove_
${COUNTDOWN} critical ret_result
125 if check_mysql
"$MPASS" "mysql"; then
126 #the mysql root password works, so can exit loop
127 log_only
"Passed the mysql check loop"
130 #the mysql root password did not work
131 if [ "$COUNTDOWN" -ge "3" ]; then
132 prompt_input openemr
/unable_remove critical ret_result
133 unable_exit
"OpenEMR removal attempt failed (can try again when you know the mysql root password)"
140 #collect scripting information from config file
141 PROCESS
=$
(collect_var process
$CONFIG)
142 PLAN
=$
(collect_var plan
$CONFIG)
144 for dir
in $
(find $SITEDIR/* -maxdepth 0 -type d
); do
146 SITENAME
=$
(basename "$dir")
148 # Collect database information from sqlconf.php file
149 SQLLOCATION
=$
(collect_var \
$host $SITEDIR/$SITENAME/sqlconf.php
)
150 SQLUSER
=$
(collect_var \
$login $SITEDIR/$SITENAME/sqlconf.php
)
151 SQLPASSWORD
=$
(collect_var \
$pass $SITEDIR/$SITENAME/sqlconf.php
)
152 SQLDATABASE
=$
(collect_var \
$dbase $SITEDIR/$SITENAME/sqlconf.php
)
154 #remove openemr mysql database (ensure the database exists)
155 if check_mysql
"$MPASS" "$SQLDATABASE"; then
156 mysqladmin
-f -u root
-h "$SQLLOCATION" --password="$MPASS" drop
"$SQLDATABASE" >> $LOG 2>&1
157 log_only
"Removed OpenEMR MySQL database: $SQLDATABASE"
160 #remove openemr mysql user
161 mysql
-f -u root
-h "$SQLLOCATION" --password="$MPASS" -e "DELETE FROM mysql.user WHERE User = '$SQLUSER';FLUSH PRIVILEGES;" >> $LOG 2>&1
162 log_only
"Removed OpenEMR MySQL user: $SQLUSER"
165 #remove etc directory
167 log_only
"Removed OpenEMR etc directory"
169 #remove rest of web directory
171 log_only
"Finished removing OpenEMR web directory"
173 #remove tmp directory
175 log_only
"Removed OpenEMR tmp directory"
177 #removes the configuration section for OpenEMR in Apache config file (deprecated, but keeping for older packages)
178 if [ -f /etc
/apache
2/httpd.conf
]; then
179 sed -i '/#This is the start of the Apache configuration for OpenEMR./,/#This is the end of the Apache configuration for OpenEMR./d' /etc
/apache
2/httpd.conf
180 log_only
"Removed OpenEMR Apache configuration in /etc/apache2/httpd.conf"
183 #remove OpenEMR apache set up as active config
184 log_only
"Turn off apache conf for OpenEMR"
185 a2dissite openemr.conf
195 #echo "No need for upgrade instructions in prerm script to version $2"
201 echo "prerm asked to do deconfigure"
207 echo "prerm asked to do failed-upgrade from version $2"
212 echo "prerm called with unknown argument \`$1'" >&2