#!/bin/bash
set -e

INSTALL_URL="https://git.miasma-os.com/miasma/miasma-installer/releases/latest/download/miasma-installer"
INSTALL_PATH="/usr/local/bin/miasma-installer"

echo "Miasma OS Installer"
echo "==================="
echo ""

if [ "$EUID" -ne 0 ]; then
    echo "Error: This installer must be run as root"
    echo "Please run: sudo curl -fsSL https://install.miasma-os.com | sh"
    exit 1
fi

if [ ! -d "/sys/firmware/efi" ]; then
    echo "Error: UEFI boot mode not detected"
    echo "Miasma OS requires UEFI boot mode"
    exit 1
fi

if ! command -v archinstall &> /dev/null; then
    echo "Installing archinstall..."
    pacman -Sy --noconfirm archinstall
fi

echo "Downloading Miasma installer..."
curl -fsSL "$INSTALL_URL" -o "$INSTALL_PATH"
chmod +x "$INSTALL_PATH"

echo ""
echo "Starting Miasma OS installer..."
echo ""

exec "$INSTALL_PATH"
