#!/bin/sh
# chkconfig: 2345 06 94
### BEGIN INIT INFO
# Provides:          hwclock
# Required-Start:    $local_fs modules
# Required-Stop:
# Should-Start:      
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Set system time on boot
# Description:       Set system time on boot
# X-Start-Before:
# X-Stop-After:
# X-Timesys-Start-Number:  06
# X-Timesys-Stop-Number:   94
### END INIT INFO

PATH=/usr/bin:/usr/sbin:/bin:/sbin

[ -n "$(which hwclock 2>/dev/null)" ] || exit 0

UTC=no

sync_opt=--hctosys
if [ -e /etc/timezone ]; then
  read TZ 2>/dev/null < /etc/timezone
  if [ -n "$TZ" ]; then
    export TZ
    sync_opt=--systz
  fi
fi

if [ "x$UTCx" = "xyesx" ]; then
  tz_opt=--utc
else
  tz_opt=--localtime
fi

case "$1" in
  start)
    echo -n "Setting timezone and system clock: "
    hwclock $sync_opt $tz_opt
    if [ $? != 0 ]; then
      echo "[Fail]"
    else
      echo "[OK]"
    fi
  ;;
  stop)
    echo -n "Syncing system time to hwclock: "
    hwclock --systohc
    if [ $? != 0 ]; then
      echo "[Fail]"
    else
      echo "[OK]"
    fi
  ;;
  *)
    echo "$0 [start|stop]"
  ;;
esac
