#
# DESCRIPTION:
#
#   Search for kernel modules in 
#
#        $MASTER_MNT/lib/modules/ 
#   and 
#        $IMAGE_MNT/lib/modules/
#
#   Mount them under $ROOTPATH/lib/modules/<kversion>.
#
#   (directory $ROOTPATH/lib/modules/ must be writable)
#
# 
# 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
#



#
# setup a kernel module directory in $kmod_dir
# 
# synopsis:
#             _provide_kmodules <from> 
#
# description:
#
# create writable module directories and link modules to right place
# the module-kernel directory must be remounted, 
# depmod will not work with symbolic/hard links !!
#
_provide_kmodules()
{
    mkdir -p $kmod_dir
    copylnk $1 $kmod_dir
    rm -f $kmod_dir/kernel
    mkdir $kmod_dir/kernel
    mount -n --bind $1/kernel $kmod_dir/kernel
    # ToDo: How to handle a misc directory ?? 
    msg -i "using kernel modules: $1"
}


kmod_dir=$ROOTPATH/lib/modules/$kversion

if [ ! -d $kmod_dir ]; then
    #
    # See if $MASTER_MNT contains matching kernel modules. 
    #
    if [ -d $MASTER_MNT/lib/modules/$kversion ]; then
	_provide_kmodules $MASTER_MNT/lib/modules/$kversion 
    else 
	#
        # search for modules in system image
	#
	if [ -d $IMAGE_MNT/lib/modules/$kversion ]; then
	    _provide_kmodules $IMAGE_MNT/lib/modules/$kversion 
	else
            msg -w "WARNING !! no extra modules for kernel $kversion found"
            msg -w "directories searched:              "
            msg -w "          $MASTER_MNT/lib/modules/ "
            msg -w "          $IMAGE_MNT/lib/modules/  "
            msg -w "continue booting ...               "
        fi
    fi
fi


#
# you probably want to use modprobe.conf from your backup
#
if [ -d $kmod_dir ]; then
    if [ -f $IMAGE_MNT/lib/modules/modprobe.conf ]; then
	cp $IMAGE_MNT/lib/modules/modprobe.conf $kmod_dir/../modprobe.conf
    else
	echo "# !!!! fixme: dummy modprobe.conf from LiveBackup ($0)" \
	    >  $kmod_dir/../modprobe.conf
    fi
fi


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












