Advertisement
Guest User

Untitled

a guest
Jul 18th, 2014
183
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. # hwclock.sh Set and adjust the CMOS clock.
  3. #
  4. # Version: @(#)hwclock.sh 2.00 14-Dec-1998 miquels@cistron.nl
  5. #
  6. # Patches:
  7. # 2000-01-30 Henrique M. Holschuh <hmh@rcm.org.br>
  8. # - Minor cosmetic changes in an attempt to help new
  9. # users notice something IS changing their clocks
  10. # during startup/shutdown.
  11. # - Added comments to alert users of hwclock issues
  12. # and discourage tampering without proper doc reading.
  13. # 2012-02-16 Roger Leigh <rleigh@debian.org>
  14. # - Use the UTC/LOCAL setting in /etc/adjtime rather than
  15. # the UTC setting in /etc/default/rcS. Additionally
  16. # source /etc/default/hwclock to permit configuration.
  17.  
  18. # WARNING: Please read /usr/share/doc/util-linux/README.Debian.hwclock
  19. # before changing this file. You risk serious clock
  20. # misbehaviour otherwise.
  21.  
  22. ### BEGIN INIT INFO
  23. # Provides: hwclock
  24. # Required-Start: mountdevsubfs
  25. # Required-Stop: $local_fs
  26. # Default-Start: S
  27. # X-Start-Before: checkroot
  28. # Default-Stop: 0 6
  29. ### END INIT INFO
  30.  
  31. # These defaults are user-overridable in /etc/default/hwclock
  32. BADYEAR=no
  33. HWCLOCKACCESS=yes
  34. HWCLOCKPARS=
  35. HCTOSYS_DEVICE=rtc0
  36.  
  37. # We only want to use the system timezone or else we'll get
  38. # potential inconsistency at startup.
  39. unset TZ
  40.  
  41. hwclocksh()
  42. {
  43. [ ! -x /sbin/hwclock ] && return 0
  44. [ ! -r /etc/default/rcS ] || . /etc/default/rcS
  45. [ ! -r /etc/default/hwclock ] || . /etc/default/hwclock
  46.  
  47. . /lib/lsb/init-functions
  48. verbose_log_action_msg() { [ "$VERBOSE" = no ] || log_action_msg "$@"; }
  49.  
  50. case "$BADYEAR" in
  51. no|"") BADYEAR="" ;;
  52. yes) BADYEAR="--badyear" ;;
  53. *) log_action_msg "unknown BADYEAR setting: \"$BADYEAR\""; return 1 ;;
  54. esac
  55.  
  56. case "$1" in
  57. start)
  58. # If the admin deleted the hwclock config, create a blank
  59. # template with the defaults.
  60. if [ -w /etc ] && [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then
  61. printf "0.0 0 0.0\n0\nUTC" > /etc/adjtime
  62. fi
  63.  
  64. if [ -d /run/udev ] || [ -d /dev/.udev ]; then
  65. return 0
  66. fi
  67.  
  68. if [ "$HWCLOCKACCESS" != no ]; then
  69. log_action_msg "Setting the system clock"
  70.  
  71. # Just for reporting.
  72. if head -n 3 /etc/adjtime | tail -n 1 | grep -q '^UTC$' ; then
  73. UTC="--utc"
  74. else
  75. UTC=
  76. fi
  77. # Copies Hardware Clock time to System Clock using the correct
  78. # timezone for hardware clocks in local time, and sets kernel
  79. # timezone. DO NOT REMOVE.
  80. if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --hctosys $HWCLOCKPARS $BADYEAR; then
  81. # Announce the local time.
  82. verbose_log_action_msg "System Clock set to: `date $UTC`"
  83. else
  84. log_warning_msg "Unable to set System Clock to: `date $UTC`"
  85. fi
  86. else
  87. verbose_log_action_msg "Not setting System Clock"
  88. fi
  89. ;;
  90. stop|restart|reload|force-reload)
  91. #
  92. # Updates the Hardware Clock with the System Clock time.
  93. # This will *override* any changes made to the Hardware Clock.
  94. #
  95. # WARNING: If you disable this, any changes to the system
  96. # clock will not be carried across reboots.
  97. #
  98.  
  99. if [ "$HWCLOCKACCESS" != no ]; then
  100. log_action_msg "Saving the system clock"
  101. if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --systohc $HWCLOCKPARS $BADYEAR; then
  102. verbose_log_action_msg "Hardware Clock updated to `date`"
  103. fi
  104. else
  105. verbose_log_action_msg "Not saving System Clock"
  106. fi
  107. ;;
  108. show)
  109. if [ "$HWCLOCKACCESS" != no ]; then
  110. /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --show $HWCLOCKPARS $BADYEAR
  111. fi
  112. ;;
  113. *)
  114. log_success_msg "Usage: hwclock.sh {start|stop|reload|force-reload|show}"
  115. log_success_msg " start sets kernel (system) clock from hardware (RTC) clock"
  116. log_success_msg " stop and reload set hardware (RTC) clock from kernel (system) clock"
  117. return 1
  118. ;;
  119. esac
  120. }
  121.  
  122. hwclocksh "$@"
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement