Fix GPS modem selection and add a GPS-only time source
This commit is contained in:
1 parent
eaf08abcd4
commit
a50c01b416
18 files changed
+682
-16
No files matched your search
@@ -17,6 +17,11 @@ CHRONYC=/usr/bin/chronyc
|
||||
RUNDIR=/run/bananarchy-time-sync
|
||||
STAMP="$RUNDIR/last"
|
||||
LOCK="$RUNDIR/lock"
|
||||
# GPS-only mode: the user can select GNSS as the sole time source. In that
|
||||
# mode chronyd is stopped by bananarchy-gps-time-sync.sh and no NTP burst,
|
||||
# source refresh or clock step may be issued from this helper.
|
||||
TIME_SOURCE_FILE="${BANANARCHY_TIME_SOURCE_FILE:-/home/user/.config/sxmo/time_source}"
|
||||
GPS_TIME_HELPER="${BANANARCHY_GPS_TIME_HELPER:-/usr/bin/bananarchy-gps-time-sync.sh}"
|
||||
# /proc/uptime is monotonic, so a multi-decade clock step cannot invalidate
|
||||
# the stamp. Unsynchronised attempts are spaced 15 s apart; a synchronised
|
||||
# clock only needs a source refresh every 5 min after a network change.
|
||||
@@ -30,7 +35,8 @@ ATTEMPTS=8
|
||||
BOOT_ATTEMPTS=30
|
||||
SYNC_WAIT=15
|
||||
|
||||
if [ "$(id -u)" != "0" ]; then
|
||||
# Host tests (and callers that already have privileges) can skip the doas hop.
|
||||
if [ "$(id -u)" != "0" ] && [ "${BANANARCHY_TIME_SYNC_NO_ESCALATION:-0}" != "1" ]; then
|
||||
exec doas -n "$0" "$@"
|
||||
fi
|
||||
|
||||
@@ -38,6 +44,14 @@ log() {
|
||||
printf 'bananarchy-time-sync: %s\n' "$*" >&2
|
||||
}
|
||||
|
||||
time_source() {
|
||||
v="network"
|
||||
if [ -r "$TIME_SOURCE_FILE" ]; then
|
||||
read -r v < "$TIME_SOURCE_FILE" 2>/dev/null || v="network"
|
||||
fi
|
||||
case "$v" in gps) printf 'gps\n' ;; *) printf 'network\n' ;; esac
|
||||
}
|
||||
|
||||
monotonic() {
|
||||
awk '{ printf "%d\n", $1 }' /proc/uptime
|
||||
}
|
||||
@@ -106,6 +120,10 @@ wait_sources() {
|
||||
|
||||
trigger() {
|
||||
mode="${1:-network-up}"
|
||||
if [ "$(time_source)" = "gps" ]; then
|
||||
log "GPS is the sole time source; skipping NTP"
|
||||
return 1
|
||||
fi
|
||||
attempts="$ATTEMPTS"
|
||||
[ "$mode" = "boot" ] && attempts="$BOOT_ATTEMPTS"
|
||||
wait_chronyd || {
|
||||
@@ -142,6 +160,12 @@ trigger() {
|
||||
|
||||
# Config -> Sync net time: force a burst and report when the clock is set.
|
||||
sync_now() {
|
||||
if [ "$(time_source)" = "gps" ]; then
|
||||
# Config -> Sync net time must still give the user a result without
|
||||
# touching NTP when GNSS is the only configured source.
|
||||
"$GPS_TIME_HELPER" sync
|
||||
return $?
|
||||
fi
|
||||
if ! trigger sync; then
|
||||
echo "Network time unavailable: chronyd or DNS is not ready"
|
||||
return 1
|
||||
@@ -162,9 +186,17 @@ sync_now() {
|
||||
|
||||
case "${1:-status}" in
|
||||
boot|network-up)
|
||||
if [ "$(time_source)" = "gps" ]; then
|
||||
[ "${1:-}" = "boot" ] && "$GPS_TIME_HELPER" boot >/dev/null 2>&1 || true
|
||||
exit 0
|
||||
fi
|
||||
trigger "$1" && refresh_statusbar
|
||||
;;
|
||||
force)
|
||||
if [ "$(time_source)" = "gps" ]; then
|
||||
"$GPS_TIME_HELPER" sync && refresh_statusbar
|
||||
exit $?
|
||||
fi
|
||||
trigger force && refresh_statusbar
|
||||
;;
|
||||
sync)
|
||||
|
||||
Reference in new issue
Block a user