#!/bin/sh
#
# Uninstall script for Rockey4

echo Uninstall Rockey4 SDK tools...


echo
echo Install Rockey4 SDK tools...
echo

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

#Uninstall Rockey4 SDK tools
if [ -f /usr/local/include/rockey.h ]; then
rm /usr/local/include/rockey.h
fi
if [ -f /usr/local/lib/librockeyapi.a ]; then
rm /usr/local/lib/librockeyapi.a
fi

if [ -f /usr/local/lib/librockeyapi.so ]; then
rm /usr/local/lib/librockeyapi.so
fi

if [ -f /usr/local/lib/librockeyapi.so.0.1 ]; then
rm /usr/local/lib/librockeyapi.so.0.1
fi

if [ -f /usr/local/lib/libjrockey.so ]; then
rm /usr/local/lib/libjrockey.so
fi
/sbin/ldconfig

#Restore usb hotplug script
if [ -f /etc/hotplug/usb.agent ]; then
	declare -i start=0
	declare -i end=0
	declare -i headline=0 
	declare -i endline=0
	start=`cat /etc/hotplug/usb.agent -n | grep "PRO=\`echo $PRODUCT | cut -d/ -f1\`" | head -1 | cut -f1`
        if [ $start != 0 ]; then
		cp /etc/hotplug/usb.agent /etc/hotplug/usb.agent.bak
		end=`cat /etc/hotplug/usb.agent | wc -l`
		headline=$start-1
		endline=$end-$start-4
		head -n $headline /etc/hotplug/usb.agent.bak	> /etc/hotplug/usb.agent
		tail -n $endline /etc/hotplug/usb.agent.bak	>> /etc/hotplug/usb.agent
		rm /etc/hotplug/usb.agent.bak	
	fi
else
	if [ -d /etc/udev/rules.d/ ]; then
		rm -f /etc/udev/rules.d/ft.rules
	fi
fi


echo Uninstall finished!
