1
0
mirror of git://projects.qi-hardware.com/openwrt-xburst.git synced 2024-11-10 13:07:10 +02:00
openwrt-xburst/package/base-files/files/etc/hotplug.d/iface/40-rdate
jow 1ac5ad687b [package] base-files: add a hotplug handler for rdate
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@20518 3c298f89-4303-0410-b956-a3cf2f4a3e73
2010-03-27 17:13:33 +00:00

47 lines
840 B
Plaintext

uci_get_one()
{
for var in "$@"; do
uci -P /var/state get "$var" 2>/dev/null && break
done
}
rand()
{
random=$(awk 'BEGIN { srand(); print int(rand() * 10 + 1); }')
}
sync_rdate()
{
local servers=$(uci_get_one "network.$INTERFACE.lease_timesrv" \
"system.@rdate[0].server")
if [ -n "$servers" ]; then
match=0
tries=3
rand
while [ $match = 0 ] && [ $tries != 0 ]; do
for server in $servers; do
if [ $((--random)) = 0 ]; then
rdate -s $server >/dev/null 2>/dev/null && {
logger -t rdate "Synced with $server"
match=1
} || {
logger -t rdate "Failed to sync with $server"
let tries="$tries - 1"
rand
}
break
fi
done
done
else
logger -t rdate "No usable time server found"
fi
}
case "$ACTION" in
ifup) route -n | grep -q ^0.0.0.0 && sync_rdate;;
esac