2008-03-02 21:14:01 +00:00
|
|
|
#!@PREFIX@/sbin/runscript
|
2009-05-01 15:11:40 +01:00
|
|
|
# Copyright (c) 2007-2008 Roy Marples <roy@marples.name>
|
2008-01-11 15:31:10 +00:00
|
|
|
# All rights reserved. Released under the 2-clause BSD license.
|
2007-11-14 15:22:04 +00:00
|
|
|
|
2007-11-20 18:19:48 +00:00
|
|
|
extra_commands="save show"
|
2007-04-05 11:18:42 +00:00
|
|
|
|
2011-01-17 04:49:07 -05:00
|
|
|
description="Sets the local clock to UTC or Local Time."
|
2007-07-10 19:09:41 +00:00
|
|
|
description_save="Saves the current time in the BIOS."
|
2007-10-24 08:50:14 +00:00
|
|
|
description_show="Displays the current time in the BIOS."
|
2007-07-10 19:09:41 +00:00
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
: ${clock_adjfile:=${CLOCK_ADJFILE}}
|
|
|
|
: ${clock_args:=${CLOCK_OPTS}}
|
|
|
|
: ${clock_systohc:=${CLOCK_SYSTOHC}}
|
|
|
|
: ${clock:=${CLOCK:-UTC}}
|
|
|
|
if [ "$clock" = "UTC" ]; then
|
2007-12-14 14:12:38 +00:00
|
|
|
utc="UTC"
|
|
|
|
utc_cmd="--utc"
|
|
|
|
else
|
|
|
|
utc="Local Time"
|
|
|
|
utc_cmd="--localtime"
|
|
|
|
fi
|
|
|
|
|
2008-01-11 12:13:46 +00:00
|
|
|
depend()
|
|
|
|
{
|
2008-03-25 14:06:05 +00:00
|
|
|
provide clock
|
2009-04-27 07:51:18 +00:00
|
|
|
if yesno $clock_adjfile; then
|
2008-01-31 18:01:20 +00:00
|
|
|
use root
|
2007-10-23 22:49:21 +00:00
|
|
|
else
|
|
|
|
before *
|
|
|
|
fi
|
2009-11-04 19:21:24 +00:00
|
|
|
keyword -openvz -prefix -uml -vserver -xenu -lxc
|
2007-04-05 11:18:42 +00:00
|
|
|
}
|
|
|
|
|
2008-01-11 12:13:46 +00:00
|
|
|
setupopts()
|
|
|
|
{
|
2008-02-19 14:29:20 +00:00
|
|
|
case "$(uname -m)" in
|
|
|
|
s390*)
|
|
|
|
utc="s390"
|
2007-04-05 11:18:42 +00:00
|
|
|
;;
|
|
|
|
*)
|
2008-02-19 14:29:20 +00:00
|
|
|
if [ -e /proc/devices ] && \
|
|
|
|
grep -q " cobd$" /proc/devices
|
|
|
|
then
|
|
|
|
utc="coLinux"
|
|
|
|
fi
|
2007-04-05 11:18:42 +00:00
|
|
|
;;
|
|
|
|
esac
|
2007-12-14 14:12:38 +00:00
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
case "$utc" in
|
2007-12-14 14:12:38 +00:00
|
|
|
UTC|Local" "Time);;
|
|
|
|
*) unset utc_cmd;;
|
|
|
|
esac
|
2007-04-05 11:18:42 +00:00
|
|
|
}
|
|
|
|
|
2008-01-08 14:58:56 +00:00
|
|
|
# hwclock doesn't always return non zero on error
|
2008-01-11 12:13:46 +00:00
|
|
|
_hwclock()
|
|
|
|
{
|
2008-01-08 14:58:56 +00:00
|
|
|
local err="$(hwclock "$@" 2>&1 >/dev/null)"
|
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
[ -z "$err" ] && return 0
|
2008-01-08 14:58:56 +00:00
|
|
|
echo "${err}" >&2
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
|
2008-01-11 12:13:46 +00:00
|
|
|
start()
|
|
|
|
{
|
2007-12-14 14:12:38 +00:00
|
|
|
local retval=0 errstr=""
|
2007-04-05 11:18:42 +00:00
|
|
|
setupopts
|
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
if [ -z "$utc_cmd" ]; then
|
|
|
|
ewarn "Not setting clock for $utc system"
|
2008-01-04 12:50:04 +00:00
|
|
|
return 0
|
|
|
|
fi
|
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
ebegin "Setting system clock using the hardware clock [$utc]"
|
2008-10-26 07:09:02 +00:00
|
|
|
if [ -e /proc/modules ]; then
|
|
|
|
local rtc=
|
|
|
|
for rtc in /dev/rtc /dev/rtc[0-9]*; do
|
2009-04-27 07:51:18 +00:00
|
|
|
[ -e "$rtc" ] && break
|
2008-10-26 07:09:02 +00:00
|
|
|
done
|
|
|
|
if [ ! -e "${rtc}" ]; then
|
|
|
|
modprobe -q rtc-cmos || modprobe -q rtc || modprobe -q genrtc
|
|
|
|
fi
|
2008-01-04 12:50:04 +00:00
|
|
|
fi
|
2007-10-23 22:49:21 +00:00
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
if [ -e /etc/adjtime ] && yesno $clock_adjfile; then
|
|
|
|
_hwclock --adjust $utc_cmd
|
|
|
|
retval=$(($retval + $?))
|
2007-10-23 22:49:21 +00:00
|
|
|
fi
|
2011-01-17 04:49:07 -05:00
|
|
|
|
2008-01-04 12:50:04 +00:00
|
|
|
# If setting UTC, don't bother to run hwclock when first booting
|
|
|
|
# as that's the default
|
2009-04-27 07:51:18 +00:00
|
|
|
if [ "$PREVLEVEL" != N -o \
|
2011-02-06 13:23:53 -05:00
|
|
|
"$utc_cmd" != --utc -o \
|
2009-04-27 07:51:18 +00:00
|
|
|
-n "$clock_args" ];
|
2008-01-08 14:58:56 +00:00
|
|
|
then
|
2011-02-07 10:29:38 -06:00
|
|
|
if yesno $clock_hctosys; then
|
|
|
|
_hwclock --hctosys $utc_cmd $clock_args
|
|
|
|
else
|
|
|
|
_hwclock --systz $utc_cmd $clock_args
|
|
|
|
fi
|
2009-04-27 07:51:18 +00:00
|
|
|
retval=$(($retval + $?))
|
2008-01-04 12:50:04 +00:00
|
|
|
fi
|
2011-01-17 04:49:07 -05:00
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
eend $retval "Failed to set the system clock"
|
2007-04-05 11:18:42 +00:00
|
|
|
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2008-01-11 12:13:46 +00:00
|
|
|
stop()
|
|
|
|
{
|
2007-04-05 11:18:42 +00:00
|
|
|
# Don't tweak the hardware clock on LiveCD halt.
|
2009-04-27 07:51:18 +00:00
|
|
|
[ -n "$CDBOOT" ] && return 0
|
|
|
|
yesno $clock_systohc || return 0
|
2007-04-05 11:18:42 +00:00
|
|
|
|
2007-12-14 14:12:38 +00:00
|
|
|
local retval=0 errstr=""
|
2007-04-05 11:18:42 +00:00
|
|
|
setupopts
|
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
[ -z "$utc_cmd" ] && return 0
|
2008-01-04 12:50:04 +00:00
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
ebegin "Setting hardware clock using the system clock" "[$utc]"
|
2008-01-08 14:58:56 +00:00
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
if ! yesno $clock_adjfile; then
|
2008-01-04 12:50:04 +00:00
|
|
|
# Some implementations don't handle adjustments
|
2009-06-12 23:11:16 +01:00
|
|
|
if LC_ALL=C hwclock --help 2>&1 | grep -q "\-\-noadjfile"; then
|
2009-04-27 07:51:18 +00:00
|
|
|
utc_cmd="$utc_cmd --noadjfile"
|
2007-10-23 20:00:08 +00:00
|
|
|
fi
|
2007-10-23 22:49:21 +00:00
|
|
|
fi
|
2008-01-08 14:58:56 +00:00
|
|
|
|
2009-04-27 07:51:18 +00:00
|
|
|
_hwclock --systohc $utc_cmd $clock_args
|
2008-01-08 14:58:56 +00:00
|
|
|
retval=$?
|
|
|
|
|
2011-01-17 04:49:07 -05:00
|
|
|
eend $retval "Failed to sync clocks"
|
2007-04-05 11:18:42 +00:00
|
|
|
}
|
|
|
|
|
2008-01-11 12:13:46 +00:00
|
|
|
save()
|
|
|
|
{
|
2009-04-27 07:51:18 +00:00
|
|
|
clock_systohc=yes
|
2007-04-05 11:18:42 +00:00
|
|
|
stop
|
|
|
|
}
|
|
|
|
|
2008-01-11 12:13:46 +00:00
|
|
|
show()
|
|
|
|
{
|
2007-10-24 07:26:05 +00:00
|
|
|
setupopts
|
2009-04-27 07:51:18 +00:00
|
|
|
hwclock --show "$utc_cmd" $clock_args
|
2007-10-24 07:26:05 +00:00
|
|
|
}
|