#! /bin/sh 
# configure script for spip
#
# see: dh_installdeb(1)
#Based on cacti 0.6 config scripts
# Well thanks to acid for his help.

set -e
#set -x

. /usr/share/spip/bin/spip-configure.config

. /usr/share/spip/bin/spip.functions

	# Source debconf library
	. /usr/share/debconf/confmodule
	db_version 2.0

	get_config

	if [ "x$no_mysql" = "xfalse" ]
	then
		CNFFILE=`tempfile` || exit 1
		generate_mycnf
		mysqlcmd="mysql --defaults-file=$CNFFILE"

		if ! $mysqlcmd -B -e 'show databases;' > /dev/null 2>&1
		then
			echo "Spip is not configured due to wrong mysql hostname/credential"
			echo "Please run dpkg-reconfigure spip or remove /var/lib/spip/$site/ecrire/inc_connect.php3"
			rm -f $CNFFILE
			exit 0
		fi
			
	fi

	if [ ! -z " $instances_to_delete" ] ; then
		for site in $instances_to_delete ; do
			delete_spip_instance
			purge_spip_instance
		done
	fi
	if [ ! -z "$instances" ] ; then
		for site in $instances ; do
			create_spip_instance
		done
	fi

	db_set spip/instances_to_delete "" || true
	instances_to_delete=""

	server=apache
	servers=apache
	. /usr/share/wwwconfig-common/restart.sh

	db_stop
