Bug 6997: Koha-remove leaves system in inconsistent state
[koha.git] / debian / scripts / koha-remove
1 #!/bin/sh
2 #
3 # koha-remove -- Remove a Koha instance.
4 # Copyright 2010  Catalyst IT, Ltd
5
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 # GNU General Public License for more details.
15
16 # You should have received a copy of the GNU General Public License
17 # along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
19
20 set -e
21
22
23 for name in "$@"
24 do
25     echo "Removing Koha instance $name"
26
27     mysql --defaults-extra-file=/etc/mysql/koha-common.cnf <<eof
28 DROP USER \`koha_$name\`;
29 DROP DATABASE \`koha_$name\`;
30 FLUSH PRIVILEGES;
31 eof
32     
33     koha-stop-zebra $name
34     [ -f "/etc/apache2/sites-available/$name" ]  && \
35         rm "/etc/apache2/sites-available/$name"
36     [ -f "/etc/koha/sites/$name/koha-conf.xml" ] && \
37         rm "/etc/koha/sites/$name/koha-conf.xml"
38     [ -f "/etc/koha/sites/$name/zebra-biblios.cfg" ] && \
39         rm "/etc/koha/sites/$name/zebra-biblios.cfg"
40     [ -f "/etc/koha/sites/$name/zebra-authorities.cfg" ] && \
41         rm "/etc/koha/sites/$name/zebra-authorities.cfg"
42     [ -f "/etc/koha/sites/$name/zebra-authorities-dom.cfg" ] && \
43         rm "/etc/koha/sites/$name/zebra-authorities-dom.cfg"
44     [ -f "/etc/koha/sites/$name/zebra.passwd" ] && \
45         rm "/etc/koha/sites/$name/zebra.passwd"
46     [ -d "/etc/koha/sites/$name" ] && \
47         rmdir "/etc/koha/sites/$name"
48     [ -d "/var/lock/koha/$name" ] && \
49         rm -r "/var/lock/koha/$name"
50     [ -d "/var/log/koha/$name" ] && \
51         rm -r "/var/log/koha/$name"
52     [ -d "/var/run/koha/$name" ] && \
53         rm -r "/var/run/koha/$name"
54     getent passwd "$name-koha" > /dev/null && deluser --quiet "$name-koha"
55     a2dissite "$name"
56 done
57
58 service apache2 restart