#
# DESCRIPTION:
#
#      check the final system, more tests should be added
#
# 
# 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
#


#
# check for essential devices
#
if [ ! -e /dev/console ]; then
    mknod /dev/console c 5 1
    msg -w "!! WARNING, /dev/console is missing !!, created  .."
fi

if [ ! -d /dev/pts ]; then
    msg -i "create /dev/pts .."
    mkdir /dev/pts
fi

if [ ! -d /dev/shm ]; then
    msg -i "create /dev/shm .."
    mkdir /dev/shm
    chmod 777 /dev/shm
    chmod +t  /dev/shm
fi


#
# remove if backup include udev directories
#
rm -rf /dev/.static
rm -rf /dev/.udevdb


#
# check /bin/sh
#
if [ -L /bin/sh ]; then
    if [ -x /bin/bash ]; then
	ls -l /bin/sh | grep -q busybox
	if [ $? = 0 ]; then 
	    rm /bin/sh
	    ln -s /bin/bash /bin/sh
	    msg -i "installed: /bin/sh -> /bin/bash"
	fi
    fi
fi

#
# ensure that /proc is mounted
#
if [ ! -f /proc/cpuinfo ]; then
    mkdir -p /proc
    mount -n -t proc /proc /proc
fi


#
# some distributions cannot handle an already mounted /sys
#
if [ -d /sys/kernel ]; then
    umount -n /sys
else
    mkdir -p /sys
    # mount -n -t sysfs /sys /sys
fi

#
# try to eject media if copy2ram is used
#
if [ $MEDIAEJECT = "yes" ] && [ "$(echo $COPY2RAM | grep success)" ]; then
    umount $MEDIA_MNT
    msg -i "HINT: you can remove the boot media now"
    if [ "$(which eject)" ]; then
	eject $MEDIA_MNT > /dev/null 2>&1
    fi
fi

#
# save current environment
#
env > /etc/LiveBackup.env

#
# ask for interactive shell in debug mode
#
if [ $LB_DEBUG -gt 0 ]; then 
  msg -w -n "enter interacitve shell (y/n): ";
  read ans
  if [ $ans = "y" ]; then
      rescue_shell "system will continue boot procedure after exit"
  fi
fi

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