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

echo "To unistall PQLabs driver kit, all files in \"$target_dir\" will be removed. Unintall now?(y/n)[n]"
read input
if [ "$input" != "y" ]; then
    exit 1
fi

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

#remove
echo "removing platform ..."
cd ${target_dir}/platform
sudo ./uninstall.sh ${target_dir}/platform

echo "removing driver ..."
cd ${target_dir}/driver
sudo ./uninstall.sh ${target_dir}/driver

echo "removing files ..."
cd ..
sudo rm -rf ${target_dir}/driver
sudo rm -f ${target_dir}/uninstall.sh
sudo rmdir --ignore-fail-on-non-empty ${target_dir}
exit 0
