[Patches] [PATCH] Patches to bugs 6684 6997 4880

koha-patchbot at kohaaloha.com koha-patchbot at kohaaloha.com
Mon Nov 21 12:45:05 NZDT 2011


From: Simon Story <simon.story at catalyst-eu.net>
Date: Fri, 18 Nov 2011 14:52:09 +0000
Subject: [PATCH] Patches to bugs 6684 6997 4880
 6684 koha-remove should check the number of arguments it gets
 6997 koha-remove leaves system in inconsistent state if there is an error
 4880 koha-remove sometimes fails because user is logged intkoha-remove sometimes fails because user is logged in

---
 debian/scripts/koha-remove |   54 +++++++++++++++++++++++++++++++------------
 1 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/debian/scripts/koha-remove b/debian/scripts/koha-remove
index 10a8b78..be91c8b 100755
--- a/debian/scripts/koha-remove
+++ b/debian/scripts/koha-remove
@@ -19,30 +19,54 @@
 
 set -e
 
+NAMES="$@"
 
-for name in "$@"
+SITECONFDIR="/etc/koha/sites"
+# There has to be a better way of excluding '.' from find. But this works.
+INSTANCES=`cd $SITECONFDIR && find . -type d -printf " %f" |sed s/\ .\ //`
+
+if [ -z $NAMES ] ; then
+    echo "Please specify a Koha instance name. Your choices are:"
+    echo "$INSTANCES"
+    exit 1
+fi
+
+for name in $NAMES
 do
+    # Does the directory (ie instance) name exist?
+    if [ ! -d $SITECONFDIR/$name ] ; then
+	echo Koha configuration directory for instance \"$name\" does not exist, please specify a valid Koha instance
+	exit 1
+    fi
+
     echo "Removing Koha instance $name"
 
+    # 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\`;
-DROP DATABASE \`koha_$name\`;
+DROP DATABASE IF EXISTS \`koha_$name\`;
 FLUSH PRIVILEGES;
 eof
     
-    koha-stop-zebra $name
-    rm "/etc/apache2/sites-available/$name"
-    rm "/etc/koha/sites/$name/koha-conf.xml"
-    rm "/etc/koha/sites/$name/zebra-biblios.cfg"
-    rm "/etc/koha/sites/$name/zebra-authorities.cfg"
-    rm "/etc/koha/sites/$name/zebra-authorities-dom.cfg"
-    rm "/etc/koha/sites/$name/zebra.passwd"
-    rmdir "/etc/koha/sites/$name"
-    rm -r "/var/lock/koha/$name"
-    rm -r "/var/log/koha/$name"
-    rm -r "/var/run/koha/$name"
-    deluser --quiet "$name-koha"
-    a2dissite "$name"
+    # 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
+    rm -f "/etc/apache2/sites-available/$name"
+    rm -f "$SITECONFDIR/$name/koha-conf.xml"
+    rm -f "$SITECONFDIR/$name/zebra-biblios.cfg"
+    rm -f "$SITECONFDIR/$name/zebra-authorities.cfg"
+    rm -f "$SITECONFDIR/$name/zebra-authorities-dom.cfg"
+    rm -f "$SITECONFDIR/$name/zebra.passwd"
+    # 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 they have.
+    rmdir --ignore-fail-on-non-empty "$SITECONFDIR/$name" 
+    rm -rf "/var/lock/koha/$name"
+    rm -rf "/var/log/koha/$name"
+    rm -rf "/var/run/koha/$name"
+    # Frequently warns about the mailspool dir. Sometimes the daemon has not stopped yet. So work around the non-zero result code.
+    echo "Deleting Koha user for $name"
+    userdel --force --remove "$name-koha" &> /dev/null | /bin/true
+    # in case the site has already been disabled, we don't want to break the loop now.
+    a2dissite "$name" | /bin/true
 done
 
 service apache2 restart
-- 
1.7.2.5




More information about the Patches mailing list