Sophie

Sophie

distrib > Mandriva > 2009.1 > x86_64 > media > main-testing-src > by-pkgid > 2e17930c4e80264c4ae7ea6c81680a01 > files > 6

kolab-2.1.0-9.2mdv2009.1.src.rpm

#!/bin/bash

# (C) 2004 Jean-Michel Dault <jmdault@mandrakesoft.com>
# This program is Free Software under the GNU General Public License (>=v2).
# Read the file COPYING that comes with this packages for details.
# Reworked by Oden Eriksson <oeriksson@mandriva.com>
# $Id: kolab_bootstrap.sh 93049 2007-09-26 10:04:34Z oden $
# $HeadURL: svn+ssh://svn.mandriva.com/svn/packages/updates/2009.1/kolab/current/SOURCES/kolab_bootstrap.sh $

SERVICES="ldap saslauthd cyrus-imapd httpd proftpd freshclam clamd spamd amavisd postfix"
BACKUP_DIR="/etc/kolab/backup"
BACKUP_DATE="`date +%Y%m%d-%H%M%S`"
BACKUP_FILES="\
    /etc/amavisd/amavisd.conf \
    /etc/cyrus.conf \
    /etc/httpd/conf/vhosts.d/01_default_ssl_vhost.conf \
    /etc/imapd.conf \
    /etc/rc.d/init.d/ldap \
    /etc/openldap/slapd.conf \
    /etc/postfix/main.cf \
    /etc/postfix/master.cf \
    /etc/sasl2/smtpd.conf \
    /etc/postfix/transport \
    /etc/postfix/virtual \
    /etc/proftpd.conf \
    /etc/sysconfig/ldap \
    /etc/sysconfig/saslauthd \
"

show_usage()
{
    cat << EOF
Usage: kolab_bootstrap [OPTION]

Known values for OPTION are:

  -d, --debug         Configure the kolab server in debug mode
  -b, --bootstrap     Configure the kolab server
  -r, --restore       Restore original configuration files
  -h, --help          Print this help

  eg. kolab_bootstrap --debug --bootstrap

EOF
}

if test $# -eq 0; then
    show_usage
    exit 1
fi

flags=""
DEBUG=0

while test $# -gt 0; do

    case "$1" in

    --debug|-d)
	export DEBUG=1
    ;;

    --bootstrap|-b)

	mkdir -p $BACKUP_DIR

    	if ! [ -s /etc/kolab/backup/kolab_backup-orig.tar.gz ]; then
	    echo "Backuping config files to $BACKUP_DIR/kolab_backup-orig.tar.gz"
	    tar -cPf - $BACKUP_FILES | gzip -9 > $BACKUP_DIR/kolab_backup-orig.tar.gz
	else
	    echo "Backuping config files to $BACKUP_DIR/kolab_backup-$BACKUP_DATE.tar.gz"
	    tar -cPf - $BACKUP_FILES | gzip -9 > $BACKUP_DIR/kolab_backup-$BACKUP_DATE.tar.gz
	fi

	# i guess we could stop these from the real kolab_bootstrap script
	for s in $SERVICES; do
	    chkconfig --level 35 $s off
	    /etc/rc.d/init.d/$s stop >/dev/null 2>&1
	done
	
	SLURPD="`pidof slurpd`"
	if ! [ -z "$SLURPD" ]; then
	    echo "slurpd is running, it needs to be stopped..."
	    kill -9 $SLURPD
	fi

	# stop the kolab backend service
	/etc/rc.d/init.d/kolab stop >/dev/null 2>&1

	# call the real boot strapper

	if [ "$DEBUG" = "1" ]; then
	    if [ "`rpm -q perl-Devel-Trace >/dev/null; echo $?`" == "1" ]; then
		echo "the perl-Devel-Trace package is needed, trying to install it"
		urpmi perl-Devel-Trace
	    fi
	    perl -d:Trace /usr/share/kolab/scripts/kolab_bootstrap -b
	    RETVAL=$?
	    if [ $RETVAL -ne 0 ]; then exit 1; fi
	else
	    perl /usr/share/kolab/scripts/kolab_bootstrap -b
	    RETVAL=$?
	    if [ $RETVAL -ne 0 ]; then exit 1; fi
	fi
	touch /etc/kolab/.kolab2_configured

    exit 0
    ;;
    --restore|-r)

	if ! [ -f /etc/kolab/backup/kolab_backup-orig.tar.gz ]; then
	    echo "The $BACKUP_DIR/kolab_backup-orig.tar.gz file does not exist"
	    echo "No action taken"
	else
	    # stop the kolab backend service
	    /etc/rc.d/init.d/kolab stop >/dev/null 2>&1
	    chkconfig --level 35 kolab off

	    echo "Restoring original files from $BACKUP_DIR/kolab_backup-orig.tar.gz"
	    tar -zxvf $BACKUP_DIR/kolab_backup-orig.tar.gz
	
	    for s in $SERVICES; do
		echo "Resetting the $s service"
		chkconfig --add $s
	    done
	fi

    exit 0
    ;;
    --help|-h)
    show_usage
    exit 0
    ;;
    *)
    show_usage
    exit 1
    ;;
    esac

    # Next please.
    shift
done

exit 0