#!/bin/sh
# Isolated start: -I ignores PYTHON* variables, the user site-packages and the working
# directory, so nothing outside /usr/lib/afar-linux and the system site can run first or
# shadow afar, afar_iroh or cryptography. The dynamic-loader variables are cleared because
# ld.so applies them before any Python code can check them. -B keeps the root-owned tree
# free of bytecode (-I ignores PYTHONDONTWRITEBYTECODE). Start in the home folder, not the
# read-only install tree, so file choosers and relative paths land somewhere writable.
set -eu
export PYTHONDONTWRITEBYTECODE=1
cd "${HOME:-/}" 2>/dev/null || cd /
exec env -u LD_PRELOAD -u LD_LIBRARY_PATH -u LD_AUDIT /usr/bin/python3 -I -B -c \
    'import runpy, sys
sys.path.insert(0, "/usr/lib/afar-linux")
from afar.interpreter import require_supported_python
require_supported_python()
runpy.run_module("afar", run_name="__main__", alter_sys=True)' "$@"
