bug 7001 follow-up fixing POD mistake
[koha_gimpoz] / debian / scripts / koha-remove
index 10a8b78..09720ea 100755 (executable)
 
 set -e
 
+args=$(getopt -l keep-mysql -o k -n $0 -- "$@")
+set -- $args
+while [ ! -z "$1" ]
+do
+    case "$1" in
+         -k|--keep-mysql) keepmysql=1; exit;;
+          *) break;;
+    esac
+    shift
+done
+
 
 for name in "$@"
 do
     echo "Removing Koha instance $name"
 
-    mysql --defaults-extra-file=/etc/mysql/koha-common.cnf <<eof
+    if [ "$keepmysql" != "1" ]
+    then
+        mysql --defaults-extra-file=/etc/mysql/koha-common.cnf <<eof
 DROP USER \`koha_$name\`;
 DROP DATABASE \`koha_$name\`;
 FLUSH PRIVILEGES;
 eof
+    fi #`
     
     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"
+    [ -f "/etc/apache2/sites-available/$name" ]  && \
+        rm "/etc/apache2/sites-available/$name"
+    [ -f "/etc/koha/sites/$name/koha-conf.xml" ] && \
+        rm "/etc/koha/sites/$name/koha-conf.xml"
+    [ -f "/etc/koha/sites/$name/zebra-biblios.cfg" ] && \
+        rm "/etc/koha/sites/$name/zebra-biblios.cfg"
+    [ -f "/etc/koha/sites/$name/zebra-authorities.cfg" ] && \
+        rm "/etc/koha/sites/$name/zebra-authorities.cfg"
+    [ -f "/etc/koha/sites/$name/zebra-authorities-dom.cfg" ] && \
+        rm "/etc/koha/sites/$name/zebra-authorities-dom.cfg"
+    [ -f "/etc/koha/sites/$name/zebra.passwd" ] && \
+        rm "/etc/koha/sites/$name/zebra.passwd"
+    [ -d "/etc/koha/sites/$name" ] && \
+        rmdir "/etc/koha/sites/$name"
+    [ -d "/var/lock/koha/$name" ] && \
+        rm -r "/var/lock/koha/$name"
+    [ -d "/var/log/koha/$name" ] && \
+        rm -r "/var/log/koha/$name"
+    [ -d "/var/run/koha/$name" ] && \
+        rm -r "/var/run/koha/$name"
+    getent passwd "$name-koha" > /dev/null && deluser --quiet "$name-koha"
     a2dissite "$name"
 done