fleet/ee/maintained-apps/inputs/homebrew/scripts/cleanmymac-uninstall.sh
Allen Houchins 3c63c81331
Add multiple macOS FMAs (#37036)
This pull request adds support for several new macOS applications to the
maintained apps system. It introduces metadata and installer/uninstaller
scripts for each app and updates the main apps output file to include
them with descriptions and platform information. The most significant
changes are grouped below.

**New Application Integrations:**

* Added support for `balenaEtcher`, including metadata
(`balenaetcher.json`), installer/uninstaller scripts, and entry in
`apps.json` with description.
[[1]](diffhunk://#diff-929134bb1d28b55d168f4dc3e35f9f08a0d1e45d46bcf6f4183f99f79428433cR1-R8)
[[2]](diffhunk://#diff-8d03c90ab45b7ed733912e7ba94c2601b8a80047896ed6812dbacb91d538b2edR1-R21)
[[3]](diffhunk://#diff-4c1446cfc02c6bb0bda874481e333c65b84e184fcea52f656b49a6489f73c9c2R165-R171)
* Added support for `CleanMyMac`, including metadata
(`cleanmymac.json`), installer/uninstaller scripts, and entry in
`apps.json` with description.
[[1]](diffhunk://#diff-a3148bf2381a87133a9daf9bb676da3561b68458fac4a8bf5a13ee4b2ca1e6a0R1-R8)
[[2]](diffhunk://#diff-3c53d70fb16a8d91fddbe12c90115a282738652ce25e082795baff88d67cb4afR1-R21)
[[3]](diffhunk://#diff-4c1446cfc02c6bb0bda874481e333c65b84e184fcea52f656b49a6489f73c9c2R305-R318)
* Added support for `CleanShot X`, `Clockify Desktop`, `CotEditor`,
`DBeaver` (Community, Enterprise, Lite, Ultimate), `DeepL`, and
`Dialpad` with metadata files and entries in `apps.json`.
[[1]](diffhunk://#diff-371522e9c06a5ea355102f316203a3e6c9227337e418fa477c6a70e04f558da4R1-R8)
[[2]](diffhunk://#diff-32597ee59d679b740ccc62e2bf05354aa0918a3662d9949d27f117526128ab62R1-R8)
[[3]](diffhunk://#diff-1be741483848b645a6c7e85e58d79c3b5eb1b4353b27f57316c00ec6e176b6e5R1-R8)
[[4]](diffhunk://#diff-dff15693362fcb9e4b7d6dde7a8eafa67806903a0b05d6ab07e2eb923cf7bbe1R1-R8)
[[5]](diffhunk://#diff-cef23a1c4601fb334e1bd6cc7f4a96a7e25550b08b381942998bb108fc64d58dR1-R8)
[[6]](diffhunk://#diff-5df1e672d5a9546c5acbfe9d82ddddfa82bc946d1c0b18900d5bc055efbbcdd9R1-R8)
[[7]](diffhunk://#diff-b249fc32817185ddef560ebee1c3271e480c8ad3a15e276b9603f573d24b76b2R1-R8)
[[8]](diffhunk://#diff-0c12c073b1a807c9688bc529c1c5ab8682fbd6e8ddeb70cfa44ce9758e5ae4e7R1-R8)
[[9]](diffhunk://#diff-d9099249f5d9ce758e4c9dfe6a5df22821ff466fdcfecb8138f1880b7f9c76e6R1-R8)
[[10]](diffhunk://#diff-4c1446cfc02c6bb0bda874481e333c65b84e184fcea52f656b49a6489f73c9c2R305-R318)
[[11]](diffhunk://#diff-4c1446cfc02c6bb0bda874481e333c65b84e184fcea52f656b49a6489f73c9c2R340-R346)
[[12]](diffhunk://#diff-4c1446cfc02c6bb0bda874481e333c65b84e184fcea52f656b49a6489f73c9c2R361-R367)
[[13]](diffhunk://#diff-4c1446cfc02c6bb0bda874481e333c65b84e184fcea52f656b49a6489f73c9c2R403-R451)

**Installer and Uninstaller Scripts:**

* Added custom install and uninstall shell scripts for `balenaEtcher`
and `CleanMyMac`, referenced in their respective output JSON files for
automated deployment and removal.
[[1]](diffhunk://#diff-8d03c90ab45b7ed733912e7ba94c2601b8a80047896ed6812dbacb91d538b2edR1-R21)
[[2]](diffhunk://#diff-3c53d70fb16a8d91fddbe12c90115a282738652ce25e082795baff88d67cb4afR1-R21)

**App Metadata and Categorization:**

* Each new app includes metadata such as name, unique identifier,
installer format, slug, and default categories in its respective input
JSON file for improved organization and categorization.
[[1]](diffhunk://#diff-929134bb1d28b55d168f4dc3e35f9f08a0d1e45d46bcf6f4183f99f79428433cR1-R8)
[[2]](diffhunk://#diff-a3148bf2381a87133a9daf9bb676da3561b68458fac4a8bf5a13ee4b2ca1e6a0R1-R8)
[[3]](diffhunk://#diff-371522e9c06a5ea355102f316203a3e6c9227337e418fa477c6a70e04f558da4R1-R8)
[[4]](diffhunk://#diff-32597ee59d679b740ccc62e2bf05354aa0918a3662d9949d27f117526128ab62R1-R8)
[[5]](diffhunk://#diff-1be741483848b645a6c7e85e58d79c3b5eb1b4353b27f57316c00ec6e176b6e5R1-R8)
[[6]](diffhunk://#diff-dff15693362fcb9e4b7d6dde7a8eafa67806903a0b05d6ab07e2eb923cf7bbe1R1-R8)
[[7]](diffhunk://#diff-cef23a1c4601fb334e1bd6cc7f4a96a7e25550b08b381942998bb108fc64d58dR1-R8)
[[8]](diffhunk://#diff-5df1e672d5a9546c5acbfe9d82ddddfa82bc946d1c0b18900d5bc055efbbcdd9R1-R8)
[[9]](diffhunk://#diff-b249fc32817185ddef560ebee1c3271e480c8ad3a15e276b9603f573d24b76b2R1-R8)
[[10]](diffhunk://#diff-0c12c073b1a807c9688bc529c1c5ab8682fbd6e8ddeb70cfa44ce9758e5ae4e7R1-R8)
[[11]](diffhunk://#diff-d9099249f5d9ce758e4c9dfe6a5df22821ff466fdcfecb8138f1880b7f9c76e6R1-R8)

**Main Apps Output Update:**

* Updated `apps.json` to include all new applications, complete with
platform, unique identifier, and descriptive text for each, ensuring
visibility in the maintained apps catalog.
[[1]](diffhunk://#diff-4c1446cfc02c6bb0bda874481e333c65b84e184fcea52f656b49a6489f73c9c2R165-R171)
[[2]](diffhunk://#diff-4c1446cfc02c6bb0bda874481e333c65b84e184fcea52f656b49a6489f73c9c2R305-R318)
[[3]](diffhunk://#diff-4c1446cfc02c6bb0bda874481e333c65b84e184fcea52f656b49a6489f73c9c2R340-R346)
[[4]](diffhunk://#diff-4c1446cfc02c6bb0bda874481e333c65b84e184fcea52f656b49a6489f73c9c2R361-R367)
[[5]](diffhunk://#diff-4c1446cfc02c6bb0bda874481e333c65b84e184fcea52f656b49a6489f73c9c2R403-R451)
2025-12-09 23:14:56 -06:00

132 lines
4 KiB
Bash
Executable file

#!/bin/sh
# variables
APPDIR="/Applications/"
LOGGED_IN_USER=$(scutil <<< "show State:/Users/ConsoleUser" | awk '/Name :/ { print $3 }')
# functions
quit_application() {
local bundle_id="$1"
local timeout_duration=10
# check if the application is running
if ! osascript -e "application id \"$bundle_id\" is running" 2>/dev/null; then
return
fi
local console_user
console_user=$(stat -f "%Su" /dev/console)
if [[ $EUID -eq 0 && "$console_user" == "root" ]]; then
echo "Not logged into a non-root GUI; skipping quitting application ID '$bundle_id'."
return
fi
echo "Quitting application '$bundle_id'..."
# try to quit the application within the timeout period
local quit_success=false
SECONDS=0
while (( SECONDS < timeout_duration )); do
if osascript -e "tell application id \"$bundle_id\" to quit" >/dev/null 2>&1; then
if ! pgrep -f "$bundle_id" >/dev/null 2>&1; then
echo "Application '$bundle_id' quit successfully."
quit_success=true
break
fi
fi
sleep 1
done
if [[ "$quit_success" = false ]]; then
echo "Application '$bundle_id' did not quit."
fi
}
remove_launchctl_service() {
local service="$1"
local booleans=("true" "false")
local plist_status
local paths
local should_sudo
echo "Removing launchctl service ${service}"
for should_sudo in "${booleans[@]}"; do
plist_status=$(launchctl list "${service}" 2>/dev/null)
if [[ $plist_status == \{* ]]; then
if [[ $should_sudo == "true" ]]; then
sudo launchctl remove "${service}"
else
launchctl remove "${service}"
fi
sleep 1
fi
paths=(
"/Library/LaunchAgents/${service}.plist"
"/Library/LaunchDaemons/${service}.plist"
)
# if not using sudo, prepend the home directory to the paths
if [[ $should_sudo == "false" ]]; then
for i in "${!paths[@]}"; do
paths[i]="${HOME}${paths[i]}"
done
fi
for path in "${paths[@]}"; do
if [[ -e "$path" ]]; then
if [[ $should_sudo == "true" ]]; then
sudo rm -f -- "$path"
else
rm -f -- "$path"
fi
fi
done
done
}
trash() {
local logged_in_user="$1"
local target_file="$2"
local timestamp="$(date +%Y-%m-%d-%s)"
local rand="$(jot -r 1 0 99999)"
# replace ~ with /Users/$logged_in_user
if [[ "$target_file" == ~* ]]; then
target_file="/Users/$logged_in_user${target_file:1}"
fi
local trash="/Users/$logged_in_user/.Trash"
local file_name="$(basename "${target_file}")"
if [[ -e "$target_file" ]]; then
echo "removing $target_file."
mv -f "$target_file" "$trash/${file_name}_${timestamp}_${rand}"
else
echo "$target_file doesn't exist."
fi
}
remove_launchctl_service 'com.macpaw.CleanMyMac5.HealthMonitor'
remove_launchctl_service 'com.macpaw.CleanMyMac5.Menu'
quit_application 'com.macpaw.CleanMyMac5'
quit_application 'com.macpaw.CleanMyMac5.HealthMonitor'
quit_application 'com.macpaw.CleanMyMac5.Menu'
sudo rm -rf '/Library/PrivilegedHelperTools/com.macpaw.CleanMyMac5.Agent'
sudo rm -rf "$APPDIR/CleanMyMac_5.app"
trash $LOGGED_IN_USER '/Library/LaunchDaemons/com.macpaw.CleanMyMac5.Agent.plist'
trash $LOGGED_IN_USER '/Library/PrivilegedHelperTools/com.macpaw.CleanMyMac5.Agent'
trash $LOGGED_IN_USER '/Users/Shared/CleanMyMac_5'
trash $LOGGED_IN_USER '~/Library/Application Scripts/S8EX82NJP6.com.macpaw.CleanMyMac5'
trash $LOGGED_IN_USER '~/Library/Application Support/CleanMyMac_5'
trash $LOGGED_IN_USER '~/Library/Caches/com.macpaw.CleanMyMac5'
trash $LOGGED_IN_USER '~/Library/Group Containers/S8EX82NJP6.com.macpaw.CleanMyMac5'
trash $LOGGED_IN_USER '~/Library/HTTPStorages/com.macpaw.CleanMyMac5'
trash $LOGGED_IN_USER '~/Library/HTTPStorages/com.macpaw.CleanMyMac5.binarycookies'
trash $LOGGED_IN_USER '~/Library/LaunchAgents/com.macpaw.CleanMyMac5.Updater.plist'
trash $LOGGED_IN_USER '~/Library/Logs/com.macpaw.CleanMyMac5'
trash $LOGGED_IN_USER '~/Library/Preferences/com.macpaw.CleanMyMac5.plist'
trash $LOGGED_IN_USER '~/Library/Saved Application State/com.macpaw.CleanMyMac5.savedState'