File kolab-cleanup-and-start-over of Package kolab-scripts

#!/bin/bash
#
# Copyright 2013 Aeneas Jaissle <aj@ajaissle.de>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 3 or, at your option, any later version
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin street, Fifth Floor, Boston, MA 02111-1301, USA.
#

PATH=/usr/bin:/bin

[[ ! $(id -u) ]] && {
  echo "This program must be run as root" >&2
  exit 1
}

echo "
Warning: This script will remove all Kolab components including config, IMAP store, LDAP and database from your system. These components include
  - All Kolab packages
    - Kolab meta packages (kolab, kolab-conf, kolab-imap, kolab-ldap, kolab-mta) 
    - kolab-freebusy
    - kolab-schema
    - kolab-syncroton
    - kolab-utils
    - kolab-webadmin
    - kolab-webclient
    - pykolab and all sub-packages (kolab-cli, kolab-saslauth, kolab-server, postfix-kolab, wallace)
  - apache2 (even instances not used by Kolab!)
  - 389-ds and all related packages (389-admin etc.)
  - Cyrus IMAP
  - Sieve
  - Postfix
  - amavisd-new, ClamAV
  - roundcubemail and installed plugins
  - mysql-server (mariadb) databases
  - SSL servercerts, CA etc.

It is recommended to only call this script on a clean server that is not yet running any live services. Also it is strongly recommended to backup all data you might want to use again (eg. a prepared kolab.conf).

There will be no backups made by this script!"
read -p "Do you want to erase all Kolab related data and start over? [y/N] " CONFIRM1
if [[ $CONFIRM1 == [Yy] ]] ; then
    echo "Please confirm your choice to remove all stored Kolab components AND remove all data."
    read -p "Please type the following to confirm your choice: [DELETE] " CONFIRM2
    if [[ $CONFIRM2 == 'DELETE' ]] ; then
        echo "    Removing packages..."
        systemctl stop apache2 kolabd kolab-saslauthd wallace cyrus-imapd mysql postfix amavisd clamd dirsrv.target
        zypper rm `rpm -qa "*kolab*" | grep '^[^lib]'` apache2 389* cyrus-imapd *managesieve* postfix roundcubemail* amavisd-new clamav
        echo "    Removing config and data files..."
        rm -rvf \
            /etc/amavisd.conf \
            /etc/clam*.conf \
            /etc/cyrus.conf \
            /etc/imapd.* \
            /etc/dirsrv/ \
            /etc/kolab/ \
            /etc/postfix/ \
            /etc/ssl/serial* \
            /etc/ssl/index* \
            /etc/ssl/private/ \
            /etc/ssl/servercerts/ \
            /usr/lib*/dirsrv/ \
            /usr/share/dirsrv/ \
            /var/cache/dirsrv/ \
            /var/cache/kolab-webadmin/ \
            /var/lib/clamav/ \
            /var/lib/kolab/ \
            /var/lib/kolab-freebusy/ \
            /var/lib/mysql/ \
            /var/lib/apache2/ \
            /var/lib/imap/ \
            /var/lib/sieve/ \
            /var/lib/postfix/ \
            /var/lib/roundcubemail/ \
            /var/spool/amavis/ \
            /var/spool/imap/ \
            /var/spool/postfix/ \
            /var/spool/pykolab/ \
            /srv/www/roundcubemail/
    else
        echo "Input does not match, aborting the script. No components were removed."
    fi
else
    echo "Aborting. No components were removed."
fi