summaryrefslogtreecommitdiff
path: root/etc/rc.d/rtclocaltime
blob: 9c60875dd8837583eb9b018948f37d37c658de3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/bin/sh
#
# $NetBSD: rtclocaltime,v 1.9 2009/04/08 13:29:59 martin 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=$(awk 'BEGIN{
		offset = -int(strftime("%z"));
		if (offset < 0) {
			sign = -1;
			offset = -offset;
		} else {
			sign = 1;
		}
		minutes = offset % 100;
		hours = int(offset / 100);
		offset = sign * (hours * 60 + minutes);
		print offset;
		exit(0);
	}')
	echo "Setting RTC offset to ${rtcoff}."
	sysctl -qw kern.rtc_offset=${rtcoff}
}

load_rc_config $name
run_rc_command "$1"