#
# DESCRIPTION
#
#     LiveBackup root directory should be 
#     available in $MEDIA_MNT/
#     Determine format of system image 
#     (in $MEDIA_MNT/system) and its size (kB)
#
# ToDo:
#
#       provide an option to check a md5 sum
#
# part of the LiveBackup project:  
#
#                     http://livebackup.sourceforge.net/
#
# Copyright 2006 by Wolfgang Rohrmoser <info@rohrmoser-engineering.de>
#
#    This program is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with this program; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#

image_format=""
image_size=""

if [ "$(echo $SYSTEM | grep -e '^/dev/')" ]; then
    if [ -b $SYSTEM ]; then
	image_format="blockdevice"
	if [ "$COPY2RAM" != "no" ]; then 
            # never try to copy a block device into RAM
	    msg -w "copy2ram disabled for root fs on block device!"
	    COPY2RAM="no"
	fi
    fi
fi

while [ ! "$image_format" ]; do

    if [ -d $MEDIA_MNT/system/$SYSTEM ]; then
	image_format="directory"
        image_size=$(du -s -k -L $MEDIA_MNT/system/$SYSTEM | awk '{print $1}')
    else if [ -f $MEDIA_MNT/system/$SYSTEM.sqsh ]; then 
	image_format="squashfs"
        image_size=$(du -k -L $MEDIA_MNT/system/$SYSTEM.sqsh | awk '{print $1}')
    else if [ -f $MEDIA_MNT/system/$SYSTEM.cloop ]; then
	image_format="cloop"
        image_size=$(du -k -L $MEDIA_MNT/system/$SYSTEM.cloop | awk '{print $1}')
    else if [ -f $MEDIA_MNT/system/$SYSTEM.img ]; then
	image_format="diskimage"
        image_size=$(du -k -L $MEDIA_MNT/system/$SYSTEM.img | awk '{print $1}')
    fi fi fi fi

    if [ $LB_DEBUG -gt 3 ]; then 
	msg -w "detected $MEDIA_MNT/system/$SYSTEM of format $image_format";
    fi

    if [ ! $image_format ]; then
	ls $MEDIA_MNT/system
	msg -c "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	msg -c "ERROR: could not find $SYSTEM[.sqsh|.cloop|.img]  "
	msg -c "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	rescue_shell "provide a proper file in $IMAGE_MNT manually" 
    fi

done


#
# Local Variables: 
# mode: shell-script
# End: 
#


