#!/bin/sh
#
#  This script sets up the ParaVM to use pygrub
#

prefix=$1

#
#  Source our common functions
#
if [ -e /usr/lib/xen-tools/common.sh ]; then
    . /usr/lib/xen-tools/common.sh
else
    . ./hooks/common.sh
fi

echo SCRIPT = $0
dir=`dirname "$0"`


logMessage Script $0 starting

# To avoid UDP checksum problems.

installDebianPackage ${prefix} ethtool

#
# Install the xen kernel.  linux-image-xen is in ubuntu,
# linux-image-xen-amd64 in debian.
installDebianPackage ${prefix} linux-image-xen
installDebianPackage ${prefix} linux-image-xen-amd64

installDebianPackage ${prefix} grub

#
# Make the /boot/grub directory
#
mkdir -p ${prefix}/boot/grub

#
# Create stock menu.lst
#
chroot ${prefix} /usr/sbin/update-grub -y

#
# Patches to add xen kernels, use serial console, etc.
#
for patch in $dir/patches/*; do
    patch -l -d ${prefix} -p1 < $patch
done

#
# Regenerate automagic kernels list
#
chroot ${prefix} /usr/sbin/update-grub -y

#
# Log our finish
#
logMessage Script $0 finished

