mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 18:32:02 +00:00
46 lines
1.5 KiB
Bash
46 lines
1.5 KiB
Bash
#!/bin/sh
|
|
set -eu
|
|
# Mark container as development unless explicitly disabled
|
|
export HACI_DEV="${HACI_DEV:-1}"
|
|
|
|
# If enabled, start a mock Teensy that exposes a PTY at /dev/ttyACM0 and streams LTC-like lines.
|
|
if [ "${MOCK_TEENSY:-0}" = "1" ]; then
|
|
echo "[entrypoint] Starting mock Teensy (PTY at /dev/ttyACM0)..." >&2
|
|
# Bridge the LTC generator to a PTY that looks like a Teensy serial port.
|
|
# Left side runs the generator, right side is a PTY linked to /dev/ttyACM0
|
|
socat -d -d -lf /dev/stderr EXEC:'/usr/local/bin/ltc-gen.sh',pty,ctty,echo=0,raw PTY,link=/dev/ttyACM0,raw,echo=0 &
|
|
SOCAT_PID=$!
|
|
|
|
# Wait briefly for the PTY to appear
|
|
i=0
|
|
while [ $i -lt 50 ]; do
|
|
if [ -e /dev/ttyACM0 ]; then
|
|
break
|
|
fi
|
|
i=$((i+1))
|
|
sleep 0.1
|
|
done
|
|
if [ ! -e /dev/ttyACM0 ]; then
|
|
echo "[entrypoint] WARNING: Failed to create /dev/ttyACM0 (mock Teensy)" >&2
|
|
else
|
|
export HACI_SERIAL_PORT=/dev/ttyACM0
|
|
echo "[entrypoint] Using mock serial at $HACI_SERIAL_PORT" >&2
|
|
fi
|
|
fi
|
|
|
|
# Optionally start the PTP daemon (statime) for development
|
|
if [ "${RUN_STATIME:-0}" = "1" ]; then
|
|
echo "[entrypoint] Starting statime PTP daemon..." >&2
|
|
if command -v statime >/dev/null 2>&1; then
|
|
IFACE="${PTP_INTERFACE:-eth0}"
|
|
echo "[entrypoint] statime interface: ${IFACE}" >&2
|
|
# Run statime in background; logs to container stderr/stdout
|
|
statime -i "${IFACE}" &
|
|
STATIME_PID=$!
|
|
else
|
|
echo "[entrypoint] statime not found on PATH" >&2
|
|
fi
|
|
fi
|
|
|
|
# Run the requested command (default: get-haci)
|
|
exec "$@"
|