3 # koha-remove -- Remove a Koha instance.
4 # Copyright 2010 Catalyst IT, Ltd
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.
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.
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/>.
22 args=$(getopt -l keep-mysql -o k -n $0 -- "$@")
27 -k|--keep-mysql) keepmysql=1; shift;;
36 SITECONFDIR="/etc/koha/sites"
37 # There has to be a better way of excluding '.' from find. But this works.
38 INSTANCES=`cd $SITECONFDIR && find . -type d -printf " %f" |sed s/\ .\ //`
40 if [ -z $NAMES ] ; then
41 echo "Please specify a Koha instance name. Your choices are:"
48 # Does the directory (ie instance) name exist?
49 if [ ! -d $SITECONFDIR/$name ] ; then
50 echo Koha configuration directory for instance \"$name\" does not exist, please specify a valid Koha instance
54 echo "Removing Koha instance $name"
56 if [ "$keepmysql" != "1" ]
58 # The grant creates the user in case it isn't, we don't want our loop to fail if it has already being deleted.
59 mysql --defaults-extra-file=/etc/mysql/koha-common.cnf <<eof
60 GRANT USAGE ON \`koha_$name\`.* TO \`koha_$name\`@\`%\`;
61 DROP USER \`koha_$name\`;
62 DROP DATABASE IF EXISTS \`koha_$name\`;
67 # If the daemon is not running already, we don't want to fail this loop. So bin the result code if this fails.
68 koha-stop-zebra $name | /bin/true
69 [ -f "/etc/apache2/sites-available/$name" ] && \
70 rm "/etc/apache2/sites-available/$name"
71 [ -f "/etc/koha/sites/$name/koha-conf.xml" ] && \
72 rm "/etc/koha/sites/$name/koha-conf.xml"
73 [ -f "/etc/koha/sites/$name/zebra-biblios.cfg" ] && \
74 rm "/etc/koha/sites/$name/zebra-biblios.cfg"
75 [ -f "/etc/koha/sites/$name/zebra-authorities.cfg" ] && \
76 rm "/etc/koha/sites/$name/zebra-authorities.cfg"
77 [ -f "/etc/koha/sites/$name/zebra-authorities-dom.cfg" ] && \
78 rm "/etc/koha/sites/$name/zebra-authorities-dom.cfg"
79 [ -f "/etc/koha/sites/$name/zebra.passwd" ] && \
80 rm "/etc/koha/sites/$name/zebra.passwd"
81 # Maybe a user has left something in the config directory they want to keep? We won't delete it here, nor throw an error if the have.
82 [ -d "/etc/koha/sites/$name" ] && \
83 rmdir --ignore-fail-on-non-empty "/etc/koha/sites/$name"
84 [ -d "/var/lock/koha/$name" ] && \
85 rm -r "/var/lock/koha/$name"
86 [ -d "/var/log/koha/$name" ] && \
87 rm -r "/var/log/koha/$name"
88 [ -d "/var/run/koha/$name" ] && \
89 rm -r "/var/run/koha/$name"
90 getent passwd "$name-koha" > /dev/null && deluser --quiet "$name-koha"
91 # in case the site has already been disabled, we don't want to break the loop now.
92 a2dissite "$name" | /bin/true
95 service apache2 restart