#!/bin/sh
# Modified for JustFit: product identity and integration.
set -eu

# Linked onto PATH, $0 names the link: follow it to the checkout.
script=$0
while [ -L "$script" ]; do
    target=$(readlink -- "$script")
    case $target in
        /*) script=$target ;;
        *) script=$(dirname -- "$script")/$target ;;
    esac
done
ROOT=$(CDPATH= cd -P -- "$(dirname -- "$script")" && pwd -P)

for python in "$ROOT/.venv/bin/python" python3.13 python3 python3.12 python3.14; do
    if (test -x "$python" 2>/dev/null || command -v "$python" >/dev/null 2>&1) \
        && "$python" -c 'import sys; raise SystemExit(not ((3, 12) <= sys.version_info[:2] < (3, 15)))' \
            >/dev/null 2>&1; then
        exec "$python" -u "$ROOT/install/launcher.py" "$@"
    fi
done

echo "JustFit needs Python 3.12, 3.13, or 3.14." >&2
echo "Install Python, then run ./justfit serve --model <owner/repo>." >&2
exit 1
