#!/bin/sh


LOGFILE=/tmp/mondo-restore.log



if [ "$#" -ne "1" ] ; then
    echo "make-me-bootable <fname>"
    exit 1
fi

HAVE_ACTIVE="false"
for i in `cat $1 | tr -s '\t' ' ' | cut -d' ' -f1 | grep -v "/dev/fd" | grep -v "none" | grep -v "#"` ; do
    mountpt=`cat $1 | grep "$i " | tr -s '\t' ' ' | cut -d' ' -f2`
    format=`cat $1 | grep "$i " | tr -s '\t' ' ' | cut -d' ' -f3`
    drive=`echo $i | sed -e 's/[0-9]*$//' -e 's/\([0-9]\)p$/\1/'`
    partno=`echo $i | sed -e 's/^.*[^0-9]\([0-9]*\)$/\1/'`

    if [ "$HAVE_ACTIVE" = "false" ] && [ "`fdisk -l $drive | tr -s '\t' ' ' | grep "$i " | grep -v "*"`" ] ; then
        if [ "$mountpt" = "/" ] || [ "$mountpt" = "/boot" ] || [ "$format" = "vfat" ] ; then
            LogIt "Making $i bootable (drive=$drive, partno=$partno)"
            echo -e -n "a\n$partno\nw\n" | fdisk $drive >> $LOGFILE 2>> $LOGFILE
#            HAVE_ACTIVE="true"
        fi
    fi
done
exit 0




