Add ntpclient config files by Carlos Sobrinho, thanks ! (#1052)
authorFlorian Fainelli <florian@openwrt.org>
Wed, 17 Jan 2007 19:31:22 +0000 (19:31 +0000)
committerFlorian Fainelli <florian@openwrt.org>
Wed, 17 Jan 2007 19:31:22 +0000 (19:31 +0000)
SVN-Revision: 6116

net/ntpclient/Makefile
net/ntpclient/files/ntpclient.config [new file with mode: 0644]
net/ntpclient/files/ntpclient.init

index c1bae55698620913b6873079765201f608d872de..502def60ea4bb21695fe287fc8ff04fb20ccafaf 100644 (file)
@@ -37,6 +37,8 @@ endef
 define Package/ntpclient/install       
        $(INSTALL_DIR) $(1)/etc/hotplug.d/iface
        $(INSTALL_BIN) ./files/ntpclient.init $(1)/etc/hotplug.d/iface/10-ntpclient
+       $(INSTALL_DIR) $(1)/etc/config
+       $(INSTALL_DATA) ./files/ntpclient.config $(1)/etc/config/ntp_client
        $(INSTALL_DIR) $(1)/usr/sbin
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/ntpclient $(1)/usr/sbin/
        $(INSTALL_BIN) $(PKG_BUILD_DIR)/adjtimex $(1)/usr/sbin/
diff --git a/net/ntpclient/files/ntpclient.config b/net/ntpclient/files/ntpclient.config
new file mode 100644 (file)
index 0000000..5be82ca
--- /dev/null
@@ -0,0 +1,9 @@
+config ntp_client
+       option hostname 'pool.ntp.org'
+       option port     '123'
+       option count    '1'
+
+config ntp_client
+       option hostname 'ntp.ubuntu.com'
+       option port     '123'
+       option count    '1'
index f508c313c0476b6e387a68d796ee220aeaed49fb..38cba5e0e5a3c7bd32b91c1e29b822a6bd6c40b8 100644 (file)
@@ -1,13 +1,32 @@
 #!/bin/sh
 # Copyright (C) 2006 OpenWrt.org
 
-ntp_server=$(nvram get ntp_server)
+. /etc/functions.sh
+
+config_cb() {
+       local cfg="$CONFIG_SECTION"
+       local cfgtype
+       config_get cfgtype "$cfg" TYPE
+
+       case "$cfgtype" in
+               ntp_client)
+                       config_get hostname     $cfg hostname
+                       config_get port         $cfg port
+                       config_get count        $cfg count
+                       
+                       ps x | grep 'bin/[n]tpclient' >&- || {
+                               route -n 2>&- | grep '^0.0.0.0' >&- && {
+                                       /usr/sbin/ntpclient -c ${count:-1} -s -h $hostname -p ${port:-123} 2>&- >&-
+                               }
+                       }
+               ;;
+       esac
+}
 case "${ACTION:-ifup}" in
        ifup)
-               ps x | grep 'bin/[n]tpclient' >&- || {
-                       route -n 2>&- | grep '^0.0.0.0' >&- && /usr/sbin/ntpclient -c 1 -s -h ${ntp_server:-pool.ntp.org} &
-               }
-               ;;
+               config_load ntp_client&
+       ;;
        ifdown)
-               route -n 2>&- | grep '^0.0.0.0' >&- || killall ntpclient 2>&- >&- ;;
+               route -n 2>&- | grep '^0.0.0.0' >&- || killall ntpclient 2>&- >&-
+       ;;
 esac