2022-03-27 19:13:18 -06:00
|
|
|
#!/bin/sh
|
|
|
|
true <<'LICENSE'
|
|
|
|
|
|
|
|
On boot, and every 24 hours, update the clock from the first
|
|
|
|
available NTP server we find on the network.
|
|
|
|
|
2024-05-29 01:45:25 -06:00
|
|
|
Part of AREDN® -- Used for creating Amateur Radio Emergency Data Networks
|
2022-03-27 19:13:18 -06:00
|
|
|
Copyright (C) 2022 Tim Wilkinson KN6PLV
|
|
|
|
See Contributors file for additional contributors
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation version 3 of the License.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
Additional Terms:
|
|
|
|
|
2024-05-29 01:45:25 -06:00
|
|
|
Additional use restrictions exist on the AREDN® trademark and logo.
|
2022-03-27 19:13:18 -06:00
|
|
|
See AREDNLicense.txt for more info.
|
|
|
|
|
2024-05-29 01:45:25 -06:00
|
|
|
Attributions to the AREDN® Project must be retained in the source code.
|
2022-03-27 19:13:18 -06:00
|
|
|
If importing this code into a new or existing project attribution
|
2024-05-29 01:45:25 -06:00
|
|
|
to the AREDN® project must be added to the source code.
|
2022-03-27 19:13:18 -06:00
|
|
|
|
|
|
|
You must not misrepresent the origin of the material contained within.
|
|
|
|
|
|
|
|
Modified versions must be modified to attribute to the original source
|
|
|
|
and be marked in reasonable ways as differentiate it from the original
|
|
|
|
version.
|
|
|
|
|
|
|
|
LICENSE
|
|
|
|
|
|
|
|
exec 2> /dev/null
|
|
|
|
|
2024-09-03 16:53:33 -06:00
|
|
|
# If real ntp is running, we don't need to do this
|
|
|
|
if [ "$(pidof ntpd)" != "" ]; then
|
2024-10-08 22:01:45 -06:00
|
|
|
if [ -f /var/state/ntp-stratum ] && [ $(cat /var/state/ntp-stratum) -lt 16 ]; then
|
|
|
|
echo -n "ntp" > /tmp/timesync
|
|
|
|
exit 0
|
|
|
|
fi
|
2024-09-03 16:53:33 -06:00
|
|
|
fi
|
|
|
|
|
2024-10-08 21:57:58 -06:00
|
|
|
for candidate in $(uci -q get system.ntp.server)
|
|
|
|
do
|
2022-03-27 19:13:18 -06:00
|
|
|
if $(ntpd -n -q -p ${candidate}); then
|
2024-08-15 21:28:45 -06:00
|
|
|
echo -n "ntp" > /tmp/timesync
|
2022-03-27 19:13:18 -06:00
|
|
|
logger -p notice -t update-time "Update clock from ${candidate}"
|
|
|
|
exit 0
|
|
|
|
fi
|
2024-10-08 21:57:58 -06:00
|
|
|
done
|
2022-03-27 19:13:18 -06:00
|
|
|
|
|
|
|
# NTP servers tend to be poorly advertised, so we have to use a bit of
|
|
|
|
# heuristics to find them
|
2022-10-26 19:56:56 -06:00
|
|
|
for candidate in $(grep -i ntp /var/run/services_olsr | sed "s/^.*:\/\/\(.*\):.*$/\1/")
|
2022-03-27 19:13:18 -06:00
|
|
|
do
|
|
|
|
if $(ntpd -n -q -p ${candidate}); then
|
2024-08-15 21:28:45 -06:00
|
|
|
echo -n "ntp" > /tmp/timesync
|
2022-03-27 19:13:18 -06:00
|
|
|
logger -p notice -t update-time "Update clock from ${candidate}"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
2024-08-15 21:28:45 -06:00
|
|
|
rm -f /tmp/timesync
|
|
|
|
|
2022-03-27 19:13:18 -06:00
|
|
|
logger -p notice -t update-time "Failed to update clock: No reachable ntpd servers."
|
|
|
|
exit 1
|