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 # include helper functions
23 if [ -f "/usr/share/koha/bin/koha-functions.sh" ]; then
24 .
"/usr/share/koha/bin/koha-functions.sh"
26 echo "Error: /usr/share/koha/bin/koha-functions.sh not present." 1>&2
30 args
=$
(getopt
-l keep-mysql
-o k
-n $0 -- "$@")
35 -k|
--keep-mysql) keepmysql
=1; shift;;
44 SITECONFDIR
="/etc/koha/sites"
45 # There has to be a better way of excluding '.' from find. But this works.
46 INSTANCES
=$
(get_instances
)
48 if [ -z $NAMES ] ; then
49 echo "Please specify a Koha instance name. Your choices are:"
56 # Does the directory (ie instance) name exist?
57 if [ ! -d $SITECONFDIR/$name ] ; then
58 echo Koha configuration directory
for instance
\"$name\" does not exist
, please specify a valid Koha instance
62 echo "Removing Koha instance $name"
63 mysql_hostname
="localhost"
64 if [ "$keepmysql" != "1" ]
66 # The grant creates the user in case it isn't, we don't want our loop to fail if it has already being deleted.
67 mysql
--defaults-extra-file=/etc
/mysql
/koha-common.cnf
<<eof
68 GRANT USAGE ON \`koha_$name\`.* TO \`koha_$name\`@\`%\`;
69 GRANT USAGE ON \`koha_$name\`.* TO \`koha_$name\`@\`$mysql_hostname\`;
70 DROP USER \`koha_$name\`@\`%\`;
71 DROP USER \`koha_$name\`@\`$mysql_hostname\`;
72 DROP DATABASE IF EXISTS \`koha_$name\`;
77 # If the daemon is not running already, we don't want to fail this loop. So bin the result code if this fails.
78 koha-stop-zebra
$name ||
/bin
/true
80 instancefile
=$
(get_apache_config_for
$name)
82 [ -f "$instancefile" ] && \
84 [ -f "/etc/koha/sites/$name/koha-conf.xml" ] && \
85 rm "/etc/koha/sites/$name/koha-conf.xml"
86 [ -f "/etc/koha/sites/$name/zebra-biblios.cfg" ] && \
87 rm "/etc/koha/sites/$name/zebra-biblios.cfg"
88 [ -f "/etc/koha/sites/$name/zebra-biblios-dom.cfg" ] && \
89 rm "/etc/koha/sites/$name/zebra-biblios-dom.cfg"
90 [ -f "/etc/koha/sites/$name/zebra-authorities.cfg" ] && \
91 rm "/etc/koha/sites/$name/zebra-authorities.cfg"
92 [ -f "/etc/koha/sites/$name/zebra-authorities-dom.cfg" ] && \
93 rm "/etc/koha/sites/$name/zebra-authorities-dom.cfg"
94 [ -f "/etc/koha/sites/$name/zebra.passwd" ] && \
95 rm "/etc/koha/sites/$name/zebra.passwd"
96 # 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.
97 [ -d "/etc/koha/sites/$name" ] && \
98 rmdir --ignore-fail-on-non-empty "/etc/koha/sites/$name"
99 [ -d "/var/lock/koha/$name" ] && \
100 rm -r "/var/lock/koha/$name"
101 [ -d "/var/log/koha/$name" ] && \
102 rm -r "/var/log/koha/$name"
103 [ -d "/var/run/koha/$name" ] && \
104 rm -r "/var/run/koha/$name"
105 getent passwd
"$name-koha" > /dev
/null
&& deluser
--quiet "$name-koha"
106 # in case the site has already been disabled, we don't want to break the loop now.
107 a2dissite
"$name" > /dev
/null
2>&1 || a2dissite
"${name}.conf" > /dev
/null
2>&1 ||
/bin
/true
110 service apache2 restart