Skip to content

Instantly share code, notes, and snippets.

@pythoninthegrass
Forked from mikedamm/gist:d0ef2291a3c4eecdc35a
Last active October 29, 2020 22:18
Show Gist options
  • Save pythoninthegrass/8387cf9859bc1d7e7f45fade30a52dd6 to your computer and use it in GitHub Desktop.
Save pythoninthegrass/8387cf9859bc1d7e7f45fade30a52dd6 to your computer and use it in GitHub Desktop.
Remove McAfee Agent and McAfee Endpoint Security for Mac
#!/usr/bin/env bash
# See McAfee KBs:
# https://kc.mcafee.com/corporate/index?page=content&id=KB88461 # Remove ENS for Mac (ENSM)
# https://kc.mcafee.com/corporate/index?page=content&id=KB61125 # Remove McAfee Agent
# Exit upon failed command
# set -e
# Logs
logTime=$(date +%Y-%m-%d:%H:%M:%S)
removeENSLog="/tmp/removeENSLog_$logTime.log"
exec &> >(tee -a "$removeENSLog")
# Current user
loggedInUser=$(stat -f%Su /dev/console)
# Working directory
scriptDir=$(cd "$(dirname "$0")" && pwd)
# Ensure running as root
if [[ "$(id -u)" != "0" ]]; then
exec sudo "$0" "$@"
fi
# Set $IFS to eliminate whitespace in pathnames
IFS="$(printf '\n\t')"
# Non-for loop method via find + exec
# find / -name "com.mcafee*" -exec rm {} \; -print
# ENSM REMOVAL
# c-c-c-combo breaker
declare -a comboArray=(
com.mcafee.menulet
com.mcafee.reporter
com.mcafee.virusscan.fmpd
com.mcafee.ssm.ScanManager
com.mcafee.virusscan.ssm.ScanFactory
com.mcafee.ssm.Eupdate
)
# Stop services then remove
for l in "${comboArray[@]}"; do
[[ -f "$l" ]] && echo "Stopped $l."; launchctl stop "$l" || echo "Removed $l."; launchctl remove "$l"
done
# PLISTs
plistsArray=($(sudo find "/Library/LaunchAgents" "/Library/LaunchDaemons" -name "com.mcafee.*" -maxdepth 2))
# echo $plistsArray
# Remove PLISTs
# May replace with: sudo find /Library -name "com.mcafee.*" -maxdepth 3 -exec rm -rf {} \;
for f in "${plistsArray[@]}"; do
echo "Removed $f."
[[ -f "$f" ]] && rm -f "$f"
done
# Directories
dirArray=($(sudo find "/Library/Application Support" "/usr/local" -name "*[Mm]c[Aa]fee*" -maxdepth 5))
# echo $dirArray
# Remove directories
for d in "${dirArray[@]}"; do
echo "Removed $d."
[[ -f "$d" ]] && rm -rf "$d"
done
unset IFS
# MCAFEE AGENT REMOVAL
# Call McAfee Agent Uninstall in subshell
( exec "/Library/McAfee/agent/scripts/uninstall.sh" )
# Reboot
confirm() {
# call with a prompt string or use a default
read -r -p "${1:-Are you sure? [y/N]} " response
case "$response" in
[yY][eE][sS]|[yY])
true
;;
*)
false
;;
esac
}
confirm "Do you want to reboot now [Y/n]?" && /usr/bin/sudo sh -c "reboot"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment