#
# DESCRIPTION:
#
#  this script looks for a (read only) filesystem in $IMAGE_MNT/. It 
#  creates symlinks to the current (rw) filesystem /. Files which need
#  to be writable are copied.
#
# BUGS:
#        this script can never be complete or work for all distributions
#
#
# part of the LiveBackup project:  
#
#                     http://livebackup.sourceforge.net/
#
# Copyright 2006-2010 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
#

msg -i "preparing system to run from read only filesystem"

#
# /home should be writable
#
msg -n "setup /home ... "
for name in $( ls -d $IMAGE_MNT/home/* 2>/dev/null ); do
    if [ -d $name ]; then
	cp -a $IMAGE_MNT/home/* /home 
    fi
done
msg "done"

# give user root a writable home
mkdir /root
#cp -a $IMAGE_MNT/root /root

#
# setup /lib
#
msg -n "setup /lib ... "
mkdir -p /lib
for name in $(ls -d $IMAGE_MNT/lib/*); do
  f=$(basename $name)
  if [ ! -e /lib/$f ]; then
     ln -s $IMAGE_MNT/lib/$f /lib/$f
  fi
done
msg "done"


#
# setup configuratin in etc/
#
msg -n "setup /etc ..."
mirror  $IMAGE_MNT/etc               /etc
overwrt $IMAGE_MNT/etc/filesystems   /etc/filesystems
overwrt $IMAGE_MNT/etc/group         /etc/group
overwrt $IMAGE_MNT/etc/passwd        /etc/passwd
overwrt $IMAGE_MNT/etc/shadow        /etc/shadow
overwrt $IMAGE_MNT/etc/motd          /etc/motd
overwrt $IMAGE_MNT/etc/ftpusers      /etc/ftpusers 
overwrt $IMAGE_MNT/etc/ppp           /etc/ppp
overwrt $IMAGE_MNT/etc/isdn          /etc/isdn
overwrt $IMAGE_MNT/etc/ssh           /etc/ssh
overwrt $IMAGE_MNT/etc/localtime     /etc/localtime
overwrt $IMAGE_MNT/etc/adjtime       /etc/adjtime
msg -n "."
overwrt $IMAGE_MNT/etc/inittab       /etc/inittab
overwrt $IMAGE_MNT/etc/hosts         /etc/hosts
overwrt $IMAGE_MNT/etc/network       /etc/network
overwrt $IMAGE_MNT/etc/sudoers       /etc/sudoers
overwrt $IMAGE_MNT/etc/dhcpc         /etc/dhcpc
overwrt $IMAGE_MNT/etc/ld.so.cache   /etc/ld.so.cache
overwrt $IMAGE_MNT/etc/resolv.conf   /etc/resolv.conf 
overwrt $IMAGE_MNT/etc/alternatives  /etc/alternatives
overwrt $IMAGE_MNT/etc/X11           /etc/X11
msg -n "."
overwrt $IMAGE_MNT/etc/sysconfig     /etc/sysconfig
overwrt $IMAGE_MNT/etc/mdadm         /etc/mdadm
overwrt $IMAGE_MNT/etc/acpi          /etc/acpi
overwrt $IMAGE_MNT/etc/hotplug/.run  /etc/hotplug/.run

#
# /etc/gconf
#              may grow big, so it could be overwritten 
#              by rcS.d/S00Livebackup if required
#
#  overwrt $IMAGE_MNT/etc/gconf        /etc/gconf
#


empty /etc/ioctl.save
empty /etc/pnm2ppa.conf
empty /etc/hotplug/net.enable
msg " done"


# /sbin
mirror $IMAGE_MNT/sbin /sbin

# /bin
mirror $IMAGE_MNT/bin /bin

# /boot
ln -s $IMAGE_MNT/boot /boot

# /var
msg -n "setup /var ..."
mirror  $IMAGE_MNT/var                   /var 
msg -n "."
overwrt $IMAGE_MNT/var/lib/nfs           /var/lib/nfs
overwrt $IMAGE_MNT/var/lib/acpi-support  /var/lib/acpi-support
overwrt $IMAGE_MNT/var/lib/alsa          /var/lib/alsa
overwrt $IMAGE_MNT/var/lib/dhcp3         /var/lib/dhcp3
overwrt $IMAGE_MNT/var/lib/dhcp          /var/lib/dhcp
overwrt $IMAGE_MNT/var/lib/exim4         /var/lib/exim4
overwrt $IMAGE_MNT/var/lib/gdm           /var/lib/gdm
overwrt $IMAGE_MNT/var/lib/logrotate     /var/lib/logrotate
overwrt $IMAGE_MNT/var/lib/urandom       /var/lib/urandom
msg " done"


# /dev
# copy all remaining devices, each device file consumes an inode
# there may be many many nodes.
# This not neccessary if udev is used, but does not harm anyway
#
copy_devices $IMAGE_MNT/dev /dev

#
# /usr
#
mkdir -p /usr/share
ln -s $IMAGE_MNT/usr/* /usr 2>/dev/null
ln -s $IMAGE_MNT/usr/share/* /usr/share


#
# /opt
#
if [ -d $IMAGE_MNT/opt ]; then
    ln -s $IMAGE_MNT/opt /opt
fi


#
# /media
#
if [ -d $IMAGE_MNT/media ]; then
    cp -a $IMAGE_MNT/media /
fi

#
# /windows
#
if [ -d $IMAGE_MNT/windows ]; then
    cp -a $IMAGE_MNT/windows /
fi




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