intradomain="$INTRAPREFIX$name$INTRASUFFIX$DOMAIN"
-if [ `cat $PASSWDFILE | grep "^$name:"` ]
+if [ -f $PASSWDFILE ] && [ `cat $PASSWDFILE | grep "^$name:"` ]
then
passwdline=`cat $PASSWDFILE | grep "^$name:"`
mysqluser=`echo $passwdline | cut -d ":" -f 2`
# Generate Zebra database password.
zebrapwd="$(pwgen -s 12 1)"
+ # Future enhancement: make this configurable for when your db is on
+ # another server.
+ mysql_hostname="localhost"
# Set up MySQL database for this instance.
if [ "$op" = create ]
then
mysql --defaults-extra-file=/etc/mysql/koha-common.cnf <<eof
CREATE DATABASE \`$mysqldb\`;
+CREATE USER \`$mysqluser\`@'$mysql_hostname' IDENTIFIED BY '$mysqlpwd';
CREATE USER \`$mysqluser\`@'%' IDENTIFIED BY '$mysqlpwd';
GRANT ALL PRIVILEGES ON \`$mysqldb\`.* TO \`$mysqluser\`;
FLUSH PRIVILEGES;
if [ "$op" = use ]
then
mysql --defaults-extra-file=/etc/mysql/koha-common.cnf --force <<eof
+CREATE USER \`$mysqluser\`@'$mysql_hostname' IDENTIFIED BY '$mysqlpwd';
CREATE USER \`$mysqluser\`@'%' IDENTIFIED BY '$mysqlpwd';
GRANT ALL PRIVILEGES ON \`$mysqldb\`.* TO \`$mysqluser\`;
FLUSH PRIVILEGES;
fi
echo "Removing Koha instance $name"
-
+ mysql_hostname="localhost"
if [ "$keepmysql" != "1" ]
then
# The grant creates the user in case it isn't, we don't want our loop to fail if it has already being deleted.
mysql --defaults-extra-file=/etc/mysql/koha-common.cnf <<eof
GRANT USAGE ON \`koha_$name\`.* TO \`koha_$name\`@\`%\`;
-DROP USER \`koha_$name\`;
+GRANT USAGE ON \`koha_$name\`.* TO \`koha_$name\`@\`$mysql_hostname\`;
+DROP USER \`koha_$name\`@\`%\`;
+DROP USER \`koha_$name\`@\`$mysql_hostname\`;
DROP DATABASE IF EXISTS \`koha_$name\`;
FLUSH PRIVILEGES;
eof
fi #`
# If the daemon is not running already, we don't want to fail this loop. So bin the result code if this fails.
- koha-stop-zebra $name | /bin/true
+ koha-stop-zebra $name || /bin/true
[ -f "/etc/apache2/sites-available/$name" ] && \
rm "/etc/apache2/sites-available/$name"
[ -f "/etc/koha/sites/$name/koha-conf.xml" ] && \
rm -r "/var/run/koha/$name"
getent passwd "$name-koha" > /dev/null && deluser --quiet "$name-koha"
# in case the site has already been disabled, we don't want to break the loop now.
- a2dissite "$name" | /bin/true
+ a2dissite "$name" || /bin/true
done
service apache2 restart