FMA: missing pieces (#22593)
# 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. -->
- [ ] 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/Committing-Changes.md#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2024-10-03 17:49:27 +00:00
|
|
|
#!/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
|
2024-11-11 22:00:03 +00:00
|
|
|
local should_sudo
|
FMA: missing pieces (#22593)
# 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. -->
- [ ] 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/Committing-Changes.md#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2024-10-03 17:49:27 +00:00
|
|
|
|
|
|
|
|
echo "Removing launchctl service ${service}"
|
|
|
|
|
|
2024-11-11 22:00:03 +00:00
|
|
|
for should_sudo in "${booleans[@]}"; do
|
FMA: missing pieces (#22593)
# 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. -->
- [ ] 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/Committing-Changes.md#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2024-10-03 17:49:27 +00:00
|
|
|
plist_status=$(launchctl list "${service}" 2>/dev/null)
|
|
|
|
|
|
|
|
|
|
if [[ $plist_status == \{* ]]; then
|
2024-11-11 22:00:03 +00:00
|
|
|
if [[ $should_sudo == "true" ]]; then
|
FMA: missing pieces (#22593)
# 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. -->
- [ ] 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/Committing-Changes.md#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2024-10-03 17:49:27 +00:00
|
|
|
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
|
2024-11-11 22:00:03 +00:00
|
|
|
if [[ $should_sudo == "false" ]]; then
|
FMA: missing pieces (#22593)
# 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. -->
- [ ] 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/Committing-Changes.md#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2024-10-03 17:49:27 +00:00
|
|
|
for i in "${!paths[@]}"; do
|
|
|
|
|
paths[i]="${HOME}${paths[i]}"
|
|
|
|
|
done
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
for path in "${paths[@]}"; do
|
|
|
|
|
if [[ -e "$path" ]]; then
|
2024-11-11 22:00:03 +00:00
|
|
|
if [[ $should_sudo == "true" ]]; then
|
FMA: missing pieces (#22593)
# 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. -->
- [ ] 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/Committing-Changes.md#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2024-10-03 17:49:27 +00:00
|
|
|
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)"
|
2024-11-11 22:00:03 +00:00
|
|
|
local rand="$(jot -r 1 0 99999)"
|
FMA: missing pieces (#22593)
# 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. -->
- [ ] 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/Committing-Changes.md#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2024-10-03 17:49:27 +00:00
|
|
|
|
|
|
|
|
# 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."
|
2024-11-11 22:00:03 +00:00
|
|
|
mv -f "$target_file" "$trash/${file_name}_${timestamp}_${rand}"
|
FMA: missing pieces (#22593)
# 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. -->
- [ ] 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/Committing-Changes.md#changes-files)
for more information.
- [ ] Input data is properly validated, `SELECT *` is avoided, SQL
injection is prevented (using placeholders for values in statements)
- [ ] Added support on fleet's osquery simulator `cmd/osquery-perf` for
new osquery data ingestion features.
- [ ] Added/updated tests
- [ ] If paths of existing endpoints are modified without backwards
compatibility, checked the frontend/CLI for any necessary changes
- [ ] If database migrations are included, checked table schema to
confirm autoupdate
- For database migrations:
- [ ] Checked schema for all modified table for columns that will
auto-update timestamps during migration.
- [ ] Confirmed that updating the timestamps is acceptable, and will not
cause unwanted side effects.
- [ ] Ensured the correct collation is explicitly set for character
columns (`COLLATE utf8mb4_unicode_ci`).
- [ ] Manual QA for all new/changed functionality
- For Orbit and Fleet Desktop changes:
- [ ] Orbit runs on macOS, Linux and Windows. Check if the orbit
feature/bugfix should only apply to one platform (`runtime.GOOS`).
- [ ] Manual QA must be performed in the three main OSs, macOS, Windows
and Linux.
- [ ] Auto-update manual QA, from released version of component to new
version (see [tools/tuf/test](../tools/tuf/test/README.md)).
2024-10-03 17:49:27 +00:00
|
|
|
else
|
|
|
|
|
echo "$target_file doesn't exist."
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
remove_launchctl_service 'com.microsoft.VSCode.ShipIt'
|
|
|
|
|
quit_application 'com.microsoft.VSCode'
|
|
|
|
|
sudo rm -rf "$APPDIR/Visual Studio Code.app"
|
|
|
|
|
trash $LOGGED_IN_USER '~/.vscode'
|
|
|
|
|
trash $LOGGED_IN_USER '~/Library/Application Support/Code'
|
|
|
|
|
trash $LOGGED_IN_USER '~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/com.microsoft.vscode.sfl*'
|
|
|
|
|
trash $LOGGED_IN_USER '~/Library/Caches/com.microsoft.VSCode'
|
|
|
|
|
trash $LOGGED_IN_USER '~/Library/Caches/com.microsoft.VSCode.ShipIt'
|
|
|
|
|
trash $LOGGED_IN_USER '~/Library/HTTPStorages/com.microsoft.VSCode'
|
|
|
|
|
trash $LOGGED_IN_USER '~/Library/Preferences/ByHost/com.microsoft.VSCode.ShipIt.*.plist'
|
|
|
|
|
trash $LOGGED_IN_USER '~/Library/Preferences/com.microsoft.VSCode.helper.plist'
|
|
|
|
|
trash $LOGGED_IN_USER '~/Library/Preferences/com.microsoft.VSCode.plist'
|
|
|
|
|
trash $LOGGED_IN_USER '~/Library/Saved Application State/com.microsoft.VSCode.savedState'
|