#!/bin/bash
#
# Live-ISO entry point for the Omarchy install orchestrator. Invoked from
# /root/.automated_script.sh after the configurator wizard has produced its
# user_*.json / user_*.txt files. The outer shim owns install logging.

set -eEo pipefail

# Parse our args; convert to env vars before exec'ing Python so archinstall's
# own argparse (which runs at module import time inside the orchestrator)
# doesn't choke on flags it doesn't recognize.
while [[ $# -gt 0 ]]; do
  case $1 in
    --config)               export OMARCHY_INSTALL_CONFIG="$2"; shift 2 ;;
    --creds)                export OMARCHY_INSTALL_CREDS="$2"; shift 2 ;;
    --full-name-file)       export OMARCHY_INSTALL_FULL_NAME_FILE="$2"; shift 2 ;;
    --email-file)           export OMARCHY_INSTALL_EMAIL_FILE="$2"; shift 2 ;;
    --encrypt-file)         export OMARCHY_INSTALL_ENCRYPT_FILE="$2"; shift 2 ;;
    --authorized-keys-file) export OMARCHY_INSTALL_AUTHORIZED_KEYS_FILE="$2"; shift 2 ;;
    --tailscale-authkey-file) export OMARCHY_INSTALL_TAILSCALE_AUTHKEY_FILE="$2"; shift 2 ;;
    --defer-provisioning-file)             export OMARCHY_INSTALL_DEFER_PROVISIONING_FILE="$2"; shift 2 ;;
    *)                      echo "omarchy-iso-install: unknown arg $1" >&2; exit 2 ;;
  esac
done

cd /usr/share/omarchy-iso
exec python -m orchestrator.main
