#!/bin/bash
#
#Rockey-ARM install script
#
SOVER=so.1.0
script_path=`dirname "$0"`
echo
echo Installing Rockey-ARM SDK...
echo

#Check whether the current user is root
if test $(id -ur) != 0; then
	echo
	echo "You should logon as root user!"
	echo
	exit 1
fi

get_confirm()
{
	echo "[yes or no]"
	while true
	do
		read X
		case "$X" in
			y | yes | Y | Yes | YES ) return 1;;
			n | no | N | No | NO )
				echo "Cancelled"
				return 0;;
			*) echo "Please enter yes or no";;
		esac
	done
}

#check whether proc and usbfs file system is exist!
echo	Check whether proc and usbfs file system is exist!
if [ ! -f /proc/bus/usb/devices ]; then
	if [ ! -d /dev/bus/usb ]; then
		echo
		echo "Warning: It need proc and usbdevfs file system support!"
		echo
		exit 1
	fi
fi
echo	System enable proc and usbdevfs filesystem!


#check whether enable SELinux
TEMP_VAR=`whereis chcon | awk '{print $2}'`
TEMP_VAR2=`whereis selinux | awk '{print $2}'`

if [ -f /etc/hotplug/usb.usermap ];then
	grep -l "ft.map" /etc/hotplug/usb.usermap>/dev/null
	if [ $? = 1 ];then
		echo "ft.map 0x0000 0x096e 0x0000 0x0000 0x0000 0x00 0x00 0x00 0x00 0x00 0x00 0x00000000">>/etc/hotplug/usb.usermap
	fi
fi

if [ -f /etc/rc.local ];then
	sed 's/exit 0//g' /etc/rc.local > /etc/rc.local1
	rm -f /etc/rc.local
	mv /etc/rc.local1 /etc/rc.local

	grep -l "/dev/bus/usb" /etc/rc.local>/dev/null ||echo "ln -s /sys/kernel/debug/usb/devices /dev/bus/usb/devices">>/etc/rc.local

	echo "exit 0 ">>/etc/rc.local
fi

if [ -d /etc/hotplug/usb/ ];then
	cp -f $script_path/ft.map /etc/hotplug/usb/
fi

if [ -d /etc/udev/rules.d/ ]; then
	cp $script_path/ft.rules /etc/udev/rules.d/
fi

/etc/rc.local 2>/dev/null
udevadm control --reload-rules 2>/dev/null

echo Install finished!


