for isofile in $isopath/systemrescuecd-*.iso; do
  if [ -e "$isofile" ]; then
    regexp --set=isoname "$isopath/(.*)" "$isofile"
    submenu "$isoname ->" "$isofile" {
      iso_path="$2"
      loopback loop "$iso_path"
      menuentry "Default boot options" {
        bootoptions="isoloop=$iso_path scandelay=1"
        if cpuid -l; then # Check whether CPU is 64-bit
          linux (loop)/isolinux/rescue64 $bootoptions
        else
          linux (loop)/isolinux/rescue32 $bootoptions
        fi
        initrd (loop)/isolinux/initram.igz
      }
      menuentry "All files cached to memory (docache)" {
        bootoptions="isoloop=$iso_path docache"
        if cpuid -l; then # Check whether CPU is 64-bit
          linux (loop)/isolinux/rescue64 $bootoptions
        else
          linux (loop)/isolinux/rescue32 $bootoptions
        fi
        initrd (loop)/isolinux/initram.igz
      }
      menuentry "Framebuffer console in high resolution" {
        bootoptions="isoloop=$iso_path nomodeset vga=791"
        if cpuid -l; then # Check whether CPU is 64-bit
          linux (loop)/isolinux/rescue64 $bootoptions
        else
          linux (loop)/isolinux/rescue32 $bootoptions
        fi
        initrd (loop)/isolinux/initram.igz
      }
      menuentry "Do not ask for keyboard, use US keymap" {
        bootoptions="isoloop=$iso_path setkmap=us"
        if cpuid -l; then # Check whether CPU is 64-bit
          linux (loop)/isolinux/rescue64 $bootoptions
        else
          linux (loop)/isolinux/rescue32 $bootoptions
        fi
        initrd (loop)/isolinux/initram.igz
      }
      menuentry "Boot an existing Linux system installed on the disk" {
        bootoptions="isoloop=$iso_path root=auto"
        if cpuid -l; then # Check whether CPU is 64-bit
          linux (loop)/isolinux/rescue64 $bootoptions
        else
          linux (loop)/isolinux/rescue32 $bootoptions
        fi
        initrd (loop)/isolinux/initram.igz
      }
      menuentry "Alternative kernel with default boot options" {
        bootoptions="isoloop=$iso_path scandelay=1"
        if cpuid -l; then # Check whether CPU is 64-bit
          linux (loop)/isolinux/altker64 $bootoptions
        else
          linux (loop)/isolinux/altker32 $bootoptions
        fi
        initrd (loop)/isolinux/initram.igz
      }
      menuentry "Directly start the graphical environment" {
        bootoptions="isoloop=$iso_path dostartx"
        if cpuid -l; then # Check whether CPU is 64-bit
          linux (loop)/isolinux/rescue64 $bootoptions
        else
          linux (loop)/isolinux/rescue32 $bootoptions
        fi
        initrd (loop)/isolinux/initram.igz
      }
      submenu "System Tools ->" {
        menuentry "MEMTEST: Memory test using Memtest86+" {
          bootoptions="-"
          linux16 (loop)/bootdisk/memtestp $bootoptions
        }
        menuentry "NTPASSWD: Reset or edit Windows passwords" {
          bootoptions="rw vga=1 initrd=/ntpasswd/scsi.cgz"
          linux (loop)/ntpasswd/vmlinuz $bootoptions
          initrd (loop)/ntpasswd/initrd.cgz
        }
        menuentry "FreeDOS: Clone of the MSDOS Operating System" {
          bootoptions="floppy"
          linux16 (loop)/isolinux/memdisk $bootoptions
          initrd16 (loop)/bootdisk/freedos.img
        }
        menuentry "HDT: recent hardware diagnostics tool" {
          bootoptions="floppy"
          linux16 (loop)/isolinux/memdisk $bootoptions
          initrd16 (loop)/bootdisk/hdt.img
        }
        menuentry "MHDD: Low-level Hard Drive diagnostic tool" {
          bootoptions="floppy"
          linux16 (loop)/isolinux/memdisk $bootoptions
          initrd16 (loop)/bootdisk/mhdd.img
        }
        menuentry "NETBOOT: Boot from the network" {
          bootoptions="-"
          linux16 (loop)/isolinux/netboot $bootoptions
        }
      }
    }
  fi
done
