#!/bin/sh
# grub and other bootloaders that read the filesystem do not support /boot
# on btrfs. (lilo should work). Detect and warn.

# grub2 works now.
ARCH="$(archdetect)"
case $ARCH in
    amd64/*|*-amd64/*|i386/*|*-i386/*)
	exit 0
	;;
esac

. /lib/partman/lib/base.sh

get_btrfs_root_boot () {
	(for i in /lib/partman/fstab.d/*; do
		[ -x "$i" ] || continue
		$i
	done) |
	while read fs mp type options dump pass; do
		if [ "$mp" = / ]; then
			echo root_type=$type
		elif [ "$mp" = /boot ]; then
			echo boot_type=$type
		fi
	done
}
eval "$(get_btrfs_root_boot)"

if [ "$boot_type" = btrfs ]; then
	db_input critical partman-btrfs/btrfs_boot || true
	db_go || exit 1
	exit 1
fi

if [ "$boot_type" = "" ] && [ "$root_type" = btrfs ]; then
	db_input critical partman-btrfs/btrfs_root || true
	db_go || exit 1
	exit 1
fi
