Newer
Older
Laurent Destailleur
committed
# postrm script for dolibarr
#
# see: dh_installdeb(1)
set -e
# summary of how this script can be called:
# * <postrm> `remove'
# * <postrm> `purge'
# * <old-postrm> `upgrade' <new-version>
# * <new-postrm> `failed-upgrade' <old-version>
# * <new-postrm> `abort-install'
# * <new-postrm> `abort-install' <old-version>
# * <new-postrm> `abort-upgrade' <old-version>
# * <disappearer's-postrm> `disappear' <r>overwrit>r> <new-version>
# for details, see /usr/share/doc/packaging-manual/
Laurent Destailleur
committed
. /usr/share/debconf/confmodule
Laurent Destailleur
committed
db_version 2.0
echo Run the dolibarr postrm script
Laurent Destailleur
committed
docdir='/var/lib/dolibarr/documents'
#docdir='/usr/share/dolibarr/documents'
export webserver=""
Laurent Destailleur
committed
# Allows us to loop and substitute in one pass
case $webserver in
Apache) webservers="apache2" ;;
Apache-SSL) webservers="apache2-ssl" ;;
Both) webservers="apache2 apache2-ssl" ;;
Laurent Destailleur
committed
esac
Laurent Destailleur
committed
Laurent Destailleur
committed
case "$1" in
Laurent Destailleur
committed
purge)
echo "postrm purge webservers=$webservers includefile=$includefile"
# Ask if we must delete database
echo "postrm db_input dolibarr/postrm"
db_input critical "dolibarr/postrm" || true
db_go || true
echo "postrm db_get dolibarr/postrm"
# We disable set -e to avoid premature end of script if error
set +e
Laurent Destailleur
committed
db_get "dolibarr/postrm"
Laurent Destailleur
committed
if [ "$RET" = "true" ] ; then
Laurent Destailleur
committed
# Get database configuration
#db_get "dolibarr/db/name"
#dbname="$RET"
superuserlogin=''
superuserpassword=''
if [ -f /etc/mysql/debian.cnf ] ; then
# Load superuser login and pass
superuserlogin=$(grep --max-count=1 "user" /etc/mysql/debian.cnf | sed -e 's/^user[ =]*//g')
superuserpassword=$(grep --max-count=1 "password" /etc/mysql/debian.cnf | sed -e 's/^password[ =]*//g')
fi
echo postrm Mysql superuser found to use is $superuserlogin
dbadmin="$superuserlogin"
dbadmpass="$superuserpassword"
Laurent Destailleur
committed
dbtype="mysql"
# To delete a mysql user (disabled)
# Needs: $dbuser - the user name to create (or replace).
# $dballow - what hosts to allow (defaults to %).
# $dbname - the database that user should have access to.
# $dbpass - the password to use.
# $dbserver - the server to connect to.
# $dbadmin - the administrator name.
# $dbadmpass - the administrator password.
# which
# mysql
# /usr/share/wwwconfig-coomon/mysql.get
#. /usr/share/wwwconfig-common/${dbtype}-dropuser.sh
# To delete database
# Needs: $dbname - the database that user should have access to.
# $dbserver - the server to connect to.
# $dbadmin - the administrator name.
# $dbadmpass - the administrator password.
# which
# mysql
# /usr/share/wwwconfig-common/mysql.get
echo "postrm Delete database $dbname on server $dbserver using account $dbadmin"
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# Define mysqlcmd
if [ -z "$dbserver" ] || [ "$dbserver" = "localhost" ]; then
hostopt=""
dbserver=localhost
else
case "$dbserver" in
:*)
dbsocket=`echo $dbserver | sed -e 's/^://'`
hostopt="-S $dbsocket"
;;
*)
hostopt="-h $dbserver"
;;
esac
fi
if [ -z "$dbadmpass" ] ; then
log="${log}No password used."
passopt=""
else
passopt="--password='"`echo "$dbadmpass" | sed -e "s/'/'"'"'"'"'"'"'/g"`"'"
fi
mysqlcmd="mysql $hostopt $passopt -u $dbadmin"
# Now run the drop commands
if eval $mysqlcmd -f -e "\"show databases;\"" | grep -e "^$dbname" > /dev/null 2>&1 ; then
log="${log}Droping database $dbname."
if eval $mysqlcmd -f -e "\"DROP DATABASE $dbname;\"" ; then
if eval $mysqlcmd -f -e "\"show databases;\"" | grep -e "^$dbname" > /dev/null 2>&1 ; then
error="Database $dbname NOT successfully droped. You have to do it manually."
echo $error
else
status=drop
fi
else
error="Unable to run the drop database script."
echo $error
fi
else
status=nothing
log="${log}Database $dbname already not exists."
fi
echo "Remove directory $docdir"
rm -rf $docdir ;
echo "postrm Delete of dolibarr database and uploaded files not wanted"
Laurent Destailleur
committed
fi
Laurent Destailleur
committed
for server in $webservers ; do
export conffile="/etc/$server/conf.d/dolibarr.conf"
if [ -f $conffile ] ;
then
Laurent Destailleur
committed
then restart="$restart $server"
fi
done
Laurent Destailleur
committed
# We disable blocking errors
set +e
echo "Restart server $server if exists"
if [ -x /usr/sbin/invoke-rc.d ]; then
invoke-rc.d $server reload || true
else
/etc/init.d/$server reload || true
fi
# We restore blocking errors
set -e
done
# Remove file and conf file
if [ -d $dir ] ; then
# We disable blocking errors
set +e
echo "Remove directory $dir"
rm -rf $dir ;
# We restore blocking errors
set -e
fi
Laurent Destailleur
committed
done
# We clean variable (we ignore errors because db_reset can fails if var was never set)
set +e
Laurent Destailleur
committed
;;
Laurent Destailleur
committed
remove)
echo "postrm Force remove of /usr/share/dolibarr/htdocs/install"
rm -fr /usr/share/dolibarr/htdocs/install
echo "postrm Force remove of /usr/share/dolibarr/htdocs/conf"
rm -fr /usr/share/dolibarr/htdocs/conf
# Remove include files
export restart=""
for server in $webservers ; do
export conffile="/etc/$server/conf.d/dolibarr.conf"
if [ -f $conffile ] ;
then
echo Delete file $conffile
rm -f $conffile
status=purge
fi
if [ "x$status" = "xpurge" ] ;
then restart="$restart $server"
fi
done
Laurent Destailleur
committed
;;
Laurent Destailleur
committed
upgrade)
;;
Laurent Destailleur
committed
failed-upgrade|abort-install|abort-upgrade|disappear)
;;
Laurent Destailleur
committed
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 0
;;
esac