# drtc_functions
#	This file contains functions to be used by most or all
#	shell scripts in the /opt/nec/drtc.
#
# COPYRIGHT (C) NEC CORPORATION 2010
# Rev.1

# Source function library.
. /opt/nec/hasdrtc/drtc_functions
[ -f /etc/hasdrtc.conf ] && . /etc/hasdrtc.conf

BIND_DELAY=${BIND_DELAY=300}
NR_BRETRY=${NR_BRETRY=50}
SLEEP_BRETRY=${SLEEP_BRETRY=10}
MESSAGE1=hasdrtc

function need_wait () {
	if [ $(($CYEAR  % 2)) -ne 0 -o $(($CYEAR / 10 % 2)) -ne 1 ]
	then
		return 1
	fi
	if [ "$CMONTH" != "02" ]
	then
		return 1
	fi
	if [ "$CDATE" != "28" -a "$CDATE" != "29" ]
	then
		return 1
	fi

	diff_seconds
	if ((BIND_DELAY < DIFFSECONDS))
	then
		return 1
	fi
	return 0
}

function wait_chdate () {
	/sbin/initlog -n hasdrtc -s "Wait for bind module."
	sleep $DIFFSECONDS
	drtc_exe -WRITE $NR_BRETRY $SLEEP_BRETRY
}

get_systime
need_wait && wait_chdate
