- 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
+ local server
+ server=$(uci_get_state "network.$INTERFACE.lease_timesrv")
+ [ -n "$server" ] && do_rdate "$server"
+ [ -n "$SYNCED" ] && return
+
+ config_load timeserver
+ config_foreach add_server timeserver
+
+ local servers
+ while [ $MAX -gt 0 ] && [ -z "$SYNCED" ]; do
+ unset servers; random=$(awk "BEGIN { srand(); print int(rand() * $MAX + 1); }")
+ for server in $SERVERS; do
+ [ $((--random)) -eq 0 ] && { do_rdate "$server"; continue; }
+ servers="${servers} $server"