Add koha-foreach, a script to run a command for each Koha instance.
[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/debian.cnf <<eof
28 DROP USER 'koha_$name';
29 DROP DATABASE koha_$name;
30 FLUSH PRIVILEGES;
31 eof
32     
33     rm "/etc/apache2/sites-available/$name"
34     rm "/etc/koha/sites/$name/koha-conf.xml"
35     rm "/etc/koha/sites/$name/zebra-biblios.cfg"
36     rm "/etc/koha/sites/$name/zebra-authorities.cfg"
37     rm "/etc/koha/sites/$name/zebra-authorities-dom.cfg"
38     rm "/etc/koha/sites/$name/zebra.passwd"
39     rmdir "/etc/koha/sites/$name"
40     rm -r "/var/lock/koha/$name"
41     rm -r "/var/log/koha/$name"
42     rm -r "/var/run/koha/$name"
43     deluser --quiet "$name-koha"
44     a2dissite "$name"
45 done
46
47 service apache2 restart