# This is the ArchLinux Grub config
# from GLIM

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

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

	echo "Found Arches in ${this_isopath}"

submenu "ArchLinux >" "${this_isopath}" --class arch {
this_isopath=$2

menuentry "ArchLinux BIOS netboot" --class arch {
	echo "Booting ArchLinux BIOS netboot"
	linux16 ${this_isopath}/ipxe.419cd003a298.lkrn
}

if [ ${grub_platform} == "efi" ]; then
	menuentry "ArchLinux EFI netboot" --class arch {
		echo "Booting ArchLinux EFI netboot"
		chainloader ${this_isopath}/ipxe.176077d7fccb.efi
	}
fi

menuentry "" { true }

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

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

	menuentry "Arch Linux ${version} ${arch}" "${isofile}" "${isoname}" --class arch {
		set isofile=$2
		set isoname=$3

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

		echo "Using ${isoname}..."
		loopback loop "${isodev}${isofile}"
		linux (loop)/arch/boot/x86_64/vmlinuz-linux img_dev=/dev/disk/by-uuid/${rootuuid} img_loop=${isofile}
		initrd (loop)/arch/boot/intel-ucode.img (loop)/arch/boot/amd-ucode.img (loop)/arch/boot/x86_64/initramfs-linux.img
	}
done

}	

# kill for loop
break
done
