setclock 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/bin/sh
  2. ########################################################################
  3. # Begin setclock
  4. #
  5. # Description : Setting Linux Clock
  6. #
  7. # Authors : Gerard Beekmans - gerard@linuxfromscratch.org
  8. # DJ Lucas - dj@linuxfromscratch.org
  9. # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org
  10. #
  11. # Version : LFS 7.0
  12. #
  13. ########################################################################
  14. ### BEGIN INIT INFO
  15. # Provides:
  16. # Required-Start:
  17. # Should-Start: modules
  18. # Required-Stop:
  19. # Should-Stop: $syslog
  20. # Default-Start: S
  21. # Default-Stop:
  22. # Short-Description: Stores and restores time from the hardware clock
  23. # Description: On boot, system time is obtained from hwclock. The
  24. # hardware clock can also be set on shutdown.
  25. # X-LFS-Provided-By: LFS BLFS
  26. ### END INIT INFO
  27. . /etc/rc.d/functions
  28. [ -r /etc/sysconfig/clock ] && . /etc/sysconfig/clock
  29. case "${UTC}" in
  30. yes|true|1)
  31. CLOCKPARAMS="${CLOCKPARAMS} --utc"
  32. ;;
  33. no|false|0)
  34. CLOCKPARAMS="${CLOCKPARAMS} --localtime"
  35. ;;
  36. esac
  37. case ${1} in
  38. start)
  39. [ ! -z $TZ ] && TIMEZONE=$TZ
  40. [ ! -z $TIMEZONE ] && ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime
  41. hwclock --hctosys ${CLOCKPARAMS} >/dev/null
  42. ;;
  43. stop)
  44. log_info_msg "Setting hardware clock..."
  45. hwclock --systohc ${CLOCKPARAMS} >/dev/null
  46. evaluate_retval
  47. ;;
  48. *)
  49. echo "Usage: ${0} {start|stop}"
  50. exit 1
  51. ;;
  52. esac
  53. exit 0