#!/bin/sh

# ClonePanel - Manages duplicate accounts on two or more webservers,
# including snapshot backups, monitoring and failover dns.
# Copyright (C)2006 Chris Cheers, Internet Lynx.
# Contact chris[at]clonepanel[dot]com.
# Internet Lynx, PO Box 7117, Mannering Park, NSW 2259, Australia

# 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; either version 2
# of the License, 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 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 02110-1301, USA.

Version=0.33
# includes runs a series of standard include files

# Initial setup of paths applicable to all
SYNC_DIR=$PROGRAM_DIR/..
# Main directory for clonepanel (program dir derived from script param $0)

SYSTEM_DIR=$SYNC_DIR/system
# System directory stores config files specific to individual installation

allcommands=(commands colours error_codes config)
# commands: allowable shell commands, colours: bash colour support,
# error_codes: standard exit codes, setup: common startup functions

quiet_mode='n'
# Quiet mode suppresses copyleft display - default off but can be overridden
# in config or individual scripts

if [ $# -gt 0 ]; then
	if [ "$1" != "init" ]; then
		allcommands[${#allcommands}]=setup
	fi
	if [ "$1" == "-q" ]; then
		quiet_mode='y'
	fi	
else
	allcommands[${#allcommands}]=setup
# Clumsy way to add setup command except in case of initial install
# TODO - clean up
fi

for config_file in ${allcommands[*]}
do
	for source_dir in $PROGRAM_DIR $SYSTEM_DIR
# default config files in program directory, override if required in system
	do
		if [ -f "$source_dir/$config_file" ]; then
			. $source_dir/$config_file
		fi
	done
done

# Convert SYNC_DIR and PROGRAM_DIR to absolute paths:
if [ "$PROGRAM_DIR" == "." ]; then
        PROGRAM_DIR=`/bin/pwd`
fi
SYNC_DIR=`$DIRNAME $PROGRAM_DIR`
PROGRAM_DIRNAME=`$BASENAME $PROGRAM_DIR`
SYNC_DIR=`cd $SYNC_DIR; /bin/pwd`
PROGRAM_DIR="$SYNC_DIR/$PROGRAM_DIRNAME"

if [ "$QUIET_MODE" == "y" ]; then
	quiet_mode='y'
fi
# local setting either from includes -q or config setting
if [ "$quiet_mode" != "y" ]; then
	cecho -c $info $COPYLEFT
fi

