#!/bin/bash
set -e

cd "$(dirname "$0")"

# Bootstrap virtualenv on first run
if [ ! -d ".venv" ]; then
  echo "Creating virtualenv..."
  python3 -m venv .venv
  .venv/bin/pip install -q --upgrade pip
  .venv/bin/pip install -q -r requirements.txt
fi

mkdir -p data/bots
mkdir -p static

# Set token — override via: MANAGER_TOKEN=mysecret ./start.sh
export MANAGER_TOKEN="${MANAGER_TOKEN:-changeme}"

echo ""
echo "  SimpleX Manager"
echo "  URL:   http://0.0.0.0:8000"
echo "  Token: $MANAGER_TOKEN"
echo ""

exec .venv/bin/uvicorn main:app --host 0.0.0.0 --port 8000 --reload
