if [ x$feature_default_font_path = xy ] ; then
   font=unicode
else
   font=$prefix/font.pf2
fi

if loadfont $font ; then
  set gfxmode=800x600
  set gfxpayload=keep
  insmod efi_gop
  insmod efi_uga
  insmod video_bochs
  insmod video_cirrus
  insmod gfxterm
  insmod png
  insmod jpeg
  # Added as a workaround for #1110759
  echo "Loading bootloader..."
  terminal_output gfxterm
  set scutarius_gfx=y
fi

# Scutarius: the installer theme (build/boot/scutarius-theme.txt, copied as
# theme.txt next to splash.jpg by config/x86.cfg, patch 0010) draws the
# shield-wall background and puts the menu BELOW the artwork, where GRUB's
# default menu box used to cover it. Only on a graphical terminal: gfxmenu
# draws nothing anywhere else. Without the theme, the background with the
# theme's colours as before, the same look as boot/arm64/grub/grub-efi.cfg;
# no Devuan splash on any path (handoff 2026-09-05 G2). Plain colours if the
# image cannot be shown either.
# (GRUB script has no && -- hence the nested ifs.)
# Presence is tested by LOADING splash.jpg, not with -f: GRUB's network
# filesystem lists no directory entries, so -f is false for every file on a
# PXE boot and the theme never loaded there (see boot/arm64/grub/grub-efi.cfg
# for the measurement). splash.jpg ships beside theme.txt; dropped again,
# gfxmenu draws its own.
if [ x$scutarius_gfx = xy ]; then
  if background_image $prefix/splash.jpg; then
    background_image
    if insmod gfxmenu; then
      set scutarius_theme=y
    fi
  fi
fi
if [ x$scutarius_theme = xy ]; then
  set theme=$prefix/theme.txt
  export theme
elif background_image -m stretch $prefix/splash.jpg; then
  set color_normal=light-gray/black
  set color_highlight=white/black
else
  set menu_color_normal=white/black
  set menu_color_highlight=black/light-gray
fi

insmod play
play 960 440 1 0 4 440 1

# Scutarius: put the boot MENU on the serial line as well, and give it a
# timeout so an unattended machine proceeds on its own. --append keeps
# whatever the block above configured (gfxterm where there is a screen).
if serial --unit=0 --speed=115200; then
  terminal_input --append serial
  terminal_output --append serial
fi
# Scutarius: 30 s so the menu can be caught over a KVM or serial line. The
# default is "Install" again (scutarius5/6 defaulted to the expert entry;
# reverted on the owner's ruling 2026-09-06); "... Expert install" stays under
# Advanced options (menu ids from our grub-gencfg patch: advanced>expert).
set timeout=30
set default='install'
menuentry --id=install 'Install' {
    set background_color=black
    echo 'Loading the installer kernel ...'
    linux    /debian-installer/amd64/linux vga=788 --- quiet
    echo 'Loading the initial ramdisk ...'
    initrd   /debian-installer/amd64/initrd.gz
    terminal_output console
}
submenu --hotkey=a --id=advanced 'Advanced options ...' {
    set gfxpayload=keep
    menuentry --id=expert '... Expert install' {
        set background_color=black
        echo 'Loading the installer kernel ...'
        linux    /debian-installer/amd64/linux priority=low vga=788 ---
        echo 'Loading the initial ramdisk ...'
        initrd   /debian-installer/amd64/initrd.gz
        terminal_output console
    }
    menuentry '... Rescue mode' {
        set background_color=black
        echo 'Loading the installer kernel ...'
        linux    /debian-installer/amd64/linux vga=788 rescue/enable=true --- quiet
        echo 'Loading the initial ramdisk ...'
        initrd   /debian-installer/amd64/initrd.gz
        terminal_output console
    }
    menuentry '... Automated install' {
        set background_color=black
        echo 'Loading the installer kernel ...'
        linux    /debian-installer/amd64/linux auto=true priority=critical vga=788 --- quiet
        echo 'Loading the initial ramdisk ...'
        initrd   /debian-installer/amd64/initrd.gz
        terminal_output console
    }
    menuentry --hotkey=x '... Expert install with speech synthesis' {
        set background_color=black
        echo 'Loading the installer kernel ...'
        linux    /debian-installer/amd64/linux priority=low vga=788 speakup.synth=soft ---
        echo 'Loading the initial ramdisk ...'
        initrd   /debian-installer/amd64/initrd.gz
        terminal_output console
    }
    menuentry --hotkey=r '... Rescue mode with speech synthesis' {
        set background_color=black
        echo 'Loading the installer kernel ...'
        linux    /debian-installer/amd64/linux vga=788 rescue/enable=true speakup.synth=soft --- quiet
        echo 'Loading the initial ramdisk ...'
        initrd   /debian-installer/amd64/initrd.gz
        terminal_output console
    }
    menuentry --hotkey=a '... Automated install with speech synthesis' {
        set background_color=black
        echo 'Loading the installer kernel ...'
        linux    /debian-installer/amd64/linux auto=true priority=critical vga=788 speakup.synth=soft --- quiet
        echo 'Loading the initial ramdisk ...'
        initrd   /debian-installer/amd64/initrd.gz
        terminal_output console
    }
    menuentry '... Install (serial console)' {
        set background_color=black
        echo 'Loading the installer kernel ...'
        linux    /debian-installer/amd64/linux vga=788 --- quiet console=tty0 console=ttyS0,115200n8
        echo 'Loading the initial ramdisk ...'
        initrd   /debian-installer/amd64/initrd.gz
        terminal_output console
    }
    menuentry '... Expert install (serial console)' {
        set background_color=black
        echo 'Loading the installer kernel ...'
        linux    /debian-installer/amd64/linux priority=low vga=788 --- console=tty0 console=ttyS0,115200n8
        echo 'Loading the initial ramdisk ...'
        initrd   /debian-installer/amd64/initrd.gz
        terminal_output console
    }
    submenu '... Desktop environment menu ...' {
        set gfxpayload=keep
        submenu '... GNOME desktop boot menu ...' {
            set gfxpayload=keep
            menuentry '... Install' {
                set background_color=black
                echo 'Loading the installer kernel ...'
                linux    /debian-installer/amd64/linux desktop=gnome vga=788 --- quiet
                echo 'Loading the initial ramdisk ...'
                initrd   /debian-installer/amd64/initrd.gz
                terminal_output console
            }
            submenu '... GNOME advanced options ...' {
                set gfxpayload=keep
                menuentry '... Expert install' {
                    set background_color=black
                    echo 'Loading the installer kernel ...'
                    linux    /debian-installer/amd64/linux desktop=gnome priority=low vga=788 ---
                    echo 'Loading the initial ramdisk ...'
                    initrd   /debian-installer/amd64/initrd.gz
                    terminal_output console
                }
                menuentry '... Automated install' {
                    set background_color=black
                    echo 'Loading the installer kernel ...'
                    linux    /debian-installer/amd64/linux desktop=gnome auto=true priority=critical vga=788 --- quiet
                    echo 'Loading the initial ramdisk ...'
                    initrd   /debian-installer/amd64/initrd.gz
                    terminal_output console
                }
                menuentry --hotkey=x '... Expert install with speech synthesis' {
                    set background_color=black
                    echo 'Loading the installer kernel ...'
                    linux    /debian-installer/amd64/linux desktop=gnome priority=low vga=788 speakup.synth=soft ---
                    echo 'Loading the initial ramdisk ...'
                    initrd   /debian-installer/amd64/initrd.gz
                    terminal_output console
                }
                menuentry --hotkey=a '... Automated install with speech synthesis' {
                    set background_color=black
                    echo 'Loading the installer kernel ...'
                    linux    /debian-installer/amd64/linux desktop=gnome auto=true priority=critical vga=788 speakup.synth=soft --- quiet
                    echo 'Loading the initial ramdisk ...'
                    initrd   /debian-installer/amd64/initrd.gz
                    terminal_output console
                }
            }
        }
        submenu '... KDE Plasma desktop boot menu ...' {
            set gfxpayload=keep
            menuentry '... Install' {
                set background_color=black
                echo 'Loading the installer kernel ...'
                linux    /debian-installer/amd64/linux desktop=kde vga=788 --- quiet
                echo 'Loading the initial ramdisk ...'
                initrd   /debian-installer/amd64/initrd.gz
                terminal_output console
            }
            submenu '... KDE Plasma advanced options ...' {
                set gfxpayload=keep
                menuentry '... Expert install' {
                    set background_color=black
                    echo 'Loading the installer kernel ...'
                    linux    /debian-installer/amd64/linux desktop=kde priority=low vga=788 ---
                    echo 'Loading the initial ramdisk ...'
                    initrd   /debian-installer/amd64/initrd.gz
                    terminal_output console
                }
                menuentry '... Automated install' {
                    set background_color=black
                    echo 'Loading the installer kernel ...'
                    linux    /debian-installer/amd64/linux desktop=kde auto=true priority=critical vga=788 --- quiet
                    echo 'Loading the initial ramdisk ...'
                    initrd   /debian-installer/amd64/initrd.gz
                    terminal_output console
                }
                menuentry --hotkey=x '... Expert install with speech synthesis' {
                    set background_color=black
                    echo 'Loading the installer kernel ...'
                    linux    /debian-installer/amd64/linux desktop=kde priority=low vga=788 speakup.synth=soft ---
                    echo 'Loading the initial ramdisk ...'
                    initrd   /debian-installer/amd64/initrd.gz
                    terminal_output console
                }
                menuentry --hotkey=a '... Automated install with speech synthesis' {
                    set background_color=black
                    echo 'Loading the installer kernel ...'
                    linux    /debian-installer/amd64/linux desktop=kde auto=true priority=critical vga=788 speakup.synth=soft --- quiet
                    echo 'Loading the initial ramdisk ...'
                    initrd   /debian-installer/amd64/initrd.gz
                    terminal_output console
                }
            }
        }
        submenu '... LXDE desktop boot menu ...' {
            set gfxpayload=keep
            menuentry '... Install' {
                set background_color=black
                echo 'Loading the installer kernel ...'
                linux    /debian-installer/amd64/linux desktop=lxde vga=788 --- quiet
                echo 'Loading the initial ramdisk ...'
                initrd   /debian-installer/amd64/initrd.gz
                terminal_output console
            }
            submenu '... LXDE advanced options ...' {
                set gfxpayload=keep
                menuentry '... Expert install' {
                    set background_color=black
                    echo 'Loading the installer kernel ...'
                    linux    /debian-installer/amd64/linux desktop=lxde priority=low vga=788 ---
                    echo 'Loading the initial ramdisk ...'
                    initrd   /debian-installer/amd64/initrd.gz
                    terminal_output console
                }
                menuentry '... Automated install' {
                    set background_color=black
                    echo 'Loading the installer kernel ...'
                    linux    /debian-installer/amd64/linux desktop=lxde auto=true priority=critical vga=788 --- quiet
                    echo 'Loading the initial ramdisk ...'
                    initrd   /debian-installer/amd64/initrd.gz
                    terminal_output console
                }
                menuentry --hotkey=x '... Expert install with speech synthesis' {
                    set background_color=black
                    echo 'Loading the installer kernel ...'
                    linux    /debian-installer/amd64/linux desktop=lxde priority=low vga=788 speakup.synth=soft ---
                    echo 'Loading the initial ramdisk ...'
                    initrd   /debian-installer/amd64/initrd.gz
                    terminal_output console
                }
                menuentry --hotkey=a '... Automated install with speech synthesis' {
                    set background_color=black
                    echo 'Loading the installer kernel ...'
                    linux    /debian-installer/amd64/linux desktop=lxde auto=true priority=critical vga=788 speakup.synth=soft --- quiet
                    echo 'Loading the initial ramdisk ...'
                    initrd   /debian-installer/amd64/initrd.gz
                    terminal_output console
                }
            }
        }
    }
}
submenu --hotkey=d 'Accessible dark contrast installer menu ...' {
    set menu_color_normal=white/black
    set menu_color_highlight=yellow/black
    set color_normal=white/black
    set color_highlight=yellow/black
    background_image
    set gfxpayload=keep
    menuentry '... Install' {
        set background_color=black
        echo 'Loading the installer kernel ...'
        linux    /debian-installer/amd64/linux vga=788 theme=dark --- quiet
        echo 'Loading the initial ramdisk ...'
        initrd   /debian-installer/amd64/initrd.gz
        terminal_output console
    }
    submenu --hotkey=a '... Advanced options ...' {
        set menu_color_normal=white/black
        set menu_color_highlight=yellow/black
        set color_normal=white/black
        set color_highlight=yellow/black
        background_image
        set gfxpayload=keep
        menuentry '... Expert install' {
            set background_color=black
            echo 'Loading the installer kernel ...'
            linux    /debian-installer/amd64/linux priority=low vga=788 theme=dark ---
            echo 'Loading the initial ramdisk ...'
            initrd   /debian-installer/amd64/initrd.gz
            terminal_output console
        }
        menuentry '... Rescue mode' {
            set background_color=black
            echo 'Loading the installer kernel ...'
            linux    /debian-installer/amd64/linux vga=788 rescue/enable=true theme=dark --- quiet
            echo 'Loading the initial ramdisk ...'
            initrd   /debian-installer/amd64/initrd.gz
            terminal_output console
        }
        menuentry '... Automated install' {
            set background_color=black
            echo 'Loading the installer kernel ...'
            linux    /debian-installer/amd64/linux auto=true priority=critical vga=788 theme=dark --- quiet
            echo 'Loading the initial ramdisk ...'
            initrd   /debian-installer/amd64/initrd.gz
            terminal_output console
        }
    }
}
