#!/bin/sh

#     DESCRIPTION
#
# Automatically fix Linux MBR.
# Grub or lilo.


#     REQUIRES
#
# fixmbr utility at /sbin/
# fixmbr at isolinux.cfg


#     INFO
# At thim moment see http://ftp.altlinux.org/pub/distributions/ALTLinux/Daedalus/i586/RPMS.daedalus/fixmbr-0.1.0-alt1.noarch.rpm
# Add fixmbr call to /etc/rc.d/rc.sysinit.rescue

NAME="init3-fixmbr"

verbose()
{
    if [ -n "$GLOBAL_VERBOSE" ]; then
        echo "HOOK: $NAME: $@"
    fi
}

CONFIG="/etc/rc.d/rc.sysinit"

verbose "has started"

verbose "add fixmbr to $CONFIG"

if ! [ -f "$CONFIG" ]; then
    verbose "Can't find $CONFIG"
    exit 0;
fi

sed -i -e '/Language fixes/ i\
\
# inserted by HOOK ###########################################\
MBRRESC=/sbin/fixmbr\
if [ -e "$MBRRESC" ] && grep -iwqs fixmbr /proc/cmdline; then\
       action "Restore MBR:" "$MBRRESC" \
       printf "reboot in 10 seconds..."\
       sleep 10 && reboot\
fi\
##############################################################\
\
' "$CONFIG"


verbose "finished"
