#!/bin/ksh
#
# Component: commit
#
# Description:
#  Control script of component commit
#
# Last Updated     : $Author$
# Update Date Time : $Date$
# RCS File Name    : $RCSfile$
# RCS Revision     : $Revision$
# Locked by        : $Locker$
# Symbolic name    : $Name$
# State            : $State$

#--- INIT ------------------------------
#needs $HOME
. $HOME/etc/ctrl.main.shi

[ -f $HOME/etc/setenv.sh ] && . $HOME/etc/setenv.sh

#--- FUNC ------------------------------
do_shell_()
{
	cat <<-EndOfInlineData
		COMMIT_HOME=$HOME/component/commit
		COMMIT_VAR=\$VAR/commit
	EndOfInlineData
} #do_shell_()


do_crontab_()
{
	# Get time for starting update.sh from crontabSchedule settings
	[ -f "$CONF/crontabSchedule.shi" ] && . $CONF/crontabSchedule.shi
	[ -z "$CommitUpdate" ] && CommitUpdate="01-56/5 *"

	cat <<- EOI
		$CommitUpdate * * * $COMMIT_HOME/bin/update.sh >/dev/null 2>&1
	EOI
} #do_crontab_()


do_status_()
{
	echo "OK"
	exit

} #do_status_()

do_start_()
{
 	# check and create $COMMIT_VAR
 	[ ! -d "$COMMIT_VAR" ] && mkdir $COMMIT_VAR
 	[ ! -d "$COMMIT_VAR/transactions" ] && mkdir $COMMIT_VAR/transactions
 	[ ! -d "$COMMIT_VAR/flags" ] && mkdir $COMMIT_VAR/flags
	[ ! -d "$COMMIT_VAR/responses" ] && mkdir $COMMIT_VAR/responses

	[ ! -f "$COMMIT_VAR/commit.cfg" ] && cp $COMMIT_HOME/commit.cfg $COMMIT_VAR/commit.cfg
} #do_start_()


#
# List files/tables to be backed up grouped by categories
#
# output lines should be in '<category> <type> <names>' format
#
do_listbackup_()
{
	S_COMMIT_VAR=${COMMIT_VAR#$HOME/}
	cat <<-EOFLISTBACKUP
		data.commit FILE $S_COMMIT_VAR/transactions $S_COMMIT_VAR/flags $S_COMMIT_VAR/responses
		config.devices FILE $S_COMMIT_VAR/commit.cfg
	EOFLISTBACKUP
}

#--- MAIN ------------------------------

check_action_ $1
if [ 0 = $? ]; then
	do_$1_ $2

else
	echo "--- Component commit [ctrl $$]: Bad command: $1" >&2
	exit 1

fi
