#!/bin/sh

# 02/03/02
# - softlink mondo-restore -> mondorestore if mondorestore exists but m-r not
#
# 12/10/01
# - removed the 'clear' from the start of the script
#
# 12/09/01
# - broke up spaghetti code; made lots of subroutines
# - moved some subroutines to /sbin/init, where they belong
#------------------------------------------------------------


iso=`cat /proc/cmdline | grep "iso"`
nuke=`cat /proc/cmdline | grep "nuke"`
expert=`cat /proc/cmdline | grep "expert"`
compare=`cat /proc/cmdline | grep "compare"`
interactive=`cat /proc/cmdline | grep "interactive"`
which mondorestore > /dev/null2 >/dev/null && ln -s `which mondorestore` /usr/bin/mondo-restore
if which mondo-restore > /dev/null 2> /dev/null ; then
    LogIt "mondo-restore found; cool..."
else
    if [ "$iso$nuke$compare$interactive" != "" ] ; then
	LogIt "This CD was made by Mindi, not Mondo. You cannot use" 1
	LogIt "this CD for restoring data from backups. Sorry." 1
#	exit 1
    else
	LogIt "Mindi-Linux has finished booting."
    fi
fi

sleep 1

if [ -h "`which mondo-restore`" ] ; then
    LogIt "Turning mondo-restore from a hyperlink into an executable"
    cp -f `which mondo-restore` /usr/bin/MR
    rm -f `which mondo-restore`
    mv /usr/bin/MR /usr/bin/mondo-restore
fi

if which bootstrap > /dev/null 2> /dev/null ; then
    LogIt "Calling bootstrap script" 1
    bootstrap
fi

if [ "$iso" ] ; then
    LogIt "--------------------ISO MODE-------------------" 1
    mondo-restore --iso
elif [ "$compare" ] ; then
    LogIt "------------------COMPARE MODE-----------------" 1
    mondo-restore --compare
elif [ "$nuke" ] ; then
    LogIt "-------------------NUKE MODE-------------------" 1
    mondo-restore --nuke
elif [ "$expert" ] ; then
    if [ "`cat /tmp/mondo-restore.cfg | grep tapedev`" ] ; then
	LogIt "-------------------TAPE MODE-------------------" 1
	loc=`which mondo-restore 2> /dev/null`
	if [ "$loc" = "" ] ; then
	    LogIt "I presume you backed up with Mindi, not Mondo." 1
	else
	    LogIt "Tape Mode -- calling mondo-restore..."
            if [ "$nuke" ] ; then
                mondo-restore --nuke
            else
	        mondo-restore; # MR will detect & access the tape
            fi
	fi
    elif [ "`cat /tmp/mondo-restore.cfg | grep using-cdstream`" ] ; then
        LogIt "------------------CDSTREAM MODE------------------" 1
        loc=`which mondo-restore 2> /dev/null`
        if [ "$loc" = "" ] ; then
            LogIt "I presume you backed up with Mindi, not Mondo." 1
        else
            LogIt "Cdstream Mode -- calling mondo-restore..."
            if [ "$nuke" ] ; then
                mondo-restore --nuke
            else
                mondo-restore; # MR will detect & access the cdstream
            fi
        fi
    else
	LogIt "------------------EXPERT MODE------------------" 1
	LogIt "You do all the work. :-)" 1
	which mondo-restore > /dev/null 2> /dev/null && LogIt "Type 'mondo-restore' to begin the restore/compare process." 1
	loc=`which ISO 2> /dev/null`
	if [ "$loc" != "" ] ; then
	    LogIt "Or, if you want to restore from ISO images, type 'ISO'." 1
	fi
    fi
else
    LogIt "------------------INTERACTIVE------------------" 1
    mondo-restore --interactive
fi


