xref: /freebsd/libexec/rc/rc.d/ntpdate (revision dd41de95a84d979615a2ef11df6850622bf6184e)
1#!/bin/sh
2#
3# $FreeBSD$
4#
5
6# PROVIDE: ntpdate
7# REQUIRE: NETWORKING syslogd
8# KEYWORD: nojail
9
10. /etc/rc.subr
11
12name="ntpdate"
13desc="Set the date and time via NTP"
14rcvar="ntpdate_enable"
15stop_cmd=":"
16start_cmd="ntpdate_start"
17
18ntpdate_start()
19{
20	if [ -z "$ntpdate_hosts" -a -f "$ntpdate_config" ]; then
21		ntpdate_hosts=`awk '
22			/^server[ \t]*127.127/      {next}
23			/^(server|peer|pool)/       {
24			    if ($2 ~/^-/)           {print $3}
25			    else                    {print $2}}
26		' < "$ntpdate_config"`
27	fi
28	if [ -n "$ntpdate_hosts" -o -n "$rc_flags" ]; then
29		echo "Setting date via ntp."
30		${ntpdate_program:-ntpdate} $rc_flags $ntpdate_hosts
31	fi
32}
33
34load_rc_config $name
35run_rc_command "$1"
36