#! /bin/sh

set -e

. /usr/share/debconf/confmodule

GRUB_CONFIG=/target/boot/grub/menu.lst
REORDER_TOOL=/target/usr/sbin/reorder-grub.sh

db_get athens-grub-setup/boot_label
XP="${RET}"

if [ -f ${GRUB_CONFIG} ]; then
    if [ `grep -c "${XP}" "${GRUB_CONFIG}"` = 0 ]; then
        # Add grub stanza for XP
        # The '@' in front of the XP recovery is special,
        # the Athens version of grub knows to hide entries
        # with a title that start with '@'.
        cat >> ${GRUB_CONFIG} << EOF

title  	  ${XP}
root	  (hd0,1)
chainloader +1

title	  @${XP} recovery
root	  (hd0,0)
chainloader +1
EOF
    fi

    # Requires athens-config 0.23 or higher, or 0.20.2
    if [ -x ${REORDER_TOOL} ]; then
        ${REORDER_TOOL} ${GRUB_CONFIG}
    fi
fi

exit 0
