NetBSD/etc/rc.d/rtclocaltime
apb e2832b6345 Back out previous (which worked but made the code harder to understand),
and implement a different method of avoiding a "-0" result.
2007-08-25 07:07:39 +00:00

38 lines
659 B
Bash
Executable File

#!/bin/sh
#
# $NetBSD: rtclocaltime,v 1.7 2007/08/25 07:07:39 apb Exp $
#
# PROVIDE: rtclocaltime
# REQUIRE: mountcritremote
# BEFORE: ntpdate ntpd
$_rc_subr_loaded . /etc/rc.subr
name="rtclocaltime"
rcvar=$name
start_cmd="rtclocaltime_start"
stop_cmd=":"
rtclocaltime_start()
{
rtcoff=$(date '+%z' | awk '{
offset = -int($1);
if (offset < 0) {
sign = -1;
offset = -offset;
} else {
sign = 1;
}
minutes = offset % 100;
hours = int(offset / 100);
offset = sign * (hours * 60 + minutes);
print offset;
}')
echo "Setting RTC offset to ${rtcoff}."
sysctl -qw kern.rtc_offset=${rtcoff}
}
load_rc_config $name
run_rc_command "$1"