#! /bin/bash

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

set -a

if [ -r $LOGDIR/disk_var.sh ] ; then
  . $LOGDIR/disk_var.sh
else
  echo "disk_var.sh not found!"
  exit 0
fi

# 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

$ROOTCMD grub-install --no-floppy $(device2grub $BOOT_DEVICE)
GROOT=$(device2grub $BOOT_PARTITION)
perl -pi -e 's/#(\w+)#/$ENV{$1}/g' $2
$ROOTCMD /usr/sbin/update-grub
echo "Grub installed on $BOOT_DEVICE on $GROOT"

exit $error

