parent
0cdaaa90fe
commit
63f49e43e6
@ -1,3 +1,12 @@ |
||||
config system |
||||
option hostname OpenWrt |
||||
option timezone UTC |
||||
|
||||
config rdate |
||||
list server ac-ntp0.net.cmu.edu |
||||
list server ptbtime1.ptb.de |
||||
list server ac-ntp1.net.cmu.edu |
||||
list server ntp.xs4all.nl |
||||
list server ptbtime2.ptb.de |
||||
list server cudns.cit.cornell.edu |
||||
list server ptbtime3.ptb.de |
||||
|
@ -0,0 +1,46 @@ |
||||
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 |
Loading…
Reference in new issue