5198da16a1
git-svn-id: svn://svn.openwrt.org/openwrt/packages@11103 3c298f89-4303-0410-b956-a3cf2f4a3e73
46 lines
862 B
Bash
46 lines
862 B
Bash
#!/bin/sh
|
|
# Copyright (C) 2006 OpenWrt.org
|
|
|
|
. /etc/functions.sh
|
|
|
|
DONE=0
|
|
config_cb() {
|
|
local cfg="$CONFIG_SECTION"
|
|
local cfgtype
|
|
config_get cfgtype "$cfg" TYPE
|
|
|
|
# initial frequency offset, if configured
|
|
case "$cfgtype" in
|
|
ntpdrift)
|
|
config_get freq $cfg freq
|
|
|
|
if [ ! "$freq" = "" ]; then
|
|
adjtimex -f $freq >/dev/null
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
case "$cfgtype" in
|
|
ntpclient)
|
|
config_get hostname $cfg hostname
|
|
config_get port $cfg port
|
|
config_get count $cfg count
|
|
|
|
[ "$DONE" = "1" ] && exit 0
|
|
ps | 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>&- >&- && DONE=1
|
|
}
|
|
}
|
|
;;
|
|
esac
|
|
}
|
|
case "${ACTION:-ifup}" in
|
|
ifup)
|
|
config_load ntpclient&
|
|
;;
|
|
ifdown)
|
|
route -n 2>&- | grep '^0.0.0.0' >&- || killall ntpclient 2>&- >&-
|
|
;;
|
|
esac
|