#!/bin/bash
clear
echo "Your architecture is 64 bit"
echo ""

#Set current working directory to the directory of the script
cd "$(dirname "$0")"

echo "ScanaStudio uninstall script for Ubuntu "
echo "====================================="
echo "(c)2023 IKALOGIC S.A.S. FRANCE"
echo ""
echo "This Install script requires SUDO privileges"
echo ""
sudo echo "" #ask for user's password once for all

if [ -f /etc/udev/rules.d/99-ikalogic.rules ]; then
	echo "[1/5]--- Removing drivers"
	sudo rm /etc/udev/rules.d/99-ikalogic.rules
else
	echo "[1/5]--- Nothing to be done: Ikalogic drivers already removed."
fi

echo "[2/5]--- Nothing to be done: Keeping menu icons the way they are"

if [ -d ~/Ikalogic/ScanaStudio/ ]; then
	echo "[3/5]--- Deleting ScanaStudio from ~/Ikalogic/ScanaStudio/"
	rm -rf ~/Ikalogic/ScanaStudio
else
	echo "[3/5]--- Nothing to be done: ScanaStudio already removed."
fi

if [ -f ~/.local/share/mime/packages/ScanaStudio.xml ]; then
	echo "[4/5]--- Removing ScanaStudio mime types"
	rm ~/.local/share/mime/packages/ScanaStudio.xml
	rm ~/.local/share/applications/ScanaStudio.desktop
	rm ~/.local/share/icons/application-x-ScanaStudio.png
	find ~/.local/share/icons/ -name ScanaStudio.png | xargs sudo rm
else
	echo "[4/5]--- Nothing to be done: ScanaStudio already removed."
fi

echo "[5/5]--- Updating mime database (This may take a few seconds...)"
update-mime-database  ~/.local/share/mime

echo "[---]--- DONE!"
echo ""
echo "You may need to log off and log in again to refresh your desktop"
echo "If you are facing any technical problems, please don't hesitate to contact us"
echo ""
echo "IKALOGIC Team: contact@ikalogic.com"
echo ""
