#!/bin/sh


if [ $# -ne 1  ] ; then
	echo "Usage: setup_links [ create | remove | all ]"
	cd $currdir
	exit 0
fi

currdir=`pwd`
if [ -z `echo $currdir | grep "babhisax"` ] ; then
	cd drivers/babhisax
fi

if [ $1 = "remove" ] ; then
	# Clean up
	/bin/rm -rf ./hisax
	/bin/rm -f ./isdnif.h
	/bin/rm -f ./isdn.h

elif [ $1 = "create" ] ; then	
	/bin/rm -rf ./hisax
	/bin/rm -f ./isdnif.h
	/bin/rm -f ./isdn.h

if [ ! -f /usr/include/linux/version.h ] ; then
	echo "warning: Kernel not configured properly!"
	echo "warning: /usr/include/linux/version.h does not exist."

	kernel_version=`uname -r`
	echo "warning: Using running kernel version ($kernel_version)."
	major=`echo $kernel_version | cut -f1 -d"."`
	minor=`echo $kernel_version | cut -f2 -d"."`
	if [ ${major} -eq 2 -a ${minor} -eq 2 ] ; then
		RELEASE=131584
	elif [ ${major} -eq 2 -a ${minor} -eq 4 ] ; then
		RELEASE=132096
	fi
		
else
	RELEASE=`grep LINUX_VERSION_CODE /usr/include/linux/version.h | cut -f3 -d" "`
fi

# If we didn't get any release information, default to 2.2 support.
if [ -z $RELEASE ] ; then
	echo "Warning: Couldn't determine kernel version."
	echo "Warning: Defaulting to 2.2 support."
	echo "Please check your kernel source installation." 
	/bin/ln -s isdn-2.2.h isdn.h
	/bin/ln -s isdnif-2.2.h isdnif.h
	/bin/ln -s hisax-2.2 hisax
	cd $currdir
	exit 0
fi

# Check for 2.2.X kernel
if [ ${RELEASE} -lt 131883 -a ${RELEASE} -ge 131584 ] ; then
	echo "creating links for 2.2.X kernel"
	/bin/ln -s isdn-2.2.h isdn.h
	/bin/ln -s isdnif-2.2.h isdnif.h
	/bin/ln -s hisax-2.2 hisax
# Check for 2.4.X kernel (2.3.43 <= REL < 2.5.0)
elif [ ${RELEASE} -ge 131883 -a ${RELEASE} -lt 132352 ] ; then 
	echo "creating links for 2.4.X kernel"
	/bin/ln -s isdn-2.4.h isdn.h
	/bin/ln -s isdnif-2.4.h isdnif.h
	/bin/ln -s hisax-2.4 hisax
# Check for 2.0.X kernel (not tested)
elif [ ${RELEASE} -ge 131108 -a ${RELEASE} -lt 131328 ] ; then
	echo "creating links for 2.0.X kernel"
	/bin/ln -s isdn-2.2.h isdn.h
	/bin/ln -s isdnif-2.2.h isdnif.h
	/bin/ln -s hisax-2.2 hisax
else
	echo "Warning: Couldn't determine kernel version."
	echo "Warning: Defaulting to 2.2 support."
	echo "Please check your kernel source installation." 
	/bin/ln -s isdn-2.2.h isdn.h
	/bin/ln -s isdnif-2.2.h isdnif.h
	/bin/ln -s hisax-2.2 hisax
fi
else
	echo "Usage: setup_links [ remove | create | all ]"
fi

cd $currdir
