home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / etc / init.d / hwclock.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2009-02-18  |  5.1 KB  |  172 lines

  1. #!/bin/sh
  2. # hwclock.sh    Set and adjust the CMOS clock, according to the UTC
  3. #        setting in /etc/default/rcS (see also rcS(5)).
  4. #
  5. # Version:    @(#)hwclock.sh  2.00  14-Dec-1998  miquels@cistron.nl
  6. #
  7. # Patches:
  8. #        2000-01-30 Henrique M. Holschuh <hmh@rcm.org.br>
  9. #         - Minor cosmetic changes in an attempt to help new
  10. #           users notice something IS changing their clocks
  11. #           during startup/shutdown.
  12. #         - Added comments to alert users of hwclock issues
  13. #           and discourage tampering without proper doc reading.
  14.  
  15. # WARNING:    Please read /usr/share/doc/util-linux/README.Debian.hwclock
  16. #        before changing this file. You risk serious clock
  17. #        misbehaviour otherwise.
  18.  
  19. # In Ubuntu, it is normal that this init script is not run at startup;
  20. # the system clock is set from the hardware clock by the kernel, and
  21. # adjusted if the hardware clock was in localtime by udev.
  22.  
  23. ### BEGIN INIT INFO
  24. # Provides:          hwclock
  25. # Required-Start:    mountdevsubfs
  26. # Required-Stop:     $local_fs
  27. # Default-Start:     
  28. # Default-Stop:      0 6
  29. ### END INIT INFO
  30.  
  31. FIRST=no    # debian/rules sets this to 'yes' when creating hwclockfirst.sh
  32.  
  33. # Set this to any options you might need to give to hwclock, such
  34. # as machine hardware clock type for Alphas.
  35. HWCLOCKPARS=
  36.  
  37. # Set this to the hardware clock device you want to use, it should
  38. # probably match the CONFIG_RTC_HCTOSYS_DEVICE kernel config option.
  39. HCTOSYS_DEVICE=rtc0
  40.  
  41. hwclocksh()
  42. {
  43.     [ ! -x /sbin/hwclock ] && return 0
  44.     . /etc/default/rcS
  45.  
  46.     . /lib/lsb/init-functions
  47.     verbose_log_action_msg() { [ "$VERBOSE" = no ] || log_action_msg "$@"; }
  48.  
  49.     [ "$GMT" = "-u" ] && UTC="yes"
  50.     case "$UTC" in
  51.        no|"")    GMT="--localtime"
  52.         UTC=""
  53.         if [ "X$FIRST" = "Xyes" ] && [ ! -r /etc/localtime ]; then
  54.             if [ -z "$TZ" ]; then
  55.             log_action_msg "System clock was not updated at this time"
  56.             return 1
  57.             fi
  58.         fi
  59.         ;;
  60.        yes)    GMT="--utc"
  61.         UTC="--utc"
  62.         ;;
  63.        *)    log_action_msg "Unknown UTC setting: \"$UTC\""; return 1 ;;
  64.     esac
  65.  
  66.     case "$BADYEAR" in
  67.        no|"")    BADYEAR="" ;;
  68.        yes)    BADYEAR="--badyear" ;;
  69.        *)    log_action_msg "unknown BADYEAR setting: \"$BADYEAR\""; return 1 ;;
  70.     esac
  71.  
  72.     case "$1" in
  73.     start)
  74.         if [ -w /etc ] && [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then
  75.         echo "0.0 0 0.0" > /etc/adjtime
  76.         fi
  77.  
  78.         if [ ! -w /etc/adjtime ]; then
  79.         NOADJ="--noadjfile"
  80.         else
  81.             NOADJ=""
  82.         fi
  83.  
  84.         if [ "$FIRST" != yes ]; then
  85.         # Uncomment the hwclock --adjust line below if you want
  86.         # hwclock to try to correct systematic drift errors in the
  87.         # Hardware Clock.
  88.         #
  89.         # WARNING: If you uncomment this option, you must either make
  90.         # sure *nothing* changes the Hardware Clock other than
  91.         # hwclock --systohc, or you must delete /etc/adjtime
  92.         # every time someone else modifies the Hardware Clock.
  93.         #
  94.         # Common "vilains" are: ntp, MS Windows, the BIOS Setup
  95.         # program.
  96.         #
  97.         # WARNING: You must remember to invalidate (delete)
  98.         # /etc/adjtime if you ever need to set the system clock
  99.         # to a very different value and hwclock --adjust is being
  100.         # used.
  101.         #
  102.         # Please read /usr/share/doc/util-linux/README.Debian.hwclock
  103.         # before enabling hwclock --adjust.
  104.  
  105.         #/sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --adjust $GMT $BADYEAR
  106.         :
  107.         fi
  108.  
  109.         if [ "$HWCLOCKACCESS" != no ]; then
  110.         log_action_msg "Setting the system clock"
  111.  
  112.         # Copies Hardware Clock time to System Clock using the correct
  113.         # timezone for hardware clocks in local time, and sets kernel
  114.         # timezone. DO NOT REMOVE.
  115.         if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --hctosys $GMT $HWCLOCKPARS $BADYEAR $NOADJ; then
  116.             #    Announce the local time.
  117.             verbose_log_action_msg "System Clock set to: `date $UTC`"
  118.         else
  119.             log_warning_msg "Unable to set System Clock to: `date $UTC`"
  120.         fi
  121.         else
  122.         verbose_log_action_msg "Not setting System Clock"
  123.         fi
  124.         ;;
  125.     stop|restart|reload|force-reload)
  126.         #
  127.         # Updates the Hardware Clock with the System Clock time.
  128.         # This will *override* any changes made to the Hardware Clock.
  129.         #
  130.         # WARNING: If you disable this, any changes to the system
  131.         #          clock will not be carried across reboots.
  132.         #
  133.         if [ ! -w /etc/adjtime ]; then
  134.         NOADJ="--noadjfile"
  135.         else
  136.             NOADJ=""
  137.         fi
  138.  
  139.         if [ "$HWCLOCKACCESS" != no ]; then
  140.         log_action_msg "Saving the system clock"
  141.         if [ "$GMT" = "-u" ]; then
  142.             GMT="--utc"
  143.         fi
  144.         if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --systohc $GMT $HWCLOCKPARS $BADYEAR $NOADJ; then
  145.             verbose_log_action_msg "Hardware Clock updated to `date`"
  146.         fi
  147.         else
  148.         verbose_log_action_msg "Not saving System Clock"
  149.         fi
  150.         ;;
  151.     show)
  152.         if [ ! -w /etc/adjtime ]; then
  153.         NOADJ="--noadjfile"
  154.         else
  155.             NOADJ=""
  156.         fi
  157.  
  158.         if [ "$HWCLOCKACCESS" != no ]; then
  159.         /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --show $GMT $HWCLOCKPARS $BADYEAR $NOADJ
  160.         fi
  161.         ;;
  162.     *)
  163.         log_success_msg "Usage: hwclock.sh {start|stop|reload|force-reload|show}"
  164.         log_success_msg "       start sets kernel (system) clock from hardware (RTC) clock"
  165.         log_success_msg "       stop and reload set hardware (RTC) clock from kernel (system) clock"
  166.         return 1
  167.         ;;
  168.     esac
  169. }
  170.  
  171. hwclocksh "$@"
  172.