
:
#	Copyright (C) 1998  MOXA Technologies Co., Ltd.
#	All Rights Reserved.
#
#	MOXA Serial I/O Device driver installation script
#
# Version History :
# 	date		author		moment
#	01/06/1997	Victor		Ver=4.0 for C218/C320 at QNX
#	02/04/1998	Casper		Ver=4.1 (upgrade)
#	05/05/1998	Casper		Ver=4.2 (upgrade)
#	12/07/1998	Casper		Ver=5.0 (upgrade)(for Intellio)

################################################################################
# define value and default value setting
################################################################################
TempDir="/tmp/moxa"
DriverVer="5.0"
ProductName="Moxa"
YES=0
NO=1
Device=""
EntryPwd=`pwd`

################################################################################
# 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
}

################################################################################
# print_usage()
#	to print the usage message
################################################################################
print_usage() {
	echo "\nCopyright (C) 1999 Moxa Technologies Co., Ltd."
	echo "All Rights Reserved."
	echo "\nMoxa Serial I/O Device driver installation script."
	echo "\nUsage: mxinst [device name]"
	echo "\n       device name	source floppy device name"
	echo ""
}

################################################################################
# tar_files()
#	tar the needed file to disk at $TempDir
#	And copy the Driver.o file
################################################################################
tar_files() {
	echo "\nTar files, please wait ...\c"
	[ -d $TempDir ] || mkdir $TempDir > /dev/null 2>&1
	cd $TempDir
	[ "$Device" = "harddisk" ] || {
		tar xvf $Device $TempDir/qnx.tar > /dev/null 2>&1
		[ $? != 0 ] && {
			[ -d $TempDir ] && rm -rf $TempDir > /dev/null 2>&1
			echo "\nDevice name error ! It cannot tar file !"
			exit 1
		} 
	}
	tar xvf $TempDir/qnx.tar > /dev/null 2>&1
	echo " O.K."
}

################################################################################
# get_devicename()
#	to input the floppy device name
################################################################################
get_devicename() {
	flag=TRUE
	while [ "$flag" = TRUE ]
	do
		echo "\nPlease select follwing floppy device type"
		echo "1.	/dev/fd0	(A floppy)"
		echo "2.	/dev/fd1	(B floppy)"
		echo "3.	Hard Disk	/tmp/moxa"
		echo "Select : \c"
		read Device
		case $Device in
		[1])
			flag=FALSE
			Device="/dev/fd0"
			;;
		[2])
			flag=FALSE
			Device="/dev/fd1"
			;;
		[3])
			flag=FALSE
			Device="harddisk"
			;;
		*)
			echo "\nInvalid input ! Please retry."
			;;
		esac
	done
}

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

$ProductName Device Driver Installation (Ver. $DriverVer)
==============================================================================="
Device=$2
[ "$Device" = "" ] && get_devicename
#
# start the install process
#
echo "\nFor QNX System"
trap interrupt_quit2 1 2 3 9 15			# trap signal
tar_files					# copy file
./moxainst
[ $? != 0 ] && {
	clean_tempfile				# clear all temp file
	exit 0
}
clean_tempfile					# clear all temp file
echo "\n$ProductName device driver installation completed."
echo "\nAll $ProductName driver & readme,release note files are"
echo "put in the directory /usr/lib/moxa."
echo "\n"
exit 0
