#! /bin/bash

error=0 ; trap "error=$((error|1))" ERR

set -a

# during softupdate use this file
[ -r $target/var/log/fai/disk_var.sh ] && . $target/var/log/fai/disk_var.sh

# if class NOMBR is defined, write boot loader into root partition, not into mbr
ifclass NOMBR && BOOT_DEVICE=$BOOT_PARTITION

[ -z "$BOOT_DEVICE" ]    && exit 701
[ -z "$BOOT_PARTITION" ] && exit 702

grub-install --no-floppy --root-directory=$target $BOOT_DEVICE
GROOT=$(device2grub $BOOT_PARTITION)
$ROOTCMD /usr/sbin/update-grub -y

ainsl -s $target/etc/kernel-img.conf  'postinst_hook = update-grub'
ainsl -s $target/etc/kernel-img.conf  'postrm_hook = update-grub'

echo "Grub installed on $BOOT_DEVICE on $GROOT"

exit $error

