| 1 |
#!/sbin/runscript |
| 2 |
# Copyright 1999-2007 Gentoo Foundation |
| 3 |
# Distributed under the terms of the GNU General Public License v2 |
| 4 |
|
| 5 |
opts="save" |
| 6 |
|
| 7 |
depend() { |
| 8 |
need localmount |
| 9 |
} |
| 10 |
|
| 11 |
setupopts() { |
| 12 |
if is_uml_sys ; then |
| 13 |
TBLURB="UML" |
| 14 |
fakeit=1 |
| 15 |
elif is_vserver_sys ; then |
| 16 |
TBLURB="VServer" |
| 17 |
fakeit=1 |
| 18 |
elif is_xenU_sys ; then |
| 19 |
TBLURB="xen" |
| 20 |
fakeit=1 |
| 21 |
elif is_vz_sys ; then |
| 22 |
TBLURB="VZ" |
| 23 |
fakeit=1 |
| 24 |
elif grep -q ' cobd$' /proc/devices ; then |
| 25 |
TBLURB="coLinux" |
| 26 |
fakeit=1 |
| 27 |
elif [[ $(uname -m) == s390* ]] ; then |
| 28 |
TBLURB="s390" |
| 29 |
fakeit=1 |
| 30 |
elif [[ ${CLOCK} == "UTC" ]] ; then |
| 31 |
myopts="--utc" |
| 32 |
TBLURB="UTC" |
| 33 |
else |
| 34 |
myopts="--localtime" |
| 35 |
TBLURB="Local Time" |
| 36 |
fi |
| 37 |
[[ ${fakeit} -eq 1 ]] && return 0 |
| 38 |
|
| 39 |
if [[ ${readonly} == "yes" ]] ; then |
| 40 |
myadj="--noadjfile" |
| 41 |
else |
| 42 |
myadj="--adjust" |
| 43 |
fi |
| 44 |
|
| 45 |
if [[ ${SRM} == "yes" ]] ; then |
| 46 |
myopts="${myopts} --srm" |
| 47 |
fi |
| 48 |
if [[ ${ARC} == "arc" ]] ; then |
| 49 |
myopts="${myopts} --arc" |
| 50 |
fi |
| 51 |
myopts="${myopts} ${CLOCK_OPTS}" |
| 52 |
|
| 53 |
# Make sure user isn't using rc.conf anymore. |
| 54 |
if grep -qs ^CLOCK= /etc/rc.conf ; then |
| 55 |
ewarn "CLOCK should not be set in /etc/rc.conf but in /etc/conf.d/clock" |
| 56 |
fi |
| 57 |
# Make sure people set their timezone ... we do it here |
| 58 |
# even though we don't actually use the variable so that |
| 59 |
# people see the warning on boot. |
| 60 |
if [[ -z ${CDBOOT} && ${TIMEZONE-Factory} == "Factory" ]] ; then |
| 61 |
ewarn "Your TIMEZONE in /etc/conf.d/clock is still set to Factory!" |
| 62 |
fi |
| 63 |
} |
| 64 |
|
| 65 |
start() { |
| 66 |
local myopts="" syscmd="" |
| 67 |
local myadj="" |
| 68 |
local TBLURB="" fakeit=0 |
| 69 |
local errstr="" |
| 70 |
local readonly="no" |
| 71 |
local ret=0 |
| 72 |
|
| 73 |
if ! touch /etc/adjtime 2>/dev/null ; then |
| 74 |
readonly="yes" |
| 75 |
elif [[ ! -s /etc/adjtime ]] ; then |
| 76 |
echo "0.0 0 0.0" > /etc/adjtime |
| 77 |
fi |
| 78 |
|
| 79 |
setupopts |
| 80 |
|
| 81 |
if [[ ${fakeit} -ne 1 && -e /proc/modules && ! -e /dev/rtc ]] ; then |
| 82 |
modprobe rtc &> /dev/null || modprobe genrtc &> /dev/null |
| 83 |
fi |
| 84 |
|
| 85 |
if [[ ${CLOCK_HCTOSYS} == "yes" ]] ; then |
| 86 |
ebegin "Setting system clock using the hardware clock [${TBLURB}]" |
| 87 |
syscmd="--hctosys" |
| 88 |
else |
| 89 |
ebegin "Setting timezone [${TBLURB}]" |
| 90 |
syscmd="--systz" |
| 91 |
fi |
| 92 |
|
| 93 |
if [[ ${fakeit} -eq 1 ]] ; then |
| 94 |
ret=0 |
| 95 |
|
| 96 |
elif [[ -x /sbin/hwclock ]] ; then |
| 97 |
# Since hwclock always exit's with a 0, need to check its output. |
| 98 |
errstr=$(/sbin/hwclock ${myadj} ${myopts} 2>&1 >/dev/null) |
| 99 |
errstr="${errstr}$(/sbin/hwclock ${syscmd} ${myopts} 2>&1 >/dev/null)" |
| 100 |
|
| 101 |
if [[ -n ${errstr} ]] ; then |
| 102 |
ewarn "${errstr}" |
| 103 |
ret=1 |
| 104 |
else |
| 105 |
ret=0 |
| 106 |
fi |
| 107 |
errstr="Failed to set clock" |
| 108 |
else |
| 109 |
ret=1 |
| 110 |
errstr="/sbin/hwclock not found" |
| 111 |
fi |
| 112 |
eend ${ret} "${errstr}" "You will need to set the clock yourself" |
| 113 |
|
| 114 |
return 0 |
| 115 |
} |
| 116 |
|
| 117 |
stop() { |
| 118 |
# Don't tweak the hardware clock on LiveCD halt. |
| 119 |
[[ -n ${CDBOOT} ]] && return 0 |
| 120 |
|
| 121 |
[[ ${CLOCK_SYSTOHC} != "yes" ]] && return 0 |
| 122 |
|
| 123 |
local myopts="" |
| 124 |
local TBLURB="" |
| 125 |
local errstr="" |
| 126 |
local ret=0 |
| 127 |
|
| 128 |
setupopts |
| 129 |
|
| 130 |
ebegin "Setting hardware clock using the system clock [${TBLURB}]" |
| 131 |
if [[ ${fakeit} -eq 1 ]] ; then |
| 132 |
ret=0 |
| 133 |
|
| 134 |
elif [[ -x /sbin/hwclock ]] ; then |
| 135 |
errstr=$(/sbin/hwclock --systohc ${myopts} 2>&1 >/dev/null) |
| 136 |
|
| 137 |
if [[ -n ${errstr} ]] ; then |
| 138 |
ret=1 |
| 139 |
else |
| 140 |
ret=0 |
| 141 |
fi |
| 142 |
errstr="Failed to sync clocks" |
| 143 |
else |
| 144 |
ret=1 |
| 145 |
errstr="/sbin/hwclock not found" |
| 146 |
fi |
| 147 |
eend ${ret} "${errstr}" |
| 148 |
} |
| 149 |
|
| 150 |
save() { |
| 151 |
CLOCK_SYSTOHC="yes" |
| 152 |
stop |
| 153 |
} |
| 154 |
|
| 155 |
|
| 156 |
# vim:ts=4 |