#!/bin/sh
###############################################################################
# Program:
# 		MOXA Linux driver installer
#	
# History:
# 2009/09/11
#
# Author:
# Ken Huang, ken.huang@moxa.com
#
# Discription:
# The script install and load the MOXA Linux driver.
#
###############################################################################

TARGET_DRIVER_26=mxu11x0
TARGET_DRIVER_24=mxu1100_24
MXVER=2.0
KERNEL_VERSION_MAJOR_NUMBER=$(uname -r | cut -f1 -d.)
KERNEL_VERSION_MINOR_NUMBER=$(uname -r | cut -f2 -d.)

# first we set it to be kernel 2.6
TARGET_DRIVER_X=$TARGET_DRIVER_26
if test $KERNEL_VERSION_MAJOR_NUMBER -eq 2 ; then
	if test $KERNEL_VERSION_MINOR_NUMBER -eq 4 ; then
	    # after comparision, we set it to be kernel 2.4
		TARGET_DRIVER_X=$TARGET_DRIVER_24
	fi
fi

if lsmod | grep -q $TARGET_DRIVER_X ; then
    echo "Found driver in system..."
    echo "Unloading driver..."
    rmmod $TARGET_DRIVER_X || exit 1
    make clean
    echo "Unload driver successfully."
    echo ""
fi
 
if make install ; then
	echo ""
	echo "Loading driver..."
	modprobe $TARGET_DRIVER_X || exit 1
	echo "************************************************************************"
	echo " MOXA UPort 11x0 series driver $MXVER loaded successfully."
	echo "************************************************************************"
fi
