#!/bin/sh
#
# Keep the board clock right (2026-10-28).
#
# The board has no RTC and busybox ships no NTP client, so the system starts at
# a bogus date. /home/root/board-clock is a small SNTP client that sets the
# clock once at boot and re-syncs periodically. Without this, log timestamps
# are meaningless and any time-based proof cannot judge freshness.
#
# Runs from rc5 after S01networking.
#
case "$1" in
  start)
    if [ ! -x /home/root/board-clock ]; then
      echo "boardclock: /home/root/board-clock missing" > /dev/kmsg 2>/dev/null
      exit 1
    fi
    mkdir -p /var/log-persist
    /sbin/start-stop-daemon -S -b -m -p /var/run/board-clock.pid \
      -x /home/root/board-clock -- -interval 6h -log /var/log-persist/board-clock.log
    ;;
  stop)
    /sbin/start-stop-daemon -K -p /var/run/board-clock.pid -x /home/root/board-clock
    ;;
  *)
    echo "usage: $0 {start|stop}"
    exit 1
    ;;
esac
