#!/bin/sh                                                                       

echo "uninstall"
uninstall_all()
{
		rm -f /etc/rcS.d/S79switch
		rm -f /etc/rc5.d/s96rundk
		rm -f /etc/rc5.d/S96rundk
		rm -f /etc/rc5.d/rundk.sh
		rm -f /etc/rc5.d/S95dkupdate
		rm -rf /mnt/us/DK_System/
		rm -rf /test/DKLite 
		rm -rf /mnt/us/DK_Mbp/
		rm -rf /mnt/us/DK_User/
		rm	 -f /mnt/base/?pdate*.bin
		rm -f /dev/viewinfodat1.txt
		rm -f /dev/viewinfodat.txt
		rm -f /dev/activeevent
		rm -f /dev/usbevent
		rm -f /dev/DK_Debug.log  
		rm -f /etc/rcS.d/S79showmenu
		rm -f /etc/init.d/usb_switch
		rm -f /etc/rc5.d/usbsingle.sh		
		sync
}
uninstall_lite()
{
	mntroot rw
	if [ -f /mnt/us/DK_System/bin/ebook ] 
	then	
			  rm /mnt/us/DK_System/bin/Lite -rf
			  rm /mnt/us/DK_System/bin/dk2system.bin -f
			  rm /mnt/us/DK_System/bin/dk3system.bin -f
			  rm /mnt/us/DK_System/bin/update.sh -f
	else
			  uninstall_all
	fi
	rm /test/DKLite -rf
	mv /etc/rc5.d/s95framework /etc/rc5.d/S95framework
	sync
	mntroot ro
}

uninstall_ebook()
{
	mntroot rw
	if [ ! -d /mnt/us/DK_System/Lite ] || [ ! -f /test/DKLite/KindleApp ]
	then
			uninstall_all
	else
			rm -rf /mnt/us/DK_System/bin/ebook
    	rm -rf /mnt/us/DK_System/Savers/
    	rm -rf /mnt/us/DK_System/system/
    	rm -rf /mnt/us/DK_System/lib/   
    	rm -rf /mnt/us/DK_System/PrintScreen/
    	rm -rf /mnt/us/DK_System/config.ini
			rm -rf /mnt/us/DK_Mbp/
			rm -rf /mnt/us/DK_User/
			rm	 -f /mnt/base/?pdate*.bin
			rm -f /dev/viewinfodat1.txt
			rm -f /dev/viewinfodat.txt
			rm -f /dev/activeevent
			rm -f /dev/usbevent
			rm -f /dev/DK_Debug.log  
			rm -f /etc/rcS.d/S79showmenu
			rm -f /etc/init.d/usb_switch
			rm -f /etc/rc5.d/usbsingle.sh			
	fi
	mv /etc/rc5.d/s95framework /etc/rc5.d/S95framework
	sync
	mntroot ro
}

echo "uninstall begin"
cd /
if [ $1 == "ebook" ]
then
		echo "uninstall_ebook"
		uninstall_ebook
elif [ $1 == "lite" ]
then
		echo "uninstall_lite"
		uninstall_lite
else
		echo "UnInstal param error"
fi 

echo "uninstall end "
cd /
shutdown -r -F now
return
			

