#!/bin/bash

. /etc/rc.conf
. /etc/rc.d/functions

case $HARDWARECLOCK in
	UTC) HWCLOCK_PARAMS="--utc";;
	localtime) HWCLOCK_PARAMS="--localtime";;
	*) HWCLOCK_PARAMS="";;
esac

case "$1" in
	start)
		if [[ $HWCLOCK_PARAMS ]]; then
			status "Adjusting Hardware Clock" \
				/sbin/hwclock --adjust
			stat_busy "Setting System Clock"
			/sbin/hwclock --hctosys $HWCLOCK_PARAMS || stat_die
			stat_done
			# Note: This also enables /etc/cron.hourly/adjtime
			add_daemon hwclock
		fi
		;;
	stop)
		if [[ $HWCLOCK_PARAMS ]]; then
			stat_busy "Saving System Clock"
			/sbin/hwclock --systohc $HWCLOCK_PARAMS || stat_die
			stat_done
		fi
		rm_daemon hwclock
		;;
	restart)
		$0 stop
		sleep 1
		$0 start
		;;
	*)
		echo "usage: $0 {start|stop|restart}"
esac
