# Ubuntu Grub Config


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

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

	echo "Found Ubuntus in ${this_isopath}"

submenu "Ubuntu >" "${this_isopath}" --class ubuntu {
this_isopath=$2

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

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

	menuentry "Ubuntu ${version} ${arch} ${variant}" "${isofile}" "${isoname}" --class ubuntu {
		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 boot=casper iso-scan/filename=${isofile} quiet splash
		initrd (loop)/casper/initrd*
	}
done
}

# kill for loop
break
done
