#!/bin/sh
defaultConfigIniStr="DefaultEpsConfig.ini"
cynetEpsStr="CynetEPS"
servicePlistStr="com.cyneteps.service.plist"
serviceNameStr="com.cynet.cyneteps_service"
servicePlistFullPathStr="/Library/LaunchDaemons/$servicePlistStr"
fullDiskAccessHelper="FullDiskAccessHelper.app"

# We will try to remove the package
IDENTIFIER1="cynet.com.cyneteps_service"

# The location to copy the contents of files.
INSTALL_LOCATION="/opt/Cynet"

echo "remove previous service if installed"
if [ -f "$servicePlistFullPathStr" ]; then
    echo "Do stop service $serviceNameStr"
    launchctl unload "$servicePlistFullPathStr"
    launchctl remove "$serviceNameStr"
    rm -rf "$servicePlistFullPathStr"
else
    echo "Service is not installed:"
    echo "  try to terminate $cynetEpsStr, if running"
    pkill -9 CynetEPS
    echo "  try to terminate avupdate.bin, if running"
	pkill -9 avupdate.bin
fi

echo "remove installed data and binaries from $INSTALL_LOCATION"
rm -rf $INSTALL_LOCATION
rm -rf /Applications/CynetEPS.app

echo "now, unistall the package"
pkgutil --forget $IDENTIFIER1

echo done
