#!/bin/sh set -eu # 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 # Run the requested command (default: get-haci) exec "$@"