#!/bin/sh
# ###############################################################
# Exceed Connection Server 2008
# Copyright (c) 1997-2008 Hummingbird Ltd. All Rights Reserved.
# ###############################################################
# ecsinstall
# $Revision: 10408 $
# ###############################################################
 

# bash script to create the file node.cfg.
# tries to make intelligent guesses about options and
# offers the user the option to change these guesses

# the name of the log file to append information into is the 
# only argument

. ./sys/msg.txt

logfile=$1

cd ..
rootdir=`pwd`"/"

pre="    "

infoscript="./ecsinfo"

sslmark="bin/openssl.cnf"
sslable="0"
sshcommand=
dspwd=
dshash=

getSSLInfo()
{
	if [ -r $sslmark ] ; then
		sslable="1"

		if [ -r "${rootdir}bin/sys/ssh" ] ; then
			sshcommand="${rootdir}bin/sys/ssh"
		fi
	fi

	pwdout=`bin/sys/keymgr --pwdgen`

	if [ ! -z "$pwdout" ] ; then
		for i in $pwdout
		do
			if [ -z "$dspwd" ] ; then
				dspwd=$i
			else
				dshash=$i
			fi
		done
	fi
}

usage()
{
	if [ "${logfile}xxxx" = "xxxx" ]; then
		${ECHO} ${pre}${USAGE}: $0 $LOGFILE_ARG
		exit 1
	fi
}

update_config_file_server_section()
{
	cat >> $config_file << EOF
[SERVER]
EoDSSHCommand=$sshcommand
EOF
}


update_config_file_common_section()
{
	cat >> $config_file << EOF
[COMMON]
EoDHomeDir=$rootdir
EoDSSLAvailable=$sslable
EoDDataStoreDir=
EoDDataStorePassword=$dspwd

EOF
}

update_cluster_file()
{
	cat >> "$cluster_file" << EOF
[CLUSTER]
EoDCMPassword=$dshash
EoDCMSSL=0
EoDCMLog=html
EoDCMDefXconfig=Passive.cfg
EoDCMAuth=native
EoDCMAuthPAMPwdPrompt=Password:
EoDCMPreferredPCM=
EoDLoadBalancing=cpu
EoDCMLogLevel=1
EoDCMLogRollSize=0
EoDCMLogRollTime=0
EodShowShareConfirmDialog=0

EOF
}

update_logfile()
{
	cat >> $logfile << EOF
$INFO $TTXPM_CREATING_FILE "node.cfg":
$INFO EoDServerLog=html
$INFO EoDSSHCommand=$sshcommand
$INFO EoDHomeDir=$rootdir
$INFO EoDSSLAvailable=$sslable
$INFO EoDDataStoreDir=
$INFO EoDDataStorePassword=$dspwd

EOF
}

updateConfigClusterLogFiles()
{
	update_config_file_common_section
	update_config_file_server_section

	update_cluster_file
	update_logfile
}

usage
getSSLInfo

cd bin

updateConfigClusterLogFiles

# exit with success
exit 0
