# Tails Grub config
# from GLIM

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

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

	echo "Found Tailses in ${this_isopath}"

submenu "Tails" "${this_isopath}" --class tails {
this_isopath=$2

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

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

	menuentry "Tails ${version} ${arch}" "${isofile}" "${isoname}" --class tails {
		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 live-media=removable findiso=${isofile} config apparmor=1 security=apparmor nopersistence noprompt timezone=Etc/UTC block.events_dfl_poll_msecs=1000 splash noautologin module=Tails kaslr slab_nomerge slub_debug=FZP mce=0 vsyscall=none page_poison=1 quiet
		initrd (loop)/live/initrd.img
	}
done

}

# kill for loop
break
done
