Home | History | Annotate | Line # | Download | only in rc.d
      1 #!/bin/sh
      2 #
      3 # $NetBSD: rtclocaltime,v 1.9 2009/04/08 13:29:59 martin Exp $
      4 #
      5 
      6 # PROVIDE: rtclocaltime
      7 # REQUIRE: mountcritremote
      8 # BEFORE:  ntpdate ntpd
      9 
     10 $_rc_subr_loaded . /etc/rc.subr
     11 
     12 name="rtclocaltime"
     13 rcvar=$name
     14 start_cmd="rtclocaltime_start"
     15 stop_cmd=":"
     16 
     17 rtclocaltime_start()
     18 {
     19 	rtcoff=$(awk 'BEGIN{
     20 		offset = -int(strftime("%z"));
     21 		if (offset < 0) {
     22 			sign = -1;
     23 			offset = -offset;
     24 		} else {
     25 			sign = 1;
     26 		}
     27 		minutes = offset % 100;
     28 		hours = int(offset / 100);
     29 		offset = sign * (hours * 60 + minutes);
     30 		print offset;
     31 		exit(0);
     32 	}')
     33 	echo "Setting RTC offset to ${rtcoff}."
     34 	sysctl -qw kern.rtc_offset=${rtcoff}
     35 }
     36 
     37 load_rc_config $name
     38 run_rc_command "$1"
     39