#! /bin/sh -e
# grub-mkconfig helper script
# Copyright (c) 2008-2013 by Silvan Calarco

prefix=/usr
exec_prefix=/usr
datarootdir="${prefix}/share"
. "${datarootdir}/grub/grub-mkconfig_lib"


if [ ! -e /etc/sysconfig/grub ]; then
   [ -e /root/.installer.conf ] && . /root/.installer.conf
   cat > /etc/sysconfig/grub << _EOF
GRUB_OTHER_DEVICES=(${INSTALL_BOOTLOADER_CHAINLOAD[*]})
_EOF
fi
. /etc/sysconfig/grub

for d in `seq 1 ${#GRUB_OTHER_DEVICES[*]}`; do
   TITLE=${GRUB_OTHER_TITLES[$d-1]}
   [ "$TITLE" ] || TITLE="Windows"
   echo "Adding other O.S. entry: $TITLE on ${GRUB_OTHER_DEVICES[$d-1]}" >&2
   cat << _EOF
menuentry "$TITLE" {
_EOF
   save_default_entry | sed -e "s/^/\t/"
   cat << _EOF
        set root='`grub-probe --device ${GRUB_OTHER_DEVICES[$d-1]} --target drive`'
	chainloader +1
}
_EOF
done
