#
# 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-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
#

kmod_dir=$ROOTPATH/lib/modules/$kversion

#
# See if $MASTER_MNT contains matching kernel modules. 
# Use these in first place.
#
m=$MASTER_MNT/lib/modules/$kversion
if [ -d $m ]; then
    rm -rf $kmod_dir
    mkdir -p $kmod_dir/kernel
    for name in $(ls -1 $m); do
	case $name in
	    kernel)
		mount -n --bind $m/kernel $kmod_dir/kernel
		msg -i "using kernel modules: $m"
		;;
	    TRANS.TBL)
		;;
	    build)
		;;
	    source)
		;;
	    *)
		cp -a $m/$name $kmod_dir/
	esac
    done
else
    if [ ! -d $kmod_dir/kernel ]; then
        msg -w "WARNING !! no modules for kernel $kversion found"
        msg -w "directories searched:              "
        msg -w "          $MASTER_MNT/lib/modules/ "
        msg -w "          $ROOTPATH/lib/modules/  "
        msg -w "continue booting ...               "
    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
	if [ ! -f $kmod_dir/../modprobe.conf ]; then
	    echo "# !!!! fixme: dummy modprobe.conf from LiveBackup ($0)" \
		>  $kmod_dir/../modprobe.conf
	fi
    fi
fi


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












