#!/bin/bash
# Listen headless sender. No UI, one stream, nothing stored.
# Usage:  curl -fsSL https://marcusx.fun/listen/send.sh | bash
set -euo pipefail
URL="${LISTEN_URL:-https://marcusx.fun/listen}"
URL="${URL%/}"
PY=$(command -v python3 || true)
if [ -z "$PY" ]; then
  echo "python3 is required (macOS: xcode-select --install)" >&2
  exit 1
fi
DIR=$(cd "$(dirname "$0")" 2>/dev/null && pwd || true)
if [ -n "${DIR:-}" ] && [ -f "$DIR/sender.py" ] && [ -f "$DIR/proto.py" ]; then
  exec "$PY" -B "$DIR/sender.py" --url "$URL" "$@"
fi
# Fetched copies live only in a temp dir and are deleted on exit. Nothing is stored.
TMP=$(mktemp -d -t listen-send.XXXXXX)
trap 'rm -rf "$TMP"' EXIT
curl -fsSL "$URL/sender.py" -o "$TMP/sender.py"
curl -fsSL "$URL/proto.py" -o "$TMP/proto.py"
exec "$PY" -B "$TMP/sender.py" --url "$URL" "$@"
