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: Brady Miller <brady@sparmy.com>
10 # Amalu Obinna <amaluobinna@aol.com>
12 # Un-install script steps:
13 # 1) Collect the MySQL root user password (mandatory)
14 # 2) Remove OpenEMR etc directory
15 # 3) Remove OpenEMR web directory
16 # 4) Remove OpenEMR MySQL database
17 # 5) Remove OpenEMR MySQL user
20 # summary of how this script can be called:
22 # * <old-prerm> `upgrade' <new-version>
23 # * <new-prerm> `failed-upgrade' <old-version>
24 # * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
25 # * <deconfigured's-prerm> `deconfigure' `in-favour'
26 # <package-being-installed> <version> `removing'
27 # <conflicting-package> <version>
28 # for details, see http://www.debian.org/doc/debian-policy/ or
29 # the debian-policy package
31 # Source debconf library.
32 .
/usr
/share
/debconf
/confmodule
38 LOGDIR
=/var
/log
/git-openemr
40 CONFIGDIR
=/etc
/git-openemr
41 CONFIG
=$CONFIGDIR/git-openemr.conf
43 OPENEMR
=$WEB/git-openemr
44 SITEDIR
=$OPENEMR/sites
/default
46 #Standardized echo function to send to only log file
47 # requires one parameter (string)
49 echo "`date`: $1" >> $LOG
52 #Standardized exit function to be used when unable to uninstall the
54 # requires one parameter (string with reason for exiting)
56 echo "`date`: $1" >> $LOG
57 echo "`date`: EXITING.........." >> $LOG
61 #function to check mysql for selected databases
62 # 1st param is password, 2nd param database, 3rd param is host (optional), 4th param is user (optional)
75 if [ "`mysql -u "$USE" -h "$HOST" --password="$1" -e 'show databases' 2>/dev/null | awk '{ print $1}' | grep "^
$2$
"`" == "$2" ]; then
82 #function to collect variables from config files
83 # 1st param is variable name, 2nd param is filename
85 echo `grep -i "^[[:space:]]*$1[[:space:]=]" $2 | cut -d \= -f 2 | cut -d \; -f 1 | sed "s/[ '\"]//gi"`
88 #function to prompt for input
89 # 1st param is name, 2nd param is priority, 3rd param is where result gets sent back in
93 db_fset
"$1" seen false
94 db_input
"$2" "$1" || true
97 local input_value
="$RET"
99 db_fset
"$1" seen false
101 eval $__result="'$input_value'"
104 #collect the mysql root password
106 if check_mysql
"$MPASS" "mysql"; then
107 log_only
"Passed the mysql check loop"
109 #the blank initial mysql password didn't work, so prompt for password
110 # (will give 3 chances to provide correct password)
113 prompt_input git-openemr
/mysql_p_remove_
${COUNTDOWN} critical ret_result
115 if check_mysql
"$MPASS" "mysql"; then
116 #the mysql root password works, so can exit loop
117 log_only
"Passed the mysql check loop"
120 #the mysql root password did not work
121 if [ "$COUNTDOWN" -ge "3" ]; then
122 prompt_input git-openemr
/unable_remove critical ret_result
123 unable_exit
"OpenEMR removal attempt failed (can try again when you know the mysql root password)"
130 #collect scripting information from config file
131 PROCESS
=$
(collect_var process
$CONFIG)
132 PLAN
=$
(collect_var plan
$CONFIG)
134 # Collect database information from sqlconf.php file
135 SQLLOCATION
=$
(collect_var \
$host $SITEDIR/sqlconf.php
)
136 SQLUSER
=$
(collect_var \
$login $SITEDIR/sqlconf.php
)
137 SQLPASSWORD
=$
(collect_var \
$pass $SITEDIR/sqlconf.php
)
138 SQLDATABASE
=$
(collect_var \
$dbase $SITEDIR/sqlconf.php
)
140 #remove etc directory
142 log_only
"Removed OpenEMR etc directory"
144 #remove web directory
146 log_only
"Finished removing OpenEMR web directory"
148 #remove openemr mysql database (ensure the database exists)
149 if check_mysql
"$MPASS" "$SQLDATABASE"; then
150 mysqladmin
-f -u root
-h "$SQLLOCATION" --password="$MPASS" drop
"$SQLDATABASE" >> $LOG 2>&1
151 log_only
"Removed OpenEMR MySQL database"
154 #remove openemr mysql user
155 mysql
-f -u root
-h "$SQLLOCATION" --password="$MPASS" -e "DELETE FROM mysql.user WHERE User = '$SQLUSER';FLUSH PRIVILEGES;" >> $LOG 2>&1
156 log_only
"Removed OpenEMR MySQL user"
158 #remove OpenEMR apache set up as active config
159 log_only
"Turn off apache conf for OpenEMR"
160 a2dissite git-openemr.conf
170 #echo "No need for upgrade instructions in prerm script to version $2"
176 echo "prerm asked to do deconfigure"
182 echo "prerm asked to do failed-upgrade from version $2"
187 echo "prerm called with unknown argument \`$1'" >&2