#!/usr/bin/env bash
# Run inside the Omarchy live ISO when it was booted from a partition on the
# disk you are installing to. The installer hides the disk it booted from,
# which leaves an empty disk list ("gum: no options provided").
# This drops that filter for this live session only, then restarts the installer.
set -euo pipefail

configurator=/root/configurator

[[ $EUID -eq 0 ]] || { echo "Run as root." >&2; exit 1; }
[[ -d /run/archiso && -f $configurator ]] || { echo "Not an Omarchy live ISO." >&2; exit 1; }

sed -i 's/exclude_disk=$(get_root_disk "$boot_source")/exclude_disk=/' "$configurator"
grep -qE '^[[:space:]]*exclude_disk=$' "$configurator" ||
  { echo "Patch did not apply: this installer version differs. Nothing was changed." >&2; exit 1; }

cat <<'EOF'
Installer patched: the boot disk is now selectable.

In the installer choose "Free space install".
Do NOT choose the full-disk install: it wipes every partition on the disk,
including your other OS and the live media this installer runs from.

EOF
read -rp "Press Enter to start the installer, or Ctrl+C to stop. " </dev/tty
exec bash /root/.automated_script.sh </dev/tty
