#!/bin/sh

THIS_KERNEL=`uname -r`
ls -ld /lib/modules/${THIS_KERNEL}/build > /dev/null
[ $? != 0 ] && {
	exit 1
}

#
# We need to make sure that "version.h" exists.  This is a problem on SLES7
#
ls /lib/modules/${THIS_KERNEL}/build/include/linux/version.h > /dev/null
[ $? != 0 ] && {
	ls /boot/vmlinuz.version.h > /dev/null
	[ $? -eq 0 ] && {
		cp /boot/vmlinuz.version.h /lib/modules/${THIS_KERNEL}/build/include/linux/version.h
	} || {
		exit 1
	}

}

#
# We need to make sure that "autoconf.h" exists.  This is a problem on SLES7
#
ls /lib/modules/${THIS_KERNEL}/build/include/linux/autoconf.h > /dev/null
[ $? != 0 ] && {
	ls /boot/vmlinuz.autoconf.h > /dev/null
	[ $? -eq 0 ] && {
		cp /boot/vmlinuz.autoconf.h /lib/modules/${THIS_KERNEL}/build/include/linux/autoconf.h
	} || {
		exit 1
	}

}
#
# We now need to make sure that the version.h file matches the kernel
# we are trying to build.
#
fgrep ${THIS_KERNEL} /lib/modules/${THIS_KERNEL}/build/include/linux/version.h > /dev/null
[ $? != 0 ] && {
# 
#       We will now try to see if this is a SLES 7 system that might have
#  been patched.
#
	ls /boot/vmlinuz.version.h > /dev/null
	[ $? -eq 0 ] && {
		fgrep ${THIS_KERNEL} /boot/vmlinuz.version.h > /dev/null
		[ $? -eq 0 ] && {
			mv /lib/modules/${THIS_KERNEL}/build/include/linux/version.h /lib/modules/${THIS_KERNEL}/build/include/linux/version.h.ORIGINAL
			mv /lib/modules/${THIS_KERNEL}/build/include/linux/autoconf.h /lib/modules/${THIS_KERNEL}/build/include/linux/autoconf.h.ORIGINAL
			cp /boot/vmlinuz.version.h /lib/modules/${THIS_KERNEL}/build/include/linux/version.h

			cp /boot/vmlinuz.autoconf.h /lib/modules/${THIS_KERNEL}/build/include/linux/autoconf.h

		} || {
			exit 1
		}

	} || {
		exit 1
	}

}

exit 0

