Skip to content

Commit b3926e8

Browse files
authored
Merge pull request #76 from macadmins/dev
v2.3.1
2 parents 175b67f + e455955 commit b3926e8

File tree

3 files changed

+162
-75
lines changed

3 files changed

+162
-75
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [2.3.1] - 2025-10-06
8+
### Changed
9+
- Refactored the uninstall script with better error handling and logging.
10+
711
## [2.3.0] - 2025-09-18
812
### Changed
913
- Updated UI elements to match the new look introduced in macOS 26 (Tahoe).

SupportCompanion/Info.plist

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
33
<plist version="1.0">
4-
<dict>
5-
<key>CFBundleDevelopmentRegion</key>
6-
<string>$(DEVELOPMENT_LANGUAGE)</string>
7-
<key>CFBundleExecutable</key>
8-
<string>$(EXECUTABLE_NAME)</string>
9-
<key>CFBundleIdentifier</key>
10-
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11-
<key>CFBundleInfoDictionaryVersion</key>
12-
<string>6.0</string>
13-
<key>CFBundleName</key>
14-
<string>$(PRODUCT_NAME)</string>
15-
<key>CFBundlePackageType</key>
16-
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17-
<key>CFBundleIconFile</key>
18-
<string>AppIcon</string>
19-
<key>LSMinimumSystemVersion</key>
20-
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
21-
<key>CFBundleShortVersionString</key>
22-
<string>2.3.0</string>
23-
<key>CFBundleVersion</key>
24-
<string>2.3.0</string>
25-
<key>CFBundleURLTypes</key>
26-
<array>
27-
<dict>
28-
<key>CFBundleURLName</key>
29-
<string>com.github.macadmins.SupportCompanion</string>
30-
<key>CFBundleURLSchemes</key>
31-
<array>
32-
<string>supportcompanion</string>
33-
</array>
34-
</dict>
35-
</array>
36-
<key>SMPrivilegedExecutables</key>
37-
<dict>
38-
<key>com.github.macadmins.SupportCompanion.helper</key>
39-
<string>anchor apple generic and identifier &quot;com.github.macadmins.SupportCompanion.helper&quot; and (certificate leaf[field.1.2.840.113635.100.6.1.9] /* exists */ or certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */ and certificate leaf[field.1.2.840.113635.100.6.1.13] /* exists */ and certificate leaf[subject.OU] = $(TEAM_ID))</string>
40-
</dict>
41-
</dict>
42-
</plist>
4+
<dict>
5+
<key>CFBundleDevelopmentRegion</key>
6+
<string>$(DEVELOPMENT_LANGUAGE)</string>
7+
<key>CFBundleExecutable</key>
8+
<string>$(EXECUTABLE_NAME)</string>
9+
<key>CFBundleIdentifier</key>
10+
<string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
11+
<key>CFBundleInfoDictionaryVersion</key>
12+
<string>6.0</string>
13+
<key>CFBundleName</key>
14+
<string>$(PRODUCT_NAME)</string>
15+
<key>CFBundlePackageType</key>
16+
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
17+
<key>CFBundleIconFile</key>
18+
<string>AppIcon</string>
19+
<key>LSMinimumSystemVersion</key>
20+
<string>$(MACOSX_DEPLOYMENT_TARGET)</string>
21+
<key>CFBundleShortVersionString</key>
22+
<string>2.3.1</string>
23+
<key>CFBundleVersion</key>
24+
<string>2.3.1</string>
25+
<key>CFBundleURLTypes</key>
26+
<array>
27+
<dict>
28+
<key>CFBundleURLName</key>
29+
<string>com.github.macadmins.SupportCompanion</string>
30+
<key>CFBundleURLSchemes</key>
31+
<array>
32+
<string>supportcompanion</string>
33+
</array>
34+
</dict>
35+
</array>
36+
<key>SMPrivilegedExecutables</key>
37+
<dict>
38+
<key>com.github.macadmins.SupportCompanion.helper</key>
39+
<string>anchor apple generic and identifier "com.github.macadmins.SupportCompanion.helper" and (certificate leaf[field.1.2.840.113635.100.6.1.9] /* exists */ or certificate 1[field.1.2.840.113635.100.6.2.6] /* exists */ and certificate leaf[field.1.2.840.113635.100.6.1.13] /* exists */ and certificate leaf[subject.OU] = $(TEAM_ID))</string>
40+
</dict>
41+
</dict>
42+
</plist>
Lines changed: 119 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,123 @@
11
#!/bin/zsh
22

3-
# Script requires root so check for root access
4-
if [ $(id -u) -ne 0 ]; then
5-
echo "Please run this script as root or using sudo"
6-
exit 1
3+
set -u # error on unset vars
4+
5+
# --- helpers ---------------------------------------------------------------
6+
log() { print -- "[uninstall] $*" }
7+
warn() { print -- "[warn] $*" >&2 }
8+
err() { print -- "[error] $*" >&2 }
9+
10+
# run a command, ignore if it fails; print message
11+
_try() {
12+
local desc="$1"; shift
13+
if "$@"; then
14+
log "$desc: ok"
15+
else
16+
warn "$desc: skipped/failed"
17+
fi
18+
}
19+
20+
# delete a file/dir if it exists
21+
_rm_if_exists() {
22+
local path="$1"
23+
if [ -e "$path" ] || [ -L "$path" ]; then
24+
/bin/rm -rf -- "$path" && log "removed: $path" || warn "failed to remove: $path"
25+
else
26+
log "not present: $path"
27+
fi
28+
}
29+
30+
# get console user + uid
31+
get_console_user() {
32+
/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" \
33+
| /usr/bin/awk '/Name :/ && $3 != "loginwindow" { print $3 }'
34+
}
35+
get_console_uid() {
36+
/usr/sbin/scutil <<< "show State:/Users/ConsoleUser" \
37+
| /usr/bin/awk '/kCGSSessionUserIDKey/ {print $NF; exit}'
38+
}
39+
40+
# --- preflight -------------------------------------------------------------
41+
if [ "$(id -u)" -ne 0 ]; then
42+
err "Please run this script as root or using sudo"
43+
exit 1
744
fi
8-
# Use Apple Recommended Method to detect the user signed in to the desktop
9-
current_user=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }')
10-
console_user_uid=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/kCGSSessionUserIDKey/ {print $NF; exit}' )
11-
# Kill the process
12-
echo "Killing the process..."
13-
pkill -f SupportCompanion
14-
# Remove user defaults
15-
echo "Removing user defaults..."
16-
sudo -u "${current_user}" defaults delete com.github.macadmins.SupportCompanion
17-
# Unload launchctl job
18-
echo "Unloading helepr launchctl job..."
19-
launchctl unload -w /Library/LaunchDaemons/com.github.macadmins.SupportCompanion.helper.plist
20-
# Remove launchctl job
21-
echo "Removing helper launchctl job..."
22-
rm -f /Library/LaunchDaemons/com.github.macadmins.SupportCompanion.helper.plist
23-
# Remove launch agent
24-
if [ -f "/Library/LaunchAgents/com.github.macadmins.SupportCompanion.agent.plist" ]; then
25-
echo "Unloading launch agent..."
26-
/bin/launchctl asuser "${console_user_uid}" /bin/launchctl unload -w /Library/LaunchAgents/com.github.macadmins.SupportCompanion.agent.plist
27-
echo "Removing launch agent..."
28-
rm /Library/LaunchAgents/com.github.macadmins.SupportCompanion.agent.plist
45+
46+
APP_ID="com.github.macadmins.SupportCompanion"
47+
HELPER_ID="com.github.macadmins.SupportCompanion.helper"
48+
AGENT_ID="com.github.macadmins.SupportCompanion.agent"
49+
50+
APP_PATH="/Applications/SupportCompanion.app"
51+
HELPER_PATH="/Library/PrivilegedHelperTools/${HELPER_ID}"
52+
DAEMON_PLIST="/Library/LaunchDaemons/${HELPER_ID}.plist"
53+
AGENT_PLIST="/Library/LaunchAgents/${AGENT_ID}.plist"
54+
55+
CONSOLE_USER=$(get_console_user || true)
56+
CONSOLE_UID=$(get_console_uid || true)
57+
58+
log "Console user: ${CONSOLE_USER:-unknown} (uid ${CONSOLE_UID:-n/a})"
59+
60+
# --- stop processes --------------------------------------------------------
61+
log "Stopping application and helper if running"
62+
_try "kill app" pkill -f SupportCompanion
63+
64+
# --- defaults cleanup (non-fatal) -----------------------------------------
65+
if [ -n "${CONSOLE_USER:-}" ]; then
66+
# Only attempt if domain exists to avoid noisy errors
67+
if sudo -u "$CONSOLE_USER" /usr/bin/defaults domains | /usr/bin/grep -q -- "$APP_ID"; then
68+
_try "delete user defaults" sudo -u "$CONSOLE_USER" /usr/bin/defaults delete "$APP_ID"
69+
else
70+
log "user defaults domain not present: $APP_ID"
71+
fi
72+
else
73+
warn "No console user detected; skipping user defaults removal"
2974
fi
30-
# Remove the app
31-
echo "Removing the app..."
32-
rm -rf /Applications/SupportCompanion.app
33-
# Remove app data
34-
echo "Removing helper..."
35-
rm -rf "/Library/PrivilegedHelperTools/com.github.macadmins.SupportCompanion.helper"
36-
# Forget the package
37-
echo "Forgetting the package..."
38-
pkgutil --forget com.github.macadmins.SupportCompanion > /dev/null 2>&1
39-
pkgutil --forget com.github.macadmins.SupportCompanion.LaunchAgent > /dev/null 2>&1
40-
pkgutil --forget com.github.macadmins.SupportCompanion.suite > /dev/null 2>&1
75+
76+
# --- launchd: daemon (helper) ---------------------------------------------
77+
if [ -f "$DAEMON_PLIST" ]; then
78+
log "Unloading helper launch daemon"
79+
_try "launchctl unload daemon" /bin/launchctl unload -w "$DAEMON_PLIST"
80+
else
81+
log "daemon plist not present: $DAEMON_PLIST"
82+
fi
83+
84+
# Remove daemon plist regardless of unload outcome
85+
_rm_if_exists "$DAEMON_PLIST"
86+
87+
# --- launchd: agent (per-user) --------------------------------------------
88+
if [ -f "$AGENT_PLIST" ]; then
89+
if [ -n "${CONSOLE_UID:-}" ]; then
90+
log "Unloading launch agent for uid $CONSOLE_UID"
91+
_try "launchctl unload agent" /bin/launchctl asuser "$CONSOLE_UID" /bin/launchctl unload -w "$AGENT_PLIST"
92+
else
93+
warn "No console uid; unloading agent in current context"
94+
_try "launchctl unload agent (fallback)" /bin/launchctl unload -w "$AGENT_PLIST"
95+
fi
96+
else
97+
log "agent plist not present: $AGENT_PLIST"
98+
fi
99+
100+
# Remove agent plist
101+
_rm_if_exists "$AGENT_PLIST"
102+
103+
# --- remove bits -----------------------------------------------------------
104+
log "Removing installed components"
105+
_rm_if_exists "$APP_PATH"
106+
_rm_if_exists "$HELPER_PATH"
107+
108+
# --- pkg receipts -------------------------------------------
109+
forget_if_present() {
110+
local package="$1"
111+
if /usr/sbin/pkgutil --pkgs | /usr/bin/grep -qx -- "$package"; then
112+
_try "forget $package" /usr/sbin/pkgutil --forget "$package"
113+
else
114+
log "receipt not present: $package"
115+
fi
116+
}
117+
118+
forget_if_present "${APP_ID}"
119+
forget_if_present "${APP_ID}.LaunchAgent"
120+
forget_if_present "${APP_ID}.suite"
121+
122+
log "Uninstall completed"
123+
exit 0

0 commit comments

Comments
 (0)