#!/bin/sh

functions()
	{
		SELFTMP=$0
		ORIGPWD=`pwd`
		REALPWD=`dirname $0`
		cd "$REALPWD"
		while [ -L "$SELFTMP" ]
			do
				SELFTMP=`readlink "$SELFTMP"`
				cd `dirname "$SELFTMP"`
				REALPWD=`pwd -P`
		done
		
		cd "$ORIGPWD"
		
		if [ "$INITIALIZED" != "1" ]
			then
				source $REALPWD/inc/functions.sh
		fi
	}
	
functions

apistorageswitch()
	{
		CMD="$1"
		SERVICENAME="$2"
		BACKENDNAME="$3"
		good ""
		getconfirm "Switch $SERVICENAME to $BACKENDNAME backend?" && (
			tool MODIFY SYSTEM $CMD && good "Switched $SERVICENAME to $BACKENDNAME backend successfuly " || bad "Switching $SERVICENAME to $BACKENDNAME backend problem!"
		) || warn "User cancelled"
		
		return 0

	}

spamstorageswitch()
	{
	TYPE=$1
	BACKEND=$2
	echo "SpamChallenge=$TYPE" >>$MERAKDIR/spam/spam.dat && good "Switched Challenge-reponse Storage to $BACKEND backend successfuly" || bad "Switching Challenge-response to $BACKEND backend problem!"
	return 0
	}

case `basename $0` in
        storageswitch-accounts-mysql)
                apistorageswitch "C_System_Storage_Accounts_StorageMode 2" "Account Storage" "MySQL"
		exit 0
		;;
        storageswitch-accounts-filesystem)
                apistorageswitch "C_System_Storage_Accounts_StorageMode 1" "Account Storage" "FileSystem"
		exit 0
		;;
        storageswitch-logging-mysql)
		apistorageswitch "C_System_Logging_General_EnableODBCLog 1" "Log Storage" "MySQL"
		exit 0
		;;
        storageswitch-logging-filesystem)
                apistorageswitch "C_System_Logging_General_EnableODBCLog 0" "Log Storage" "Filesystem"
		exit 0
		;;


esac

