#!/bin/sh
clear

PATCH_SCRIPT=`basename $0` 
PATCH_PATH=`echo $0 | sed "s/[\/]*$PATCH_SCRIPT//"`

if [ ! -e /usr/src/linux/Makefile ]
then
	echo "$PATCH_SCRIPT: No kernel sources were found.  Please install kernel sources."
	exit 1
fi

if [ "$PATCH_PATH" = "" -o "$PATCH_PATH" = "." ]
then
    INSTALL_DIR=`pwd`
else
	pushd $PATCH_PATH	>/dev/null
	INSTALL_DIR=`pwd`
	popd	>/dev/null 2>/dev/null
fi
echo Installing from $INSTALL_DIR

DIFF_FILES=$INSTALL_DIR/dpt_i2o.tgz
GET_DIFF='tar xfOz '$DIFF_FILES

cd /usr/src/linux

#######################################################################
#	Patch main Source files
#######################################################################

# Delete all DPT files

for f in `$GET_DIFF dpt_i2o.diff | grep +++ | awk '{ print $2 }' | cut -f2- -d'/'`
do 
	rm -f $f
done


$GET_DIFF dpt_i2o.diff | patch -lNp1 -s


#######################################################################
#	Patch Makefile config.in and hosts.c
#######################################################################

$GET_DIFF makeconfig.diff | patch -lNp1 -s

#######################################################################
#	Patch pci_ids
#######################################################################

if [ -e include/linux/pci_ids.h ]
then
	$GET_DIFF pci_ids.diff | patch -lNp1 -s
else
	$GET_DIFF pci.diff | patch -lNp1 -s
fi

#######################################################################
#	Patch oldproc.c
#######################################################################

if [ -e drivers/oldproc.c ]
then
	$GET_DIFF oldproc.diff | patch -lNp1 -s
fi

#######################################################################
#	Patch proc_fs.h
#######################################################################

if [ -e include/linux/proc_fs.h ] && grep scsi_directory include/linux/proc_fs.h>/dev/null
then
	$GET_DIFF proc_fs.diff | patch -lNp1 -s
fi

echo
echo "$PATCH_SCRIPT: Your kernel sources have been patched to include the"
echo "$PATCH_SCRIPT: latest DPT I2O driver sources.  If you wish to compile"
echo "$PATCH_SCRIPT: the Adaptec I2O driver, the driver is listed under"
echo "$PATCH_SCRIPT:    SCSI Support -> SCSI low-level drivers ->"
echo "$PATCH_SCRIPT:    DPT I2O SmartRAID V support"
echo "$PATCH_SCRIPT: in the kernel configuration."
echo "$PATCH_SCRIPT: "
echo "$PATCH_SCRIPT: Previously applied patches may appear as "
echo "$PATCH_SCRIPT: ignored rejected hunks."
