#!/bin/sh
:
#	Copyright (C) 2008 Inc.
#	All Rights Reserved.
#
#	MOXA Serial I/O Device driver installation script
#	OS = "sco5" "svr4.2" "svr4.5" "sco6"
#
# Version History :
# 	date		author		moment

################################################################################
# define value and default value setting
################################################################################
TempDir="/tmp/moxa"
DriverVer="1.13"
ProductName="MOXA Smartio/Industio Family"
OS=""
Device=""
EntryPwd=`pwd`
tmp=""

################################################################################
# clean_tempfile()
# 	to clean the temp file and $TempDir
################################################################################
clean_tempfile() {
	cd $EntryPwd 
	[ -d $TempDir ] &&
		rm -rf $TempDir > /dev/null 2>&1
	sync ; sync
}

################################################################################
# interrupt_quit1()
# 	to quit install by interrupt or quit
################################################################################
interrupt_quit1() {
	echo "\nInstallation aborted by INTERRUPT !"
	exit 1
}

################################################################################
# interrupt_quit2()
# 	to quit install by interrupt or quit
################################################################################
interrupt_quit2() {
	echo "\nInstallation aborted by INTERRUPT !"
	clean_tempfile
	exit 1
}

interrupt_nothing1() {
	exit 1
}

interrupt_nothing2() {
	clean_tempfile
	exit 1
}
################################################################################
# print_usage()
#	to print the usage message
################################################################################
print_usage() {
	echo "\nCopyright (C) 2008 MOXA Inc."
	echo "All Rights Reserved."
	echo "\nMOXA Smartio/Industio UNIX Driver Installation Script."
	echo "\nUsage: mxinstll [OS name]"
	echo "\n       OS name		{sco5 | uw21 | uw7 | sco6}"
	echo ""
}


################################################################################
# os_info()
#	to display the OS type message
################################################################################
os_info() {
	case $OS in
	"sco5")
		echo "\nFor SCO OpenServer 5\n"
		;;
	"uw21")
		echo "\nFor Unixware 2.x\n"
		;;
	"uw7")
		echo "\nFor SCO Unixware 7\n"
		;;
	"sco6")
		echo "\nFor SCO OpenServer 6\n"
		;;
	esac
}

################################################################################
# backup_os()
#	to backup the OS file
################################################################################
backup_os() {
	case $OS in
	"sco5")
		[ -f /unix.moxa ] || cp /unix /unix.moxa > /dev/null 2>&1
		;;
	esac
}

################################################################################
#	Main procedures
################################################################################
#
# to read the shell program input argument and process it
#
trap interrupt_quit1 1 3 9 15			# trap signal
trap interrupt_nothing1 2			# trap signal
if [ "$#" -ge 3 ]
then
	print_usage
	exit 1
fi
echo "
===============================================================================
Copyright (C) 2008 MOXA Inc.
All Rights Reserved.

$ProductName Device Driver Installation (Ver. $DriverVer)
==============================================================================="
if [ "$1" = "sco5" -o "$1" = "uw21" -o "$1" = "uw7" -o "$1" = "sco6" ]
then
	OS=$1
else
	print_usage
	exit 1
fi
Device=harddisk
os_info
backup_os
trap interrupt_quit2 1 3 9 15			# trap signal
trap interrupt_nothing2 2			# trap signal 
echo "Press RETURN to continue..."
read tmp
cd $TempDir
$TempDir/moxainst
[ $? != 0 ] && {
	clean_tempfile				# clear all temp file
	exit 0
}
clean_tempfile					# clear all temp file
exit 0
