#!/bin/sh
DRIVER=hpt37x2
echo "Post Install for $DRIVER on SuSE Linux 8.0"

if [ $# = '1' -a $1'X' = 'updatesX' ]; then
UPDATEKERNEL=true
elif [ $# = '0' ]; then
UPDATEKERNEL=false
else
echo 'error: Wrong arguments!'
exit 1
fi

ls -l /boot/*SMP >/dev/null 2>&1
if [ $? = '0' ];then 
SMP=smp
else
SMP=
fi

echo "Copying files..."
if [ ${UPDATEKERNEL} = 'true' ]; then
cp -f /boot/vmlinuz /boot/vmlinuz.old
cp -f /boot/vmlinuz.suse /boot/vmlinuz.suse.old
if [ ${SMP}x = 'smpx' ];then
if [ ! -f /boot/vmlinuz.${DRIVER}smp ]; then
	echo "/boot/vmlinuz.${DRIVER}smp not found."
	echo "copy kernel first, then rerun postinstall."
	exit 1
fi
cp -f /boot/vmlinuz.${DRIVER}smp /boot/vmlinuz
else
if [ ! -f /boot/vmlinuz.${DRIVER} ]; then
	echo "/boot/vmlinuz.${DRIVER} not found."
	echo "copy kernel first, then rerun postinstall."
	exit 1
fi
cp -f /boot/vmlinuz.${DRIVER} /boot/vmlinuz
fi
cp /boot/vmlinuz /boot/vmlinuz.suse
fi
if [ ${SMP}x = 'smpx' ];then
cp -f /floppy/2.4.18-64GB-SMP/$DRIVER.o /lib/modules/2.4.18-64GB-SMP/kernel/drivers/scsi/
else
cp -f /floppy/2.4.18-4GB/$DRIVER.o /lib/modules/2.4.18-4GB/kernel/drivers/scsi/
fi
grep 'INITRD_MODULES=\".*hpt37x2' /etc/sysconfig/kernel > /dev/null 2>&1
if [ $? -ne 0 ] ; then
sed -e 's/INITRD_MODULES="/INITRD_MODULES="hpt37x2 /g' /etc/sysconfig/kernel > /tmp/kernel.hpt
mv /etc/sysconfig/kernel /etc/sysconfig/kernel.old
mv /tmp/kernel.hpt /etc/sysconfig/kernel
fi
echo "Configuring system..."
mkinitrd >/dev/null 2>&1

grep 'initrd' /etc/lilo.conf > /dev/null 2>&1
if [ $? -ne 0 ] ; then
sed '/image  = \/boot\/vmlinuz$/a\
  initrd = /boot/initrd' /etc/lilo.conf |sed '/image  = \/boot\/vmlinuz.suse$/a\
  initrd = /boot/initrd.suse' > /tmp/lilo.hpt
mv /etc/lilo.conf /etc/lilo.conf.old
mv /tmp/lilo.hpt /etc/lilo.conf
fi

lilo
echo "End of $DRIVER Post Install"
echo "type \"umount /floppy\" then remove the driver disc from floppy"