for isofile in $isopath/tails-i386-*.iso; do
  if [ -e "$isofile" ]; then
    regexp --set=isoname "$isopath/(.*)" "$isofile"
    submenu "$isoname ->" "$isofile" {
      iso_path="$2"
      loopback loop "$iso_path"
      menuentry "Live" {
        bootoptions="findiso=$iso_path boot=live config apparmor=1 security=apparmor nopersistence noprompt timezone=Etc/UTC block.events_dfl_poll_msecs=1000 splash noautologin module=Tails kaslr slab_nomerge slub_debug=FZ mce=0 vsyscall=none  quiet"
        if cpuid -l; then # Check whether CPU is 64-bit
          linux (loop)/live/vmlinuz2 $bootoptions
          initrd (loop)/live/initrd2.img
        else
          linux (loop)/live/vmlinuz $bootoptions
          initrd (loop)/live/initrd.img
        fi
      }
      menuentry "Live (failsafe)" {
        bootoptions="findiso=$iso_path boot=live config apparmor=1 security=apparmor nopersistence noprompt timezone=Etc/UTC block.events_dfl_poll_msecs=1000 splash noautologin module=Tails kaslr slab_nomerge slub_debug=FZ mce=0 vsyscall=none  noapic noapm nodma nomce nolapic nomodeset nosmp vga=normal"
        if cpuid -l; then # Check whether CPU is 64-bit
          linux (loop)/live/vmlinuz2 $bootoptions
          initrd (loop)/live/initrd2.img
        else
          linux (loop)/live/vmlinuz $bootoptions
          initrd (loop)/live/initrd.img
        fi
      }
    }
  fi
done
