Created
March 31, 2020 21:03
-
-
Save eskerda/7f7ee131744ddee2300005c83c5072da to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
function confirm { | |
if [[ $FORCE == 1 ]]; then | |
return 0 | |
fi | |
local ok | |
read -r ok | |
[[ $ok == "$1" ]] | |
} | |
function remove_profile { | |
profiles -R -p $1 | |
} | |
function kill_loop { | |
while true; do | |
kill -9 $(ps aux | grep /opt/fleetsmith | awk '{print $2}') | |
sleep 0.1 | |
done | |
} | |
function on_exit { | |
[[ -z $pid ]] && return | |
>&2 echo "Killing kill loop :)" | |
kill -9 $pid | |
} | |
function main { | |
[[ $UID != 0 ]] && >&2 echo "this script must be run as root! sudo it" | |
[[ $UID == 0 ]] || exit 1 | |
FORCE=0 | |
[[ $1 == "--force" ]] && FORCE=1 | |
trap on_exit EXIT | |
fleet_profiles=$(profiles -Lv | grep "name: $4" -4 | awk -F": " '/attribute: profileIdentifier/{print $NF}' | grep fleetsmith) | |
# Create a "disabled" folder. This means none of these services will run on | |
# startup. They are still on the system, so you can check them out! | |
mkdir -p /Library/LaunchAgents/disabled | |
mkdir -p /Library/LaunchDaemons/disabled | |
>&2 echo "Starting kill loop..." | |
kill_loop &> /dev/null & | |
pid=$! | |
pushd /Library/LaunchAgents | |
>&2 echo "Disabling fleetsmith LaunchAgents ($PWD/disabled)" | |
mv *fleetsmith* disabled &> /dev/null | |
popd | |
pushd /Library/LaunchDaemons | |
>&2 echo "Disabling fleetsmith LaunchDaemons ($PWD/disabled)" | |
mv *fleetsmith* disabled &> /dev/null | |
popd | |
>&2 echo "Removing FleetSmith profiles:" | |
for profile in $fleet_profiles; do | |
>&2 printf "Remove: $profile ? n[y] " | |
confirm "n" || remove_profile $profile | |
done | |
>&2 echo "Now it's a good idea to restart your computer" | |
if [[ $FORCE == 0 ]]; then | |
>&2 printf "Say \"yes\" to restart it: " | |
confirm "yes" && reboot && wait | |
fi | |
>&2 echo "Not restarting, kill loop still running" | |
>&2 echo "Ctrl+C to bye me" | |
wait | |
} | |
pushd() { builtin pushd $1 > /dev/null; } | |
popd() { builtin popd > /dev/null; } | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment