2abb0361fc7071b6f5d316f01d67e33df86641a5
[openwrt/svn-archive/archive.git] / net / ntpclient / files / ntpclient.hotplug
1 #!/bin/sh
2 # Copyright (C) 2006 OpenWrt.org
3
4 . /etc/functions.sh
5
6 DONE=0
7 config_cb() {
8 local cfg="$CONFIG_SECTION"
9 local cfgtype
10 config_get cfgtype "$cfg" TYPE
11
12 case "$cfgtype" in
13 ntpclient)
14 config_get hostname $cfg hostname
15 config_get port $cfg port
16 config_get count $cfg count
17
18 [ "$DONE" = "1" ] && exit 0
19 ps | grep 'bin/[n]tpclient' >&- || {
20 route -n 2>&- | grep '^0.0.0.0' >&- && {
21 /usr/sbin/ntpclient -c ${count:-1} -s -h $hostname -p ${port:-123} 2>&- >&- && DONE=1
22 }
23 }
24 ;;
25 esac
26 }
27 case "${ACTION:-ifup}" in
28 ifup)
29 config_load ntpclient&
30 ;;
31 ifdown)
32 route -n 2>&- | grep '^0.0.0.0' >&- || killall ntpclient 2>&- >&-
33 ;;
34 esac