#!/bin/sh

Die() {
    LogIt "Nuke-mode terminated ($1)" 1
    exit 1
}

# ------------------------------ main -----------------------------------

LogIt "nuke-mode --- starting"

if [ -e "/mnt/cdrom/archives/NO-TARBALLS-HERE" ] ; then
    echo "This is Mondo Rescue CD has no tarballs."
    echo "nuke-mode is exiting."
    exit 0
fi

if [ "`cat /proc/cmdline | grep "nukeV"`" != "" ] ; then
    LogIt "Warning - nuke mode (with verify)." 1
elif [ "`cat /proc/cmdline | grep "nuke"`" != "" ]; then
    NUKING=yes
    LogIt "Warning - nuke mode (no verifying)" 1
    LogIt "No verifying" > /tmp/DO-NOT-VERIFY
else
    NUKING=YES
    LogIt "I'm running nuke mode, probably at the user's request" 1
    LogIt "(but not at the boot-time request...)" 1
fi

prep-me || Die "failed to format/prep drives" 1
mount-me || Die "failed to mount destination partitions" 1
restore-me || LogIt "Warning - restoration process returned errors" 1
mkdir -p -m 1777 /mnt/RESTORING/tmp
stablilo-me || Die "LILO failed; try 'lilo -r /mnt/RESTORING && unmount-me'" 1
unmount-me || LogIt "Warning - unable to unmount all destination partitions" 1

label-partitions-as-necessary /tmp/mountlist.txt < /tmp/fstab

LogIt "Syncing." 2
sync
sync
sync

umount /mnt/cdrom
eject /dev/cdrom || LogIt "Unable to eject CD"
LogIt "nuke-mode --- leaving"
exit 0
