#!/bin/sh

# Basically anything can be put in here as long as the conditions in
# which it should be executed are clear enough

set -e
. /lib/chroot-setup.sh
. /usr/share/debconf/confmodule

TEMPLATE_ROOT=sarge-support

log() {
	logger -t sarge-support "$@"
}

# Only run if we're installing Sarge
if db_get mirror/codename && [ "$RET" ]; then
	if [ "$RET" != sarge ]; then
		exit 0
	fi
fi

# vmware uses the mptscsih driver; because of driver changes, mkinitrd
# does not pick this up correctly for the 2.6.8 kernel
if grep -q "^mptscsih.*1 mptspi" /proc/modules; then
	initrd=$(ls /target/boot/initrd.img-2.6.8* 2>/dev/null || true)
	if [ "$initrd" ] && [ -x /target/usr/sbin/mkinitrd ] ; then
		kernelver=${initrd#*initrd.img-}
		echo mptscsih >>/target/etc/mkinitrd/modules
		# Regenerate the initrd
		chroot_setup
		chroot /target mkinitrd -o /boot/initrd.img-$kernelver $kernelver
		chroot_cleanup
	fi
fi
