#!/bin/sh
. /usr/share/debconf/confmodule

log() {
	logger -t grub-installer "$@"
}

ARCH="$(archdetect)"

case $ARCH in
    i386/mac|amd64/mac)
	# Note: depends on partman-efi to load the efivars module!
	if [ -d /sys/firmware/efi ]; then
		log "GRUB not yet usable on Intel-based Macs booted using EFI"
		exit 1
	fi
	;;
    powerpc/chrp|powerpc/chrp_rs6k|powerpc/chrp_ibm|powerpc/cell)
	;;
    powerpc/*)
	mount | grep "on /target/boot/grub" 1>&2 || {
		log "GRUB requires OF bootable partition mounted at /boot/grub on PowerPC systems"
		exit 1
	}
	;;
    mipsel/loongson-2f)
	;;
    mipsel/*)
	log "GRUB not yet usable on MIPS systems other than Yeeloong"
	exit 1
	;;
    arm64/efi)
	;;
    arm64/*)
	log "GRUB is only usable on EFI arm64 systems, not $ARCH"
	exit 1
	;;
esac

db_get grub-installer/skip
if [ "$RET" = true ]; then
	exit 1
fi

exit 0
