# Debian GNU/Linux Grub config
# from GLIM

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

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

	echo "Found Debians in ${isopath}"

submenu "Debian GNU/Linux >" "${this_isopath}" --class debian {
this_isopath=$2

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

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

	menuentry "Debian NetInstall ${version} ${arch}" "${isofile}" "${isoname}" --class debian {
		set isofile=$2
		set isoname=$3

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

		echo "Using ${isoname}..."
		loopback loop "${isodev}${isofile}"
		linux (loop)/live/vmlinuz-* findiso=${isofile}
		initrd (loop)/live/initrd.img-*
	}
done

# Live CD
for isofile in ${this_isopath}/debian-live-*.iso; do
	if [ ! -e "$isofile" ]; then break; fi

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

	menuentry "Debian Live ${version} ${arch} ${variant}" "${isofile}" "${isoname}" --class debian {
		set isofile=$2
		set isoname=$3

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

		echo "Using ${isoname}..."
		loopback loop "${isodev}${isofile}"
		linux (loop)/live/vmlinuz-* boot=live findiso=${isofile} components
		initrd (loop)/live/initrd.img-*
	}
done
}

# kill for loop
break
done
