# GRUB CONF

# Load partition table and file system modules
insmod part_gpt
insmod part_msdos
insmod fat
insmod iso9660
insmod ntfs
insmod ntfscomp
insmod exfat
insmod udf

if [ -s $prefix/grubenv ]; then
 load_env
fi

function load_video {
    if [ x$feature_all_video_module = xy ]
    then
        insmod all_video
    else
        insmod video_bochs
        insmod video_cirrus
        if test "${grub_platform}" == "efi"
        then
            insmod efi_gop
            insmod efi_uga
        elif test "${grub_platform}" == "pc"
        then
            insmod vbe
            insmod vga
        fi
    fi
}

# Use graphics-mode output
insmod font
if loadfont /boot/grub/unicode.pf2
then
    set gfxmode="1920x1200,1920x1080,1600x1200,1600x1080,1600x900,1440x900,1366x768,1366x720,1360x766,1360x720,1280x1024,1024x768,800x600,640x480,auto"
    set gfxpayload="1920x1200,1920x1080,1600x1200,1600x1080,1600x900,1440x900,1366x768,1366x720,1360x766,1360x720,1280x1024,1024x768,800x600,640x480,auto"
    export gfxmode
    export gfxpayload
    load_video
    insmod gfxterm
    terminal_input console
    terminal_output gfxterm
    insmod gfxmenu
    insmod png
    insmod gettext
    loadfont /boot/grub/fonts/terminus-12.pf2
    loadfont /boot/grub/fonts/terminus-14.pf2
    loadfont /boot/grub/fonts/terminus-16.pf2
    loadfont /boot/grub/fonts/terminus-18.pf2
    loadfont /boot/grub/fonts/terminus-b12.pf2
    loadfont /boot/grub/fonts/terminus-b14.pf2
    loadfont /boot/grub/fonts/terminus-b16.pf2
    loadfont /boot/grub/fonts/terminus-b18.pf2
    set theme=/boot/grub/themes/melawy-linux/theme.txt
    export theme
else
    terminal_input console
    terminal_output console
fi

if [ x$feature_timeout_style = xy ]; then
    set timeout_style=menu
fi

set color_normal=white/black
set color_highlight=black/light-gray
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
set timeout=15

set default=0

# Enable serial console
insmod serial
insmod usbserial_common
insmod usbserial_ftdi
insmod usbserial_pl2303
insmod usbserial_usbdebug
if serial --unit=0 --speed=115200
then
    terminal_input --append serial
    terminal_output --append serial
fi

# Menu entries
menuentry "Melawy Linux (Open-Source Drivers)" --class arch --class gnu-linux --class gnu --class os --id 'Melawy Linux' {
    load_video
    set gfxpayload=keep
    linux /%INSTALL_DIR%/boot/x86_64/vmlinuz-linux-cachyos archisobasedir=%INSTALL_DIR% archisosearchuuid=%ARCHISO_UUID% cow_spacesize=10G copytoram=auto module_blacklist=nvidia,nvidia_modeset,nvidia_uvm,nvidia_drm,pcspkr nouveau.modeset=1 i915.modeset=1 radeon.modeset=1 nvme_load=yes add_efi_memmap quiet splash bgrt_disable
    initrd /%INSTALL_DIR%/boot/x86_64/initramfs-linux-cachyos.img
}

menuentry "Melawy Linux (Nvidia Drivers. Video card Nvidia GTX 900+)" --class arch --class gnu-linux --class gnu --class os --id 'Melawy Linux with Nvidia' {
    load_video
    set gfxpayload=keep
    linux /%INSTALL_DIR%/boot/x86_64/vmlinuz-linux-cachyos archisobasedir=%INSTALL_DIR% archisosearchuuid=%ARCHISO_UUID% cow_spacesize=10G copytoram=auto nvidia nvidia-drm.modeset=1 nvidia-drm.fbdev=1 nouveau.modeset=0 i915.modeset=1 radeon.modeset=1 nvme_load=yes module_blacklist=pcspkr add_efi_memmap quiet splash bgrt_disable
    initrd /%INSTALL_DIR%/boot/x86_64/initramfs-linux-cachyos.img
}

menuentry "Melawy Linux (Safe mode graphics)" --class arch --class gnu-linux --class gnu --class os --id 'Melawy Linux with safe mode graphics' {
    load_video
    set gfxpayload=keep
    linux /%INSTALL_DIR%/boot/x86_64/vmlinuz-linux-cachyos archisobasedir=%INSTALL_DIR% archisosearchuuid=%ARCHISO_UUID% cow_spacesize=10G copytoram=auto module_blacklist=nvidia,nvidia_modeset,nvidia_uvm,nvidia_drm nomodeset nvme_load=yes add_efi_memmap quiet splash bgrt_disable
    initrd /%INSTALL_DIR%/boot/x86_64/initramfs-linux-cachyos.img
}

menuentry "Melawy Linux (Without graphics options)" --class arch --class gnu-linux --class gnu --class os --id 'Melawy Linux without graphics options' {
    load_video
    set gfxpayload=keep
    linux /%INSTALL_DIR%/boot/x86_64/vmlinuz-linux-cachyos archisobasedir=%INSTALL_DIR% archisosearchuuid=%ARCHISO_UUID% cow_spacesize=10G copytoram=auto nvme_load=yes add_efi_memmap quiet splash bgrt_disable
    initrd /%INSTALL_DIR%/boot/x86_64/initramfs-linux-cachyos.img
}

menuentry "Melawy Linux (Speech)" --hotkey s --class arch --class gnu-linux --class gnu --class os --id 'Melawy Linux accessibility' {
    set gfxpayload=800x600,1024x768,1366x768,1920x1080
    linux /%INSTALL_DIR%/boot/x86_64/vmlinuz-linux-cachyos archisobasedir=%INSTALL_DIR% archisosearchuuid=%ARCHISO_UUID% accessibility=on
    initrd /%INSTALL_DIR%/boot/x86_64/initramfs-linux-cachyos.img
}

if [ "${grub_platform}" == 'efi' -a "${grub_cpu}" == 'x86_64' -a -f '/boot/memtest86+/memtest.efi' ]; then
    menuentry 'Run Memtest86+ (RAM test)' --class memtest86 --class memtest --class gnu --class tool {
        set gfxpayload=800x600,1024x768
        linux /boot/memtest86+/memtest.efi
    }
fi

if [ "${grub_platform}" == 'pc' -a -f '/boot/memtest86+/memtest' ]; then
    menuentry 'Run Memtest86+ (RAM test)' --class memtest86 --class memtest --class gnu --class tool {
        set gfxpayload=800x600,1024x768
        linux /boot/memtest86+/memtest
    }
fi

if [ "${grub_platform}" == 'efi' ]; then
    if [ "${grub_cpu}" == 'x86_64' -a -f '/shellx64.efi' ]; then
        menuentry 'UEFI Shell' --class efi {
            chainloader /shellx64.efi
        }
    elif [ "${grub_cpu}" == "i386" -a -f '/shellia32.efi' ]; then
        menuentry 'UEFI Shell' --class efi {
            chainloader /shellia32.efi
        }
    fi
    menuentry 'Boot from next volume' {
        exit
    }
    menuentry 'UEFI Firmware Settings' --id 'uefi-firmware' {
        fwsetup
    }
fi

menuentry 'System restart' --class reboot --class restart {
    echo 'System rebooting...'
    reboot
}

menuentry 'System shutdown' --class shutdown --class poweroff {
    echo 'System shutting down...'
    halt
}