#!/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 a PTP daemon for development (prefer statime, fallback to ptp4l) if [ "${RUN_STATIME:-0}" = "1" ]; then IFACE="${PTP_INTERFACE:-eth0}" if command -v statime >/dev/null 2>&1; then echo "[entrypoint] Starting statime on ${IFACE}..." >&2 statime -i "${IFACE}" & STATIME_PID=$! elif command -v ptp4l >/dev/null 2>&1; then echo "[entrypoint] Starting ptp4l on ${IFACE}..." >&2 # -m prints messages to stdout; adjust args as needed for your environment ptp4l -i "${IFACE}" -m & PTP4L_PID=$! else echo "[entrypoint] No PTP daemon found (statime or ptp4l). Skipping." >&2 fi fi # Run the requested command (default: get-haci) exec "$@"