#
# DESCRIPTION:
#
#   Prepare the switch into new rootfs. Tasks to do
#
#         * create basic devices
#         * copy LiveBackup scripts
#         * move mount points of proc, media and image
#
# 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
#

# we need basic devices
msg -i "creating device nodes .."
mkdir -p $ROOTPATH/dev
cp /dev/MAKEDEV $ROOTPATH/dev
( cd $ROOTPATH/dev; sh MAKEDEV )


#
# copy LiveBackup scripts into new root
#
mkdir -p $ROOTPATH/lib
cp -a /lib/LiveBackup $ROOTPATH/lib/

#
# move mount points
#
msg -i "move mount points to $ROOTPATH .."

if [ "$(is_mounted $MEDIA_MNT)" ]; then
    mkdir -p $ROOTPATH/$MEDIA_MNT
    mount -n --move $MEDIA_MNT $ROOTPATH/$MEDIA_MNT
fi

if [ "$(is_mounted $IMAGE_MNT)" ]; then
    mkdir -p $ROOTPATH/$IMAGE_MNT
    mount -n --move $IMAGE_MNT $ROOTPATH/$IMAGE_MNT
fi

if [ "$(is_mounted $OVERLAY_MNT)" ]; then
    mkdir -p $ROOTPATH/$OVERLAY_MNT
    mount -n --move $OVERLAY_MNT $ROOTPATH/$OVERLAY_MNT
fi

if [ "$MEDIA_MNT" != "$MASTER_MNT" ]; then
    # changed by copy2ram
    if [ "$(is_mounted $$MASTER_MNT)" ]; then
        mkdir -p $ROOTPATH/$RAM_MNT
        mount -n --move $MASTER_MNT $ROOTPATH/$RAM_MNT
    fi
fi

if [ "$(is_mounted /sys)" ]; then
    mkdir -p $ROOTPATH/sys
    mount -n --move /sys $ROOTPATH/sys
fi

# and finally /proc
mkdir -p $ROOTPATH/proc
mount -n --move /proc $ROOTPATH/proc



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