# Bodhi Linux Grub Config
# NOTE: As of 5.0.0 the "legacy" image can't mount FAT32 (charset error)

set this_isopath="${isodev}${isopath}/bodhi"

# abuse for to check for existence
for isofile in ${this_isopath}/bodhi-*.iso; do
  if [ ! -e "$isofile" ]; then break; fi

  echo "Found Bodhis in ${this_isopath}"

submenu "Bodhi Linux >" "${this_isopath}" --class bodhi {
this_isopath=$2

for isofile in ${this_isopath}/bodhi-*.iso; do
  if [ ! -e "$isofile" ]; then break; fi

  regexp \
    --set 1:isoname \
    --set 2:version \
    --set 3:variant \
    "^.*/(bodhi-([^-]+)-(.+)\.iso)\$" "${isofile}"

  menuentry "Bodhi ${version} ${variant}" "${isofile}" "${isoname}" --class bodhi {
    set isofile=$2
    set isoname=$3

    regexp \
        --set 1:isodev \
        --set 2:isofile \
        "^(\(.*\))?(.*)\$" "${isofile}"

    echo "Using ${isoname}..."
    loopback loop "${isodev}${isofile}"
    linux (loop)/casper/vmlinuz iso-scan/filename=${isofile} file=/cdrom/preseed/custom.seed boot=casper quiet splash
    initrd (loop)/casper/initrd*
  }
done
}

# kill for loop
break
done
