# Kali Grub config
# from GLIM

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

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

	echo "Found Kali Linuxes in ${this_isopath}"

submenu "Kali Linux >" "${this_isopath}" --class kali {
this_isopath=$2

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

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

	menuentry "Kali ${version} ${arch}" "${isofile}" "${isoname}" --class kali {
		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-*-amd64 fromiso=${isofile} boot=live components splash username=root hostname=kali
		initrd (loop)/live/initrd.img-*-amd64
	}
	menuentry "Kali ${version} ${arch} (forensic mode)" "${isofile}" "${isoname}" --class kali {
		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-*-amd64 fromiso=${isofile} boot=live components splash username=root hostname=kali noswap noautomount
		initrd (loop)/live/initrd.img-*-amd64
	}
done

}

# kill for loop
break
done
