#!/bin/sh

#suse and rhel
	if [ -d "/usr/X11R6/lib/X11/xkb/symbols" ]
	then		
		cp -f Setup/symbols/TamilMap /usr/X11R6/lib/X11/xkb/symbols/
	fi

#rhel
	if [ -d "/usr/X11R6/lib/X11/xkb/symbols/pc" ]
	then		
		cp Setup/symbols/TamilMap /usr/X11R6/lib/X11/xkb/symbols/pc/
	fi

#Boss
	if [ -d "/usr/share/X11/xkb/symbols" ]
	then		
		cp -f Setup/symbols/TamilMap /usr/share/X11/xkb/symbols
	fi

#check root user
	if [ $? -eq 0 ]
	then		
		echo '.....................................................'
	else
		echo 'Try Install the application as root user'
		exit
	fi
#/usr/local/bin
	if [ -d "/usr/local/bin" ]
	then
		cp -f Setup/Bin/TamilKeyboardDriver /usr/local/bin
		cp -f Setup/Bin/TamEngine /usr/local/bin
		sudo chmod 777 /usr/local/bin/TamilKeyboardDriver
		sudo chmod 777 /usr/local/bin/TamEngine
	fi

#mkdir /opt/ckdriver
	if [ -d "/opt/ckdriver" ]
	then
		echo '.....................................................'
	else
		mkdir /opt/ckdriver	
	fi

#mkdir /opt/ckdriver/CK+Technologies
	if [ -d "/opt/ckdriver/CK+Technologies" ]
	then
		echo '.....................................................'
	else
		mkdir /opt/ckdriver/CK+Technologies	
	fi

#check /opt/ckdriver/CK+Technologies
	if [ -d "/opt/ckdriver/CK+Technologies" ]
	then
		cp -f Setup/ckdriver/CK+Technologies/*.* /opt/ckdriver/CK+Technologies/
		cp -f Setup/ckdriver/CK+Technologies/Tamil.directory /opt/ckdriver/CK+Technologies/
		cp -f Help.pdf /opt/ckdriver/CK+Technologies/
	fi

#check /usr/share/applications - desktop file
	if [ -d "/usr/share/applications" ]
	then
		cp -f Setup/ckdriver/CK+Technologies/TamilKeyboardDriver.desktop /usr/share/applications/
		sudo chmod 777 /usr/share/applications/TamilKeyboardDriver.desktop
	fi

#check /usr/share/applications - directory file

	if [ -d "/usr/share/desktop-directories" ]
	then
		cp -f Setup/ckdriver/CK+Technologies/Tamil.directory /usr/share/desktop-directories/
		sudo chmod 777 /usr/share/desktop-directories/Tamil.directory
	fi

#check /usr/share/applications - menu file

	if [ -d "/etc/xdg/menus/applications-merged" ]
	then
		cp -f Setup/ckdriver/CK+Technologies/applicationsTamil.menu /etc/xdg/menus/applications-merged
		sudo chmod 777 /etc/xdg/menus/applications-merged/applicationsTamil.menu
	else
		mkdir /etc/xdg/menus/applications-merged
		cp -f Setup/ckdriver/CK+Technologies/applicationsTamil.menu /etc/xdg/menus/applications-merged
		sudo chmod 777 /etc/xdg/menus/applications-merged/applicationsTamil.menu
	fi

#Ubuntu - Fonts Installations

	if [ -d "/usr/share/fonts/truetype" ]
	then
		if [ -d "/usr/share/fonts/truetype/ttf-tamil-fonts" ]
		then
			cp -f Setup/Fonts/*.* /usr/share/fonts/truetype/ttf-tamil-fonts/
			cd /usr/share/fonts/truetype/ttf-tamil-fonts
		else
			mkdir /usr/share/fonts/truetype/ttf-tamil-fonts
			cp -f Setup/Fonts/*.* /usr/share/fonts/truetype/ttf-tamil-fonts/
			cd /usr/share/fonts/truetype/ttf-tamil-fonts
		fi	
	else
		echo '.....................................................'		
	fi

#SUSE - Fonts Installations

	if [ -d "/usr/X11R6/lib/X11/fonts/truetype" ]
	then
		if [ -d "/usr/X11R6/lib/X11/fonts/truetype/ttf-tamil-fonts" ]
		then
			cp -f Setup/Fonts/*.* /usr/X11R6/lib/X11/fonts/truetype/ttf-tamil-fonts/
			cd /usr/X11R6/lib/X11/fonts/truetype/ttf-tamil-fonts
		else
			mkdir /usr/X11R6/lib/X11/fonts/truetype/ttf-tamil-fonts
			cp -f Setup/Fonts/*.* /usr/X11R6/lib/X11/fonts/truetype/ttf-tamil-fonts/
			cd /usr/X11R6/lib/X11/fonts/truetype/ttf-tamil-fonts
		fi	
	else
		echo '.....................................................'		
	fi

	mkfontdir
	mkfontscale
	fc-cache
	cd /home

#check /usr/share/applications/desktop cache
	if [ -f "/usr/share/applications/desktop.en_IN.cache" ]
	then
		sudo rm /usr/share/applications/desktop.*.cache
		sudo sh -c "/usr/share/gnome-menus/update-gnome-menus-cache /usr/share/applications/ > /usr/share/applications/desktop.${LANG}.cache"
	else
		echo '.....................................................'
	fi

#mkdir /usr/local/qt4
	if [ -d "/usr/local/qt4" ]
	then
		echo '.....................................................'
	else
		mkdir /usr/local/qt4 
		mkdir /usr/local/qt4/lib 	
		cd /opt/ckdriver/CK+Technologies/
		tar xvzf /opt/ckdriver/CK+Technologies/lib.tar.gz >/dev/null
		cp -f  /opt/ckdriver/CK+Technologies/lib/*.* /usr/local/qt4/lib/
		sudo chmod 777 /usr/local/qt4/lib/*.*
	fi

#boss
	if [ -f "/lib/libpng12.so.0" ]
	then		
		if [ -f "/lib/libpng.so.3" ]
		then		
			echo '.....................................................'			
		else
			ln -s /lib/libpng12.so.0 /lib/libpng.so.3
		fi		
	else
		echo '.....................................................'
	fi

#suse and ubuntu
	if [ -f "/usr/lib/libpng12.so.0" ]
	then		
		if [ -f "/usr/lib/libpng.so.3" ]
		then		
			echo '.....................................................'			
		else
			ln -s /usr/lib/libpng12.so.0 /usr/lib/libpng.so.3
		fi		
	else
		echo '.....................................................'
	fi

#ubuntu 11.04
	if [ -f "/lib/i386-linux-gnu/libpng12.so.0.44.0" ]
	then		
		if [ -f "/lib/i386-linux-gnu/libpng.so.3" ]
		then		
			echo '.....................................................'
			gsettings set com.canonical.Unity.Panel systray-whitelist "['all']"			
		else
			ln -s /lib/i386-linux-gnu/libpng12.so.0.44.0 /lib/i386-linux-gnu/libpng.so.3
			gsettings set com.canonical.Unity.Panel systray-whitelist "['all']"
		fi		
	else
		echo '.....................................................'
	fi


echo 'Installation of TamilKeyboardDriver is completed Successfully.'
echo 'Restart the system before Running the Application.'


