:
#
#	@(#)asktime.sh	1.5 87/10/06 
#
#	Copyright (C) Microsoft Corporation, 1983
#
#	This Module contains Proprietary Information of Microsoft
#	Corporation and AT&T, and should be treated as Confidential.
#

#***	asktime -- prompt user for date and time, set things accordingly
#
#	If a real-time clock exists, it is used as the reference.  O.w.
#	the system clock is used.
#
#	We (silently) force the real-time clock and the system clock
#	to agree.  This is done even if the user does not change the
#	things from the reference.
#

#	The method is basically as follows (unfortunately shell script
#	limitations make the actual implementation rather convoluted):
#
#	'real-time clock'	means clock/calendar unaffected by power-downs,
#				etc.
#	'system clock'		means clock kept track of by kernel, initialized
#				at boot time from date on super-block.
#
#	ref=`date`			reference comes from real-time clock
#	date -s > /dev/null		sync system clock to real-time
#	read new			user override
#	date -c $new > /dev/null	sync real-time clock to override
#	date -s > /dev/null		sync system clock to real-time
#	exit 0

PATH=/bin:/usr/bin

# Figure out if we have a real-time clock.  If so, synchronize system clock
# to it.
rtc=FALSE
if [ -c /dev/clock -a -r /dev/clock ] ; then
	rtc=TRUE
	date -s > /dev/null
fi

# Reference
date=`date`
hour=`date +%H\%M`

echo "Current System Time is `date`"
echo  "Enter date (yymmdd) or press RETURN if ok: \c"
read date
echo  "Enter time   (hhmm) or press RETURN if ok: \c"
read time

if [ -z "$date$time" ] ; then
	exit 0
elif [ -z "$time" ]  ; then
	time=$hour
fi

if [ $rtc = TRUE ] ; then
	dateflag=-c
else
	dateflag=
fi

until date $dateflag `/lib/cvtdate $date$time 2>&1` 2>/dev/null ; do
	echo "\nTry again"
	echo  "Enter date (yymmdd) or press RETURN if ok: \c"
	read date
	echo  "Enter time   (hhmm) or press RETURN if ok: \c"
	read time
	if [ -z "$date$time" ] ; then
		exit 0
	elif [ -z "$time" ]  ; then
		time=$hour
	fi
done

if [ $rtc = TRUE ] ; then
	date -s > /dev/null
fi

exit 0
