#! /bin/sh

# This script updates the kernel and modules from your
#   current system. 
#

TOPDIR=`pwd`
KERNEL=`uname -r` 

rm -rf roottree/dev
tar xfz dev.tar.gz -C roottree
if [ $? != 0 ] ; then
   echo "Update failed."
   exit 1
fi

#
# Update modules in root RAM disk
#  Keep kernel directory structure
#
echo "Updating modules in root RAM disk"
rm -rf roottree/lib/modules
mkdir -p roottree/lib/modules
cp -af /lib/modules/$KERNEL/ roottree/lib/modules/

kernel="/boot/vmlinuz-$KERNEL"
echo "Coping $kernel to $TOPDIR/cdtree/boot/isolinux/vmlinuz"
cp -f $kernel $TOPDIR/cdtree/boot/isolinux/vmlinuz
if [ $? != 0 ] ; then
   echo "Could not find kernel. Update failed."
   exit 1
fi
if [ -e /boot/map ] ; then
   cp -f /boot/map $TOPDIR/cdtree/boot/isolinux/map
   if [ $? != 0 ] ; then
      echo "Update failed."
      exit 1
   fi
fi
