#!/bin/bash

# Script written by Sebastian Santos in January 2019
# Note: Please do not remove the author's name from this script.
# Updated by sebastian santos on December 8 2023
# Check for root privileges
if [ "$EUID" -ne 0 ]; then
    echo "Please run as root."
    exit 1
fi

# Log file path
logFilePath="/var/log/F1EDLP.log"

# Check if Forcepoint DLP Endpoint is installed
if [ -d "/Applications/Forcepoint DLP Endpoint.app" ]; then
    # Get the installed version
    #AppVersion=$(/usr/bin/defaults read "/Applications/Forcepoint DLP Endpoint.app/Contents/Info.plist" CFBundleShortVersionString)
    
    # Check if the version is one of the specified versions
    #if [[ $AppVersion == "23.04.0377" || $AppVersion == "23.10.0385" || $AppVersion == "23.11" ]]; then #Make sure you add the full version pf DLP you are trying to uninstall
        # Uninstall if version matches
     #   password="forcepoint"  # Adjust the password as needed
      #  echo "Uninstalling DLP version $AppVersion"
    #else
        # Uninstall if version doesn't match
     #   password="forcepoint"  # Adjust the password as needed
      #  echo "Uninstalling older version of DLP"
    #fi
    password="forcepoint"
    # Perform the uninstallation
    if echo "$password" | sudo -S /usr/local/sbin/wepsvc --uninstall --password "$password"; then
        echo "$(date '+%Y-%m-%d %H:%M:%S') - Uninstalled DLP version $AppVersion" >> "$logFilePath"
    else
        echo "Failed to uninstall DLP version $AppVersion"
        exit 1
    fi
else
    # If Forcepoint DLP Endpoint is not installed
    echo "Forcepoint DLP Endpoint is not installed"
fi

# Display a pop-up window notifying the user about the upcoming restart
osascript -e 'display dialog "F1E was uninstalled successfully" buttons {"OK"} default button "OK" with title "Uninstall"'

exit 0