#
# DESCRIPTION:
#
#    The master directory structure is available in $MASTER_MNT.
#    Now get the system image $MASTER_MNT/system/<xxx> 
#    mounted under $IMAGE_MNT
#
# 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
#


#
# ensure mount point exists
#
mkdir -p  $IMAGE_MNT


#
# check for proper mount command options
#
if [ -w /etc/mtab ]; then
    m_opt=""
else
    m_opt="-n"
fi


############################################################################
#
# provide system image under $IMAGE_MNT 
# (if not already mounted manually in debug mode) 
#
if [ ! $(is_mounted $IMAGE_MNT) ]; then

  case "$image_format" in

      directory)
	 rm -rf $IMAGE_MNT
	 ln -s $MASTER_MNT/system/$SYSTEM $IMAGE_MNT
	 ;;

      cloop)
	losetup /dev/cloop $MASTER_MNT/system/$SYSTEM.cloop
	#mount $m_opt -o ro -t iso9660 /dev/cloop $IMAGE_MNT
        mount $m_opt -o ro /dev/cloop $IMAGE_MNT
	;;

      squashfs)
	mount $m_opt -t squashfs -o loop $MASTER_MNT/system/$SYSTEM.sqsh $IMAGE_MNT
	;;

      diskimage)
        if [ "$SYSTEM_MOUNT_OPTS" ]; then
           mount $m_opt -o $SYSTEM_MOUNT_OPTS $MASTER_MNT/system/$SYSTEM.img $IMAGE_MNT
        else
           lomount -diskimage $MASTER_MNT/system/$SYSTEM.img -partition 1 $IMAGE_MNT
        fi
	;;

      blockdevice)
        mount $m_opt -o ro $SYSTEM $IMAGE_MNT
	;;

      *)
        msg -c "FATAL:  !! unsupported image format in $0!!"
	exit 1
  esac

fi


# check it
if [ $(is_mounted $IMAGE_MNT) ]; then
  if [ "$LB_DEBUG" ]; then 
     msg -i "$SYSTEM available under $IMAGE_MNT"
  fi
else
    ls $MASTER_MNT/system
    msg -c "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    msg -c "ERROR: cannot mount $SYSTEM, abort ..."
    msg -c "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
    rescue_shell "now you can try to setup $IMAGE_MNT manually";
fi




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