home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / etc / init.d / hwclock.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2011-01-25  |  4.9 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. ### BEGIN INIT INFO
  20. # Provides:          hwclock
  21. # Required-Start:    checkroot
  22. # Required-Stop:     $local_fs
  23. # Default-Start:     S
  24. # Default-Stop:      0 6
  25. ### END INIT INFO
  26.  
  27. FIRST=no    # debian/rules sets this to 'yes' when creating hwclockfirst.sh
  28.  
  29. # Set this to any options you might need to give to hwclock, such
  30. # as machine hardware clock type for Alphas.
  31. HWCLOCKPARS=
  32.  
  33. # Set this to the hardware clock device you want to use, it should
  34. # probably match the CONFIG_RTC_HCTOSYS_DEVICE kernel config option.
  35. HCTOSYS_DEVICE=rtc0
  36.  
  37. hwclocksh()
  38. {
  39.     [ ! -x /sbin/hwclock ] && return 0
  40.     [ ! -r /etc/default/rcS ] || . /etc/default/rcS
  41.  
  42.     . /lib/lsb/init-functions
  43.     verbose_log_action_msg() { [ "$VERBOSE" = no ] || log_action_msg "$@"; }
  44.  
  45.     [ "$GMT" = "-u" ] && UTC="yes"
  46.     case "$UTC" in
  47.        no|"")    GMT="--localtime"
  48.         UTC=""
  49.         if [ "X$FIRST" = "Xyes" ] && [ ! -r /etc/localtime ]; then
  50.             if [ -z "$TZ" ]; then
  51.             log_action_msg "System clock was not updated at this time"
  52.             return 1
  53.             fi
  54.         fi
  55.         ;;
  56.        yes)    GMT="--utc"
  57.         UTC="--utc"
  58.         ;;
  59.        *)    log_action_msg "Unknown UTC setting: \"$UTC\""; return 1 ;;
  60.     esac
  61.  
  62.     case "$BADYEAR" in
  63.        no|"")    BADYEAR="" ;;
  64.        yes)    BADYEAR="--badyear" ;;
  65.        *)    log_action_msg "unknown BADYEAR setting: \"$BADYEAR\""; return 1 ;;
  66.     esac
  67.  
  68.     case "$1" in
  69.     start)
  70.         if [ -d /dev/.udev ]; then
  71.         return 0
  72.         fi
  73.  
  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.