export GRUB_TERMINAL
export GRUB_SERIAL_COMMAND
if [ -n "$GRUB_TERMINAL" ]; then
  $GRUB_SERIAL_COMMAND
  terminal_output "$GRUB_TERMINAL"
  terminal_input "$GRUB_TERMINAL"
fi

insmod echo
insmod gzio
insmod minicmd
insmod normal
insmod test
set timeout=60
if [ ! "$lang" ]; then lang=en_US; fi
if [ -s $pfxfat/grubenv ]; then
  load_env --file $pfxfat/grubenv
  set default="${saved_entry}"
else
  set default=live
fi
function savedefault {
  if [ -z "${boot_once}" -a -s $pfxfat/grubenv ]; then
    saved_entry="${chosen}"
    save_env --file $pfxfat/grubenv saved_entry
  fi
}
function load_video {
  if [ x$feature_all_video_module = xy ]; then
    insmod all_video
  else
    insmod efi_gop
    insmod efi_uga
    insmod ieee1275_fb
    insmod vbe
    insmod vga
    insmod video_bochs
    insmod video_cirrus
  fi
}

if [ -z "$GRUB_TERMINAL" ]; then
  font=unicode
  if loadfont "$font"; then
    set gfxmode=auto
    load_video
    insmod gfxterm
    terminal_output gfxterm
    if [ -d ${prefix}/locale ]; then
      set locale_dir=${prefix}/locale
      insmod gettext
    fi
    insmod gfxmenu
    insmod jpeg
    insmod png
    if [ -f ${prefix}/themes/sisyphus/theme.txt ]; then
      set theme=${prefix}/themes/sisyphus/theme.txt;
      export theme
    fi
    set timeout_style=menu
    set menu_color_normal=white/black
    set menu_color_highlight=black/white
    set color_normal=white/black
    set color_highlight=black/white
  fi
fi
if [ "$grub_platform" = "pc" ]; then
  menuentry $"Boot from hard drive" --id 'harddisk' {
    insmod part_msdos
    insmod chain
    set oldroot="$root"
    if [ "$root" = hd0 ]
    then set root=(hd1)
    else set root=(hd0)
    fi
    chainloader +1
    set root="$oldroot"
  }
fi

menuentry $"Install "'ALT regular-mate/x86_64' --hotkey 'i' --id 'linux' {
  savedefault
  echo $"Loading Linux vmlinuz$KFLAVOUR ..."
  linux /boot/vmlinuz$KFLAVOUR fastboot live root=bootchain bootchain=fg,altboot automatic=method:disk,uuid:2024-10-23-03-24-33-00 stagename=live init=/usr/sbin/install2-init ramdisk_size=1406737 lowmem quiet splash lang=$lang
  echo $"Loading initial ramdisk ..."
  initrd /boot/initrd$KFLAVOUR.img
}
menuentry $"LiveCD (no hard disk needed)" --id 'live' {
  savedefault
  echo $"Loading Linux vmlinuz$KFLAVOUR ..."
  linux /boot/vmlinuz$KFLAVOUR fastboot live root=bootchain bootchain=fg,altboot automatic=method:disk,uuid:2024-10-23-03-24-33-00 stagename=live ramdisk_size=1406737 lowmem quiet splash lang=$lang
  echo $"Loading initial ramdisk ..."
  initrd /boot/initrd$KFLAVOUR.img
}


menuentry $"LiveCD with sessions support" --id 'session' {
  savedefault
  echo $"Loading Linux vmlinuz$KFLAVOUR ..."
  linux /boot/vmlinuz$KFLAVOUR fastboot live root=bootchain bootchain=fg,altboot automatic=method:disk,uuid:2024-10-23-03-24-33-00 stagename=live ramdisk_size=1406737 live_rw quiet splash lang=$lang
  echo $"Loading initial ramdisk ..."
  initrd /boot/initrd$KFLAVOUR.img
}
submenu $"Change language (press F2)" --hotkey 'f2' --id 'lang' {
	insmod regexp
	for langstr in \
		"ru_RU=Russian" \
		"en_US=English" \
		"pt_BR=Portuguese" \
		"uk_UA=Ukrainian" \
		"uz_UZ=Uzbek" \
		"ky_KG=Kyrgyz" \
		"kk_KZ=Kazakh" \
		; do
		regexp -s 2:langname -s 1:langcode '(.*)=(.*)' "$langstr"
		for locale in en_US ru_RU pt_BR; do
			if [ "$locale" != "$langcode" ]; then continue; fi
			menuentry "${langname}" "$langcode" {
				lang="$2"
				export lang
				configfile ${prefix}/grub.cfg
			}
		done
	done
	menuentry $"Return to the Main menu" {
		configfile ${prefix}/grub.cfg
	}
}
if [ "$grub_platform" = "pc" ]; then
  menuentry $"Memory Test" --id 'memtest' {
    linux /boot/memtest.bin
  }
fi
if [ "$grub_platform" = "efi" ]; then
  menuentry $"Memory Test (may not work with Secure Boot)" --id 'memtest' {
    linux /boot/memtest.efi
  }
fi
if [ "$grub_platform" = "efi" ]; then
  menuentry $"UEFI Shell (may not work with Secure Boot)" --id 'efishell' {
    chainloader /boot/shell.efi
  }
fi
if [ "$grub_platform" = "efi" ]; then
	menuentry $"UEFI Firmware Settings" --id 'uefi-firmware' {
		fwsetup
	}
fi
