fleet/it-and-security/lib/linux/scripts/uninstall-fleetd-linux.sh
jkatz01 5fa2550614
30259 - fix linux uninstall script (#30488)
I tested the uninstall script by:
- Making a new agent package and installing it
- Checking with `dpkg --get-selections | grep 'fleet'` that
fleet-osquery is installed
- Checking with `sudo systemctl list-units | grep 'orbit'` that
orbit.service is running
- Uninstalling the package with uninstall-fleetd-linux.sh
- Checking the above commands again to see that fleet-osquery and
orbit.service are uninstalled.

# Checklist for submitter

If some of the following don't apply, delete the relevant line.

<!-- Note that API documentation changes are now addressed by the
product design team. -->

- [x] Changes file added for user-visible changes in `changes/`,
`orbit/changes/` or `ee/fleetd-chrome/changes`.
See [Changes
files](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/guides/committing-changes.md#changes-files)
for more information.

- For Orbit and Fleet Desktop changes:
   - [x] Manual QA done on one Linux machine (Ubuntu 24 on HP laptop).
2025-07-01 17:50:47 -05:00

46 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
# Please don't delete. This script is used in tests (tools/tuf/test/migration/migration_test.sh), workflors (.github/workflows/), and in the guide here: https://fleetdm.com/guides/how-to-uninstall-fleetd
if [ $(id -u) -ne 0 ]; then
echo "Please run as root"
exit 1
fi
function remove_fleet {
set -x
systemctl stop orbit.service || true
systemctl disable orbit.service || true
rm -rf /var/lib/orbit /opt/orbit /var/log/orbit /usr/local/bin/orbit /etc/default/orbit /usr/lib/systemd/system/orbit.service
# Remove any package references
if command -v dpkg > /dev/null; then
dpkg --purge fleet-osquery || true
elif command -v rpm > /dev/null; then
rpm -e fleet-osquery || true
fi
# Kill any running Fleet processes
pkill -f fleet-desktop || true
# Reload systemd configuration
systemctl daemon-reload
echo "Fleetd has been successfully removed from the system."
}
if [ "$1" = "remove" ]; then
# We are in the detached child process
# Give the parent process time to report the success before removing
echo "inside remove process" >>/tmp/fleet_remove_log.txt
sleep 15
# We are root
remove_fleet >>/tmp/fleet_remove_log.txt 2>&1
else
# We are in the parent shell, start the detached child and return success
echo "Removing fleetd, system will be unenrolled in 15 seconds..."
echo "Executing detached child process"
# We are root
bash -c "bash $0 remove >/dev/null 2>/dev/null </dev/null &"
fi