#!/usr/bin/env python3
"""
Synex USB Creator privileged writer.

Executed as root through pkexec. It bootstraps the source path and runs the
backend writer module, preserving the original command-line arguments.
"""

from __future__ import annotations

import runpy
import sys
from pathlib import Path


CURRENT_FILE = Path(__file__).resolve()

CANDIDATE_SOURCE_DIRS = [
    CURRENT_FILE.parents[1],        # installed: /usr/lib/synex-mkboot/bin/ ; dev: ./src/bin/
    Path("/usr/lib/synex-mkboot"),  # installed fallback
]

for source_dir in CANDIDATE_SOURCE_DIRS:
    if (source_dir / "synex_mkboot").exists():
        if str(source_dir) not in sys.path:
            sys.path.insert(0, str(source_dir))
        break


if __name__ == "__main__":
    runpy.run_module("synex_mkboot.backend", run_name="__main__", alter_sys=True)
