2 # Copyright (C) 2006 OpenWrt.org
11 NTPC
=`which ntpclient`
16 [ -n "$SERVER" ] && return
17 config_get hostname
$1 hostname
18 config_get port
$1 port
19 [ -z "$hostname" ] && return
20 $NTPC -c 1 -p ${port:-123} -h $hostname > /dev/null && { SERVER=$hostname; PORT=${port:-123}; }
24 config_get freq
$1 freq
25 [ -n "$freq" ] && adjtimex
-f $freq >/dev
/null
29 config_foreach set_drift ntpdrift
30 config_foreach check_server ntpserver
31 [ -z "$SERVER" ] && exit 0
32 logger starting ntpclient
33 $NTPC ${COUNT:+-c $COUNT} ${INTERVAL:+-i $INTERVAL} -D -p $PORT -h $SERVER 2> /dev
/null
37 logger stopping ntpclient
46 config_get interval
$1 interval
47 config_get count
$1 count
48 config_get iface
$1 iface
50 [ -n "$iface" ] && IFACE
=$iface
51 [ -n "$count" ] && COUNT
=$count
52 [ -n "$interval" ] && INTERVAL
=$interval
56 config_foreach load_settings ntpclient
58 # check if we only listen to a single iface
59 [ -n "$IFACE" -a "$IFACE" != "$INTERFACE" ] && exit 0
61 DEF_ROUTE
=`route -n | grep '^0.0.0.0'`
62 NTP_RUNNING
=`ps | grep $NTPC | grep -v grep`
64 case "${ACTION:-ifup}" in
66 [ -n "$DEF_ROUTE" -a -z "$NTP_RUNNING" ] && start_ntpclient
69 [ -n "$NTP_RUNNING" ] && stop_ntpclient