:
#	@(#) asktime.sh 22.2 90/06/04 
#
#	Copyright (C) The Santa Cruz Operation, 1985, 1986, 1987, 1988, 1989.
#	This Module contains Proprietary Information of
#	The Santa Cruz Operation and Microsoft Corporation
#	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,
#	otherwise 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=`setclock`			reference comes from real-time clock
#	date $ref > /dev/null		sync system clock to real-time
#	read new			user override
#	date $new			...
#	setclock `date` > /dev/null	sync real-time clock to override
#
PATH=/bin:/usr/bin
DEFAULT=/etc/default/boot

trap "[ \"$rtc\" = yes ] && /etc/setclock `date +\%m\%d\%H\%M\%y` > /dev/null" 2

# If autobooting then timeout after 30 seconds
[ "$1" = -a ] && {
	timeout=`sed -n "/^TIMEOUT=[0-9]*$/s/TIMEOUT=//p" $DEFAULT`
	[ "$timeout" ] || timeout=30
}
rtc=no

grep "VERBOSE=NO" $DEFAULT > /dev/null 2>&1

# If we have a real-time clock, synchronize system clock to it.
cat /dev/clock > /dev/null 2>&1 && {
	rtc=yes
	date `/etc/setclock` > /dev/null
}

if [ $? -eq 0 -a `basename $0` = "asktimerc" ]
then
	echo "
Current System Time is `date`"
	[ "$rtc" = yes ] && /etc/setclock `date +\%m\%d\%H\%M\%y` > /dev/null
	exit
fi

# Start up a timeout daemon

[ "$timeout" ] && {
	[ $timeout -lt 2 ] && timeout=2
	(sleep $timeout; kill -14 $$) > /dev/null 2>&1 &
}

echo "\nCurrent System Time is `date`\nEnter new time ([yymmdd]hhmm): \c"
while	read date
	[ "$date" ]
do	date=`/lib/cvtdate $date` && date $date && break
	echo "Try again: \c"
done

[ "$rtc" = yes ] && /etc/setclock `date +\%m\%d\%H\%M\%y` > /dev/null

# Kill daemon before we exit, exec eliminates ``killed'' error message
[ "$timeout" ] && exec kill $! > /dev/null 2>&1
