#!/bin/sh
#
# VIA RAID Management Software Installation Script
# VIA Technologies Ltd.
#

# configure information
prefix_path=/usr/local
#module_path=/lib/modules/`uname -r`/misc

version_string=2.00 	###################to be modified
package_name=viaraid-$version_string

raidtoolbin=viaraid-gtk
raidtoolconf=viaraid.conf
#raidtoolmod=viasraid.o
raidtooldoc_path=/usr/share/doc/$package_name/

#check user permission
e_user=`whoami`

if [ $e_user != "root" ]; then
	echo "Root user required to install VIA Raid Tool for Linux."
	exit 1
fi

# check if the program is running
pidof $raidtoolbin > /dev/null
if [ $? -eq 0 ] ; then
	echo "The software is running. Please stop it first."
	exit 1
fi 

#ask the prefix path
while true; do
echo -n "Please spceify the base directory to install the files. [/usr/local]"
read userinput
if [ "$userinput" = "" ]; then
	break
else
	prefix_path="$userinput"
	[ -d "$userinput" ] && break
fi
done

bin_path=${prefix_path}/bin

#check whether viaraidtool has been installed
if [ -f "${bin_path}/${raidtoolbin}" ]; then
echo "There is a pre-installed VIA Raid Tool in your system."
while true; do
	echo -n "Are you sure to re-install them? (Yes/No) [Yes]"
	read  userinput
	case "$userinput" in 
		[yY] | [yY][eE][sS] | "" )
			break
			;;
		[nN] | [nN][oO] )
			echo "Install process is canceled. Bye."
			exit 1
			;;
	esac
done
fi


echo "Starting install VIA Raid Tool for Linux, please wait..."

#install binaries
install -D -m 555 bin/${raidtoolbin} ${bin_path}/${raidtoolbin}
#install configurationn file
install -m 644 conf/${raidtoolconf} /etc/${raidtoolconf}
#install help document
install -D -d doc/images ${raidtooldoc_path}/images
install -m 644 COPYRIGHT ${raidtooldoc_path}
install -D -m 644 doc/*.htm ${raidtooldoc_path}
install -D -m 644 doc/images/* ${raidtooldoc_path}/images

echo
echo "VIA Raid Tool has been installed successfully."
echo "Before run it, you must install the driver first. "
echo "And the executable file is ${raidtoolbin} under ${bin_path}"
echo

