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

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
if [ ${SMP}x = 'smpx' ];then
if [ -f /boot/vmlinuz ]; 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 /boot/vmlinuz.old
cp -f /boot/vmlinuz.suse /boot/vmlinuz.suse.old
cp -f /boot/vmlinuz.${DRIVER}smp /boot/vmlinuz
cp /boot/vmlinuz /boot/vmlinuz.suse
fi
if [ -f /boot/vmlinuz_24 ]; then
if [ ! -f /boot/vmlinuz_24.${DRIVER}smp ]; then
	echo "/boot/vmlinuz_24.${DRIVER}smp not found."
	echo "copy kernel first, then rerun postinstall."
	exit 1
fi
cp -f /boot/vmlinuz_24 /boot/vmlinuz_24.old
cp -f /boot/vmlinuz_24.${DRIVER}smp /boot/vmlinuz_24
fi
else
if [ -f /boot/vmlinuz ]; then
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 /boot/vmlinuz.old
cp -f /boot/vmlinuz.suse /boot/vmlinuz.suse.old
cp -f /boot/vmlinuz.${DRIVER} /boot/vmlinuz
cp /boot/vmlinuz /boot/vmlinuz.suse
fi
if [ -f /boot/vmlinuz_24 ]; then
if [ ! -f /boot/vmlinuz_24.${DRIVER} ]; then
	echo "/boot/vmlinuz_24.${DRIVER} not found."
	echo "copy kernel first, then rerun postinstall."
	exit 1
fi
cp -f /boot/vmlinuz_24 /boot/vmlinuz_24.old
cp -f /boot/vmlinuz_24.${DRIVER} /boot/vmlinuz_24
fi
fi
fi

if [ ${SMP}x = 'smpx' ];then
if [ -f /boot/vmlinuz ]; then
cp -f /floppy/2.2.18-SMP/$DRIVER.o /lib/modules/2.2.18-SMP/scsi
fi
if [ -f /boot/vmlinuz_24 ]; then
cp -f /floppy/2.4.0-64GB-SMP/$DRIVER.o /lib/modules/2.4.0-64GB-SMP/kernel/drivers/scsi
fi
else
if [ -f /boot/vmlinuz ]; then
cp -f /floppy/2.2.18/$DRIVER.o /lib/modules/2.2.18/scsi
fi
if [ -f /boot/vmlinuz_24 ]; then
cp -f /floppy/2.4.0-4GB/$DRIVER.o /lib/modules/2.4.0-4GB/kernel/drivers/scsi
fi
fi

grep 'INITRD_MODULES=\".*hpt37x2' /etc/rc.config > /dev/null 2>&1
if [ $? -ne 0 ] ; then
sed -e 's/INITRD_MODULES="/INITRD_MODULES="hpt37x2 /g' /etc/rc.config > /tmp/rc.hpt
mv /etc/rc.config /etc/rc.config.old
mv /tmp/rc.hpt /etc/rc.config
fi
echo "Configuring system..."
rootdev=`grep "^/dev/.*\B/\B" /etc/fstab |cut -f1`
if [ -z $rootdev ]; then
echo
echo Error: rootdev not found!
exit 1
fi
mk_initrd -d ${rootdev} >/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"
