duplicati/ReleaseBuilder/Resources/MacOS/AppBundle/uninstall.sh
Kenneth Skovhede 250bea997c Updated launchagent installs on MacOS.
This changes the way launchagents are installed via `.pkg` files.

The installers are updated to no longer use `launchtctl load` but rely on `launchctl bootstrap` instead to load in the current user context.

For the Agent, this fixes a problem where the installer would initially start in a root context.
For the GUI package this changes to not rely on `open` to start Duplicati, as that appears to be incompatible with `bootstrap`
The uninstallers are updated handle both `load` / `unload` and `bootstrap` / `bootout` before removing the launchagents.

This fixes #5766
2024-12-13 09:55:25 +01:00

44 lines
1.4 KiB
Bash
Executable file

#!/bin/bash
LAUNCHAGENT_LABEL="com.duplicati.app.launchagent"
LAUNCHAGENT_PLIST="/Library/LaunchAgents/$LAUNCHAGENT_LABEL.plist"
ANY_ULOAD_FAILURES=""
if [ -f "$LAUNCHAGENT_PLIST" ]; then
# Loop through all logged-in users
for USER_ID in $(ps aux | awk '/loginwindow/ && !/awk/ {print $1}' | uniq | xargs id -u); do
# Check if the LaunchAgent is loaded for the user
launchctl print gui/$USER_ID/$LAUNCHAGENT_LABEL > /dev/null 2>&1
if [ $? -eq 0 ]; then
# Unload the LaunchAgent for the user
launchctl bootout gui/$USER_ID "$LAUNCHAGENT_PLIST"
if [ $? -eq 0 ]; then
echo "Successfully unloaded LaunchAgent for user with UID: $USER_ID."
else
echo "Failed to unload LaunchAgent for user with UID: $USER_ID."
ANY_ULOAD_FAILURES="1"
fi
fi
done
# Legacy unload, don't care about the result
/bin/launchctl unload "$LAUNCHAGENT_PLIST" > /dev/null 2>&1
rm "$LAUNCHAGENT_PLIST"
if ! [ -z "$ANY_UNLOAD_FAILURES" ]; then
echo "Failed to unload LaunchAgent for one or more users. A machine restart may be required to fully remove the LaunchAgent."
fi
fi
if [ -d /Applications/Duplicati.app ]; then
rm -rf /Applications/Duplicati.app
echo "Removed /Applications/Duplicati.app"
fi
pkgutil --forget "com.duplicati.app"
pkgutil --forget "com.duplicati.app.daemon"