#!/usr/bin/env bash
set -euo pipefail

if ! command -v python3 >/dev/null 2>&1; then
  echo "python3 is required" >&2
  exit 1
fi

PYTHON_BIN="${PYTHON_BIN:-python3}"
PIP_BIN="${PIP_BIN:-$PYTHON_BIN -m pip}"

if ! $PYTHON_BIN -m pip --version >/dev/null 2>&1; then
  echo "python3 -m pip is required" >&2
  exit 1
fi

CONNECTORS=('planfile')
echo "Installing ifuri connectors: ${CONNECTORS[*]}"
if [ -n "${URIRUN_PIP_SPEC:-}" ]; then
  $PIP_BIN install "$URIRUN_PIP_SPEC"
else
  $PIP_BIN install 'urirun @ git+https://github.com/tellmesh/urirun.git@v0.3.12#subdirectory=adapters/python'
fi
  $PIP_BIN install 'planfile>=0.1.103'

if command -v urirun >/dev/null 2>&1; then
  echo
  echo "urirun installed:"
  urirun --help | head -20 || true
fi

echo
echo "Next:"
echo "  urirun connectors list   # after connector entry-point support lands"
echo "  ifuri host dashboard     # from the ifuri app/host package"
