# Alpine Linux Grub config


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

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

	echo "Found Alpines in ${this_isopath}"

submenu "Alpine Linux >" "${this_isopath}" --class alpine {
this_isopath=$2

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

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

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

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

		echo "Using ${isoname}..."
		loopback loop "${isodev}${isofile}"
		linux (loop)/boot/vmlinuz-lts iso-scan/filename=${isofile} alpine_dev=usbdisk:vfat modules=loop,squashfs,cramfs,sd-mod,usb-storage
		initrd (loop)/boot/initramfs-lts
	}
done

}

# kill for loop
break
done
