|
#!/bin/sh |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BADYEAR=no |
|
HWCLOCKACCESS=yes |
|
HWCLOCKPARS= |
|
HCTOSYS_DEVICE=rtc0 |
|
|
|
|
|
|
|
unset TZ |
|
|
|
hwclocksh() |
|
{ |
|
[ ! -x /sbin/hwclock ] && return 0 |
|
[ ! -r /etc/default/rcS ] || . /etc/default/rcS |
|
[ ! -r /etc/default/hwclock ] || . /etc/default/hwclock |
|
|
|
. /lib/lsb/init-functions |
|
verbose_log_action_msg() { [ "$VERBOSE" = no ] || log_action_msg "$@"; } |
|
|
|
case "$BADYEAR" in |
|
no|"") BADYEAR="" ;; |
|
yes) BADYEAR="--badyear" ;; |
|
*) log_action_msg "unknown BADYEAR setting: \"$BADYEAR\""; return 1 ;; |
|
esac |
|
|
|
case "$1" in |
|
start) |
|
|
|
|
|
if [ -w /etc ] && [ ! -f /etc/adjtime ] && [ ! -e /etc/adjtime ]; then |
|
printf "0.0 0 0.0\n0\nUTC\n" > /etc/adjtime |
|
fi |
|
|
|
if [ -d /run/udev ] || [ -d /dev/.udev ]; then |
|
return 0 |
|
fi |
|
|
|
if [ "$HWCLOCKACCESS" != no ]; then |
|
log_action_msg "Setting the system clock" |
|
|
|
|
|
if sed '3!d' /etc/adjtime | grep -q '^UTC$'; then |
|
UTC="--utc" |
|
else |
|
UTC= |
|
fi |
|
|
|
|
|
|
|
if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --hctosys $HWCLOCKPARS $BADYEAR; then |
|
|
|
verbose_log_action_msg "System Clock set to: `date $UTC`" |
|
else |
|
log_warning_msg "Unable to set System Clock to: `date $UTC`" |
|
fi |
|
else |
|
verbose_log_action_msg "Not setting System Clock" |
|
fi |
|
;; |
|
stop|restart|reload|force-reload) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if [ "$HWCLOCKACCESS" != no ]; then |
|
log_action_msg "Saving the system clock" |
|
if /sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --systohc $HWCLOCKPARS $BADYEAR; then |
|
verbose_log_action_msg "Hardware Clock updated to `date`" |
|
fi |
|
else |
|
verbose_log_action_msg "Not saving System Clock" |
|
fi |
|
;; |
|
show) |
|
if [ "$HWCLOCKACCESS" != no ]; then |
|
/sbin/hwclock --rtc=/dev/$HCTOSYS_DEVICE --show $HWCLOCKPARS $BADYEAR |
|
fi |
|
;; |
|
*) |
|
log_success_msg "Usage: hwclock.sh {start|stop|reload|force-reload|show}" |
|
log_success_msg " start sets kernel (system) clock from hardware (RTC) clock" |
|
log_success_msg " stop and reload set hardware (RTC) clock from kernel (system) clock" |
|
return 1 |
|
;; |
|
esac |
|
} |
|
|
|
hwclocksh "$@" |
|
|