summaryrefslogtreecommitdiffhomepage
path: root/modules/freifunk/root/usr/sbin/ff_rdate
blob: dc2c7b2d2c7004bb6b620d6a024a524750089d2e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/sh

uci_get_one() {
	for var in "$@"; do
		uci -P /var/state get "$var" 2>/dev/null && break
	done
}

local servers="$(uci_get_one 'network.wan.lease_timesrv') $(uci show timeserver | sed -ne 's/.*hostname=//p')"

if [ -n "$servers" ]; then
	for server in $servers; do
		rdate -s $server >/dev/null 2>/dev/null && \
			logger -t rdate "Synced with $server" && break

		logger -t rdate "Failed to sync with $server"
	done
else
	logger -t rdate "No usable time server found"
fi