#!/bin/sh
VER_NUM1=`cat /etc/issue | grep -iE "Ubuntu 1(5|6|7|8|9)|Ubuntu 2(0|1|2|3|4|5|6|7|8|9)|Debian GNU/Linux (9|10|11)|Pardus GNU/Linux |Kylin " | wc -l` ;
VER_NUM2=`lsb_release -a | grep Description | grep -iE "Ubuntu 1(5|6|7|8|9)|Ubuntu 2(0|1|2|3|4|5|6|7|8|9)|Debian GNU/Linux (9|10|11)|Pardus GNU/Linux " | wc -l`

if [ $VER_NUM1 -ne 0 ] || [ $VER_NUM2 -ne 0 ]; then
	systemctl stop dynamsoft.service
	systemctl disable dynamsoft.service
else
	rm -rf /etc/rcS.d/*DynamsoftServiced
	rm -rf /etc/init.d/DynamsoftServiced
fi

ps aux|grep DynamsoftService|grep -v grep|grep -v uninstall|grep -v Mgr|awk '{print $2}'|xargs -r kill -9

UNAME=`env | grep SUDO_USER | cut -d'=' -f2`
rm -rf /home/$UNAME/.config/autostart/dynamsoftservice.desktop
#new
rm -rf /home/$UNAME/.config/autostart/dynamsoftscanning.desktop

rm -rf /usr/bin/DynamsoftServiceMgr
#new
rm -rf /usr/bin/DynamsoftScanningMgr
rm -rf /usr/bin/DynamsoftCertCheckMgr
rm -rf /opt/dynamsoft/DynamsoftService

sed -i '/DynamsoftService/d'  /home/$UNAME/.profile
sed -i '/DynamsoftService/d'  /etc/profile
dpkg -r DynamsoftService

