#!/bin/sh
# Check that there is an HFS filesystem mounted to /boot/grub

ARCH="$(archdetect)"

case $ARCH in
    powerpc/powermac_newworld|ppc64/powermac_newworld)
	;;
    *)
	exit 0
	;;
esac

. /lib/partman/lib/base.sh

for dev in $DEVICES/*; do
	[ -d "$dev" ] || continue
	cd $dev
	open_dialog PARTITIONS
	while { read_line num id size type fs path name; [ "$id" ]; }; do
		[ "$fs" != free ] || continue
		[ -f $id/method ] || continue
		[ -f $id/acting_filesystem ] || continue
		[ -f $id/mountpoint ] || continue
		mountpoint=$(cat $id/mountpoint)
		filesystem=$(cat $id/acting_filesystem)
		if [ "$mountpoint" = /boot/grub ]; then
			boot_fs=$filesystem
			boot_type=$type
			boot_path=$path
			if [ -f $id/bootable ]; then
				boot_bootable=yes
			fi
		fi
	done
	close_dialog
done

# We need an HFS filesystem mounted to /boot/grub
if [ "$boot_fs" != hfs ] ; then
	db_set partman-hfs/boot_not_hfs true
	db_input critical partman-hfs/boot_not_hfs || true
	db_go || true
	db_get partman-hfs/boot_not_hfs
	if [ "$RET" = true ]; then
		exit 1
	fi
fi
