#!/usr/bin/env bash
# SPDX-License-Identifier: LGPL-2.1+
set -e
PYTHONPATH="$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")"
export PYTHONPATH

if [ -z "$MKOSI_INTERPRETER" ]; then
    # Note the check seems to be inverted here because the if branch is executed when the exit status is 0
    # which is equal to "False" in python.
    if python3 -c "import sys; sys.exit(sys.version_info < (3, 9))"; then
        MKOSI_INTERPRETER=python3
    elif command -v python3.9 >/dev/null; then
        MKOSI_INTERPRETER=python3.9
    else
        echo "mkosi needs python 3.9 or newer (found $(python3 --version))"
        exit 1
    fi
fi

exec "$MKOSI_INTERPRETER" -B -m mkosi "$@"
