#!/bin/bash
target_dir="/opt/pqlabs"
cd $(dirname "$0")
cur_dir=$(pwd)

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

echo "PQLabs MultiTouch DriverKit install..."
echo "testing the \"sudo\" ..."
sudo echo "OK."
if [ $? -ne 0 ]; then
    echo "Failed, plase retry later, or switch to \"root\" by \"su\" and retry."    
    exit 1
fi

sudo chmod +x prepare.sh
sudo ./prepare.sh
if [ $? -ne 0 ]; then
	echo "prepare failed, exit install."
	exit 1
fi

sudo mkdir -p $target_dir

# driver install
echo "install driver..."
cd ${cur_dir}/driver
sudo chmod +x install.sh
sudo ./install.sh
cd $cur_dir #back

# platform install
echo "install platform..."
cd ${cur_dir}/platform
sudo chmod +x install.sh
sudo ./install.sh ${target_dir}/platform
cd $cur_dir #back

#
sudo cp -f uninstall.sh $target_dir
sudo chmod +x ${target_dir}/uninstall.sh
cd $cur_dir

#check ubuntu 14.04 for reboot or relog 
is_ubuntu=0
is_ubuntu_14_later=0
linux_release=$(cat /etc/*-release)
case "$linux_release" in
      *Ubuntu*) is_ubuntu=1;;
esac

if [ $is_ubuntu -ne 0 ]; then
    is_ubuntu_14_later=1
    ubuntu_14_version="14.04"
    ubuntu_release=$(lsb_release -sr)
    if [ $ubuntu_release \< $ubuntu_14_version ]; then
        is_ubuntu_14_later=0
    fi
fi
if [ $is_ubuntu_14_later -ne 0 ]; then
    echo " need relog or restart the X server for the Ubuntu multitouch gesture."
fi

exit 0
