#!/bin/bash
# run.sh — wrapper that BBS software (Synchronet, Mystic, etc.) calls
# instead of invoking the binary directly. Sets the PATH and env that
# the door needs.
#
# Deploy on the BBS server (NOT on the dev machine):
#   scp run.sh sixeldoor-static user@bbs:/sbbs/xtrn/ytube/
#   ssh user@bbs
#     sudo mv /sbbs/xtrn/ytube/sixeldoor-static /sbbs/xtrn/ytube/sixeldoor
#     sudo chmod +x /sbbs/xtrn/ytube/sixeldoor /sbbs/xtrn/ytube/run.sh
#     sudo vim /sbbs/xtrn/ytube/run.sh   # edit SIXELDOOR_HOSTNAME below!
#
# Then in scfg:
#   Command Line: /sbbs/xtrn/ytube/run.sh %f

# ---- EDIT THIS ----
# The public hostname or IP that your users reach the BBS at.
# The door prints audio URLs as http://$SIXELDOOR_HOSTNAME:$PORT/a/<token>,
# and your users open those on their phones — so it MUST resolve from
# outside your LAN.
SIXELDOOR_HOSTNAME="bbs.example.com"

# Port for the out-of-band audio HTTP server. Must be open in your firewall.
SIXELDOOR_AUDIO_PORT=18080
# -------------------

# Search common install locations for yt-dlp and ffmpeg. Synchronet often
# starts doors with a minimal PATH, so we set an explicit one here.
export PATH="/usr/local/bin:/usr/bin:/bin:$HOME/.local/bin:$PATH"

export SIXELDOOR_HOSTNAME
export SIXELDOOR_AUDIO_PORT

# Exec the door binary with the dropfile argument Synchronet passes us.
exec "$(dirname "$0")/sixeldoor" "$@"
