+
+ # make sure this is pre-defined so we have sane settings for automated
+ # upgrades, see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=711019
+ echo "Setting ${GRUB_PACKAGE} debconf configuration for install device to $GRUB"
+ echo "${GRUB_PACKAGE} ${GRUB_PACKAGE}/install_devices multiselect $GRUB" | debconf-set-selections
+
+ if ! dpkg --list ${GRUB_PACKAGE} 2>/dev/null | grep -q '^ii' ; then
+ echo "Notice: grub option set but no ${GRUB_PACKAGE} package, installing it therefore."
+ DEBIAN_FRONTEND=$DEBIAN_FRONTEND $APTINSTALL ${GRUB_PACKAGE}
+ fi
+
+ if ! [ -x "$(command -v grub-install)" ] ; then
+ echo "Error: grub-install not available. (Error while installing grub package?)" >&2
+ return 1
+ fi
+
+ if [ -n "$SELECTED_PARTITIONS" ] ; then # using sw-raid
+ for device in $SELECTED_PARTITIONS ; do
+ GRUB="${device%%[0-9]}"
+ echo "Installing grub on ${GRUB}:"
+ if ! grub-install --no-floppy "$GRUB" ; then
+ echo "Error: failed to execute 'grub-install --no-floppy $GRUB'." >&2
+ exit 1
+ fi
+
+ done
+ rm -f /boot/grub/device.map
+ else
+ echo "Installing grub on ${GRUB}:"
+ case "$RELEASE" in
+ lenny|squeeze|wheezy)
+ local grub_dev
+ grub_dev="$(readlink -f "${GRUB}")"
+ if ! grub-install --no-floppy "${grub_dev}" ; then
+ echo "Error: failed to execute 'grub-install --no-floppy ${grub_dev}'." >&2
+ exit 1
+ fi
+ rm -f /boot/grub/device.map
+ ;;
+ *)
+ echo "(hd0) ${GRUB}" > /boot/grub/device.map
+ if ! grub-install "(hd0)" ; then
+ echo "Error: failed to execute 'grub-install (hd0)'." >&2
+ exit 1
+ fi
+ rm /boot/grub/device.map
+ ;;
+ esac
+ fi
+
+ echo "Adjusting grub configuration for use on ${GRUB}."
+
+ # finally install grub
+ if [ -x /usr/sbin/update-grub ] ; then
+ UPDATEGRUB='/usr/sbin/update-grub'
+ elif [ -x /sbin/update-grub ] ; then
+ UPDATEGRUB='/sbin/update-grub'
+ else
+ echo "Error: update-grub not available, can not execute it." >&2
+ return 1
+ fi
+
+ if [ -n "${BOOT_APPEND}" ] ; then
+ echo "Adding BOOT_APPEND configuration ['${BOOT_APPEND}'] to /etc/default/grub."
+ sed -i "/GRUB_CMDLINE_LINUX_DEFAULT/ s#\"\$# ${BOOT_APPEND}\"#" /etc/default/grub
+ fi
+
+ mountpoint /boot/efi &>/dev/null && umount /boot/efi
+
+ $UPDATEGRUB