#!/bin/sh

echo ''
echo '=== TouchKit for Linux Installer ==='
echo ''
echo '(Step 1) Install TCL TK Packages Installed'

###########################################################################
dpkg -i ./deb_tcl_tk/make_4.1-9.1ubuntu1_amd64.deb
dpkg -i ./deb_tcl_tk/libtcl8.6_8.6.8+dfsg-3_amd64.deb
dpkg -i ./deb_tcl_tk/libtk8.6_8.6.8-4_amd64.deb
dpkg -i ./deb_tcl_tk/tcl8.6_8.6.8+dfsg-3_amd64.deb
dpkg -i ./deb_tcl_tk/tk8.6_8.6.8-4_amd64.deb
dpkg -i ./deb_tcl_tk/libxss1_1%3a1.2.2-1_amd64.deb
ln -f -s /usr/bin/tclsh8.6 /usr/bin/tcl
ln -f -s /usr/bin/tclsh8.6 /usr/bin/tclsh
ln -f -s /usr/bin/wish8.6  /usr/bin/tk
ln -f -s /usr/bin/wish8.6  /usr/bin/wish

cp -rf ./deb_tcl_tk/rc-local.service /etc/systemd/system
systemctl enable rc-local

cp -rf ./kernel_update/* /boot/
#cp -rf ./evdev/evdev.ko   /lib/modules/5.0.0-23-generic/kernel/drivers/input/
cp -rf ./joydev/joydev.ko /lib/modules/5.0.0-23-generic/kernel/drivers/input/
cp -rf ./usbhid/usbhid.ko /lib/modules/5.0.0-23-generic/kernel/drivers/hid/usbhid/

rm -rf /usr/share/icons/xcursor-transparent
tar -zxvf ./kernel_update/xcursor-transparent.tgz -C /usr/share/icons/ > /dev/null
mkdir -p /etc/X11/cursors
ln -f -s /usr/share/icons/xcursor-transparent/cursor.theme /etc/X11/cursors/xcursor-transparent.theme
###########################################################################

username_list=`users`
for  username in $username_list ; do
	if  [ username != "root" ]
	then
		mkdir -p /home/$username/.config/autostart
		cp -rf ./driver/tpaneld-restart.sh.desktop /home/$username/.config/autostart/
	fi
done

#PR_AUTO_ready=1
#FULL_ready=1

#package=(make tcl tk) 
#class="Common"
#echo "[$class]"

###########################################################################
#for dpkg in ${package[@]} ; do
#        found=`rpm -qa | sed -n /^$pkg-[0-9][0-9]*\\\\./p`
#        if [ "$found" == "" ] ; then
#           if [ "$pkg" == "tcl" ] ; then
#		rpm -i ./rpm_tcl_tk/tcl-8.4.13-3.fc6.i386.rpm
#	   fi

#	   if [ "$pkg" == "tk" ] ; then
#		rpm -i ./rpm_tcl_tk/tk-8.4.13-3.fc6.i386.rpm
#           fi
#	fi
#done

###########################################################################
#for pkg in ${package[@]} ; do
#	printf " %-30s" "$pkg" 
#	found=`rpm -qa | sed -n /^$pkg-[0-9][0-9]*\\\\./p`
#	if [ "$found" != "" ] ; then
#		echo "OK ($found)"
#	else
#		echo not found
#		PR_AUTO_ready=0
#		FULL_ready=0
#	fi
#done

#if [ $PR_AUTO_ready != "1" ] ; then
#	echo ''
#	echo '(!) required package(s) missing; abort'
#	exit 1
#fi

###########################################################################

#xorgfilefound=`find /etc -name xorg.conf -print`
#if [ -e /etc/X11/xorg.conf ] ; then
#   if [ "$xorgfilefound" == "" ] ; then
#      touch /etc/X11/xorg.conf
#   fi
#fi

echo ''
echo '(Step '$nextStep') Install TouchKit'
make install						|| exit 1
make activate						|| exit 1

echo ''
echo '(I) Please RESTART your X Window Server.'
echo 'please waiting dor system reboot'
#reboot	
