/
postrm
249 lines (218 loc) · 7.04 KB
/
postrm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/bin/sh
# 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/
. /usr/share/debconf/confmodule
db_version 2.0
echo Run the dolibarr postrm script
#echo "postrm db_get dolibarr/webserver"
# We disable set -e to avoid premature end of script if error
set +e
#db_get "dolibarr/webserver" || true
set -e
export webserver="$RET"
# 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" ;;
*) webservers="apache2 apache2-ssl" ;;
esac
export includefile=/etc/dolibarr/apache.conf
case "$1" in
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
db_get "dolibarr/postrm"
set -e
if [ "$RET" = "true" ] ; then
echo postrm Mysql database deletion
# Get database configuration
dbserver="localhost"
dbname="dolibarr"
#db_get "dolibarr/db/name"
#dbname="$RET"
superuserlogin=''
superuserpassword=''
if [ -f /etc/mysql/debian.cnf ] ; then
# Load superuser login and pass
superuserlogin=$(/bin/grep --max-count=1 "user" /etc/mysql/debian.cnf | /bin/sed -e 's/^user[ =]*//g')
superuserpassword=$(/bin/grep --max-count=1 "password" /etc/mysql/debian.cnf | /bin/sed -e 's/^password[ =]*//g')
fi
echo postrm Mysql superuser found to use is $superuserlogin
dbadmin="$superuserlogin"
dbadmpass="$superuserpassword"
#db_get "dolibarr/db/admin/name"
#dbadmin="$RET"
#db_get "dolibarr/db/admin/password"
#dbadmpass="$RET"
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"
# 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
else
echo "postrm Delete of dolibarr database not wanted"
fi
# Remove include files
for server in $webservers ; do
export error=""
export conffile="/etc/$server/httpd.conf"
echo "postrm conffile=$conffile"
if [ -f $conffile ] ;
then
if [ -s $conffile ] ;
then
echo postrm remove dolibarr include from /etc/dolibarr/apache.conf
# We disable set -e to avoid premature end of script if error
set +e
GREP="Include[[:space:]]\+$includefile\b"
if grep -e "$GREP" $conffile > /dev/null 2>&1; then
log="${log}Include of $includefile found in $conffile file, purging."
status=purge
grep -v -e "$GREP" < $conffile > $conffile.purg
mv $conffile.purg $conffile
fi
# We restore blocking errors
set -e
fi
fi
if [ "$status" = "purge" ] ;
then restart="$restart $server"
fi
done
rm -rf /etc/dolibarr
# Restart servers
servers="apache2-ssl apache2 mysql"
if [ -f /usr/share/wwwconfig-common/restart.sh ] ;
then
. /usr/share/wwwconfig-common/restart.sh
else
# Another way to restart
for server in $servers ; do
# 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
fi
# Remove file and conf file
for dir in /usr/share/dolibarr ; do
if [ -d $dir ] ; then
# We disable blocking errors
set +e
echo "Remove directory $dir"
rm -rf $dir ;
# We restore blocking errors
set -e
fi
done
# We clean variable (we ignore errors because db_reset can fails if var was never set)
set +e
db_reset "dolibarr/postrm"
set -e
db_purge
;;
remove)
echo "postrm Force remove of /usr/share/dolibarr/htdocs/install"
rm -fr /usr/share/dolibarr/htdocs/install
#echo "postrm Remove menu entry and image"
#fileorig="/usr/share/applications/dolibarr.desktop"
#rm -f $fileorig
#fileorig="/usr/share/pixmaps/dolibarr.xpm"
#rm -f $fileorig
# Not sure this is usefull
if test -x /usr/bin/update-menus; then update-menus; fi
;;
upgrade)
;;
failed-upgrade|abort-install|abort-upgrade|disappear)
;;
*)
echo "postrm called with unknown argument \`$1'" >&2
exit 0
;;
esac
db_stop
#DEBHELPER#
exit 0