#!/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
# install -h for built-in documentation

set -u
# Be strict about variable declaration

unset PATH
#avoid use of $PATH - limit script to system commands we choose

PROGRAM_DIR=$(/bin/echo $0 |/bin/sed -e "s/\/[a-zA-Z0-9_]*$//")
# Extract the working directory from command line
# NB - if your system doesn't have echo and sed in these locations
# then this line will need to be changed in all shell scripts

# Run includes with the special option init to suppress calls to
# setup files that will fail  because setup is not yet done.

. $PROGRAM_DIR/includes init


# Built-in documentation:
function showdocs {
	$CAT <<-EODOC
		Initial installation / setup for a new ClonePanel backup system.
		./install and follow the prompts!
EODOC
	exit $DOC_REQUEST
}

# Start real script

# Check for help request and input variables in the command line options:
while getopts ":h" opt
do
	case $opt in
		h)	showdocs
			;;
		*)	$ECHO "Unknown option. Use -h for instructions"; exit $E_UNKNOWN_OPT
			;;
	esac
done
shift $(($OPTIND - 1))

OPTIND=1
# reset getopts for next time

if [ ! "$HOSTNAME" ]; then
	HOSTNAME='HOST'
fi

cecho -n -c $prompt "Enter a name to use for this host [$HOSTNAME] "
read myname

if [ ! "$myname" ]; then
	myname=$HOSTNAME
fi
# Fall back on hostname (if available) or HOST

def_remote_sync_dirname="cp$VERSION"
cecho -n -c $prompt "Enter a directory name for scripts and config on remote hosts [$def_remote_sync_dirname] "
read remote_sync_dirname
if [ ! "$remote_sync_dirname" ]; then
	remote_sync_dirname=$def_remote_sync_dirname
fi

cecho -n -c $prompt "Enter a directory name for database dump files on remote hosts [${remote_sync_dirname}_db] "
read remote_sync_dbname
if [ ! "$remote_sync_dbname" ]; then
	remote_sync_dbname="${remote_sync_dirname}_db"
fi

cecho -n -c $prompt "Enter an e-mail address for monitoring reports (blank for no e-mails) "
read error_report_email

cecho -c $info "Writing settings to $SYSTEM_DIR/config"

$CAT >$SYSTEM_DIR/config <<ENDCONFIG
MY_NAME='$myname'
REMOTEHOST_SYNC_DIRNAME='$remote_sync_dirname'
DATABASE_STORENAME='$remote_sync_dbname'
ERROR_REPORT_EMAIL='$error_report_email'
ENDCONFIG

$PROGRAM_DIR/server -H $myname add

cecho -c $ok "Install complete."













