Last active
March 24, 2018 23:10
-
-
Save albertico-gov/93f15b9a271bb68392ed228fc318a4b2 to your computer and use it in GitHub Desktop.
Fish script to disable the MacOS enrollment reminders.
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 fish | |
set -g SYSTEM_LAUNCH_AGENTS_DIR "/System/Library/LaunchAgents" | |
set -g SYSTEM_LAUNCH_AGENTS_DISABLED_DIR "/System/Library/LaunchAgentsDisabled" | |
set -g SYSTEM_LAUNCH_DAEMONS_DIR "/System/Library/LaunchDaemons" | |
set -g SYSTEM_LAUNCH_DAEMONS_DISABLED_DIR "/System/Library/LaunchDaemonsDisabled" | |
set -g APPLE_MANAGED_AGENT "com.apple.ManagedClientAgent.enrollagent.plist" | |
set -g APPLE_MANAGED_CLIENT "com.apple.ManagedClient.enroll.plist" | |
###################### | |
## HELPER FUNCTIONS ## | |
###################### | |
function __mac_exit_on_error | |
if not test $status = 0 | |
echo "Something went wrong... Aborting!" | |
exit 1 | |
end | |
end | |
function __mac_sudo_create_dir | |
set -l dir $argv[1] | |
if not test -d "$dir" | |
echo "Creating directory '$dir'" | |
sudo mkdir "$dir" | |
__mac_exit_on_error | |
end | |
end | |
function __mac_sudo_backup_and_remove_file | |
set -l file $argv[1] | |
set -l file_backup $argv[2] | |
if test -e "$file" | |
echo "Copying '$file'" | |
echo " to: '$file_backup'" | |
sudo cp "$file" "$file_backup" | |
__mac_exit_on_error | |
echo "Removing '$file'" | |
sudo rm "$file" | |
__mac_exit_on_error | |
else | |
echo "File '$file' NOT found... Skipping." | |
end | |
end | |
############ | |
## SCRIPT ## | |
############ | |
echo "" | |
echo "Disabling your MacOS enrollment reminders." | |
echo "" | |
echo "The script will require that you have administrator privileges." | |
echo "You may be required to enter your password." | |
echo "" | |
if not command -sq csrutil | |
__mac_exit_on_error | |
end | |
if string match -rq "status: disabled.\$" (csrutil status) | |
# Create directories to keep backup copy of agent/daemon. | |
__mac_sudo_create_dir "$SYSTEM_LAUNCH_AGENTS_DISABLED_DIR" | |
__mac_sudo_create_dir "$SYSTEM_LAUNCH_DAEMONS_DISABLED_DIR" | |
# Making backup copy and removing agent. | |
set -l agent_file "$SYSTEM_LAUNCH_AGENTS_DIR/$APPLE_MANAGED_AGENT" | |
set -l agent_file_backup "$SYSTEM_LAUNCH_AGENTS_DISABLED_DIR/$APPLE_MANAGED_AGENT."(date '+%Y%m%d_%H%M%S') | |
__mac_sudo_backup_and_remove_file "$agent_file" "$agent_file_backup" | |
# Making backup copy and removing daemon. | |
set -l client_file "$SYSTEM_LAUNCH_DAEMONS_DIR/$APPLE_MANAGED_CLIENT" | |
set -l client_file_backup "$SYSTEM_LAUNCH_DAEMONS_DISABLED_DIR/$APPLE_MANAGED_CLIENT."(date '+%Y%m%d_%H%M%S') | |
__mac_sudo_backup_and_remove_file "$client_file" "$client_file_backup" | |
# Done! | |
echo "" | |
echo "All done!" | |
echo "" | |
echo "Don't forget to ENABLE MacOS System Integrity Protection again." | |
echo "------" | |
echo " * Enable executing the following steps:" | |
echo " a. Turn off your Mac (Apple > Shut Down)" | |
echo " b. Hold down Command-R and press the Power button until the Apple logo appears." | |
echo " c. Wait for the Recovery OS to boot, then choose menu: Utilities > Terminal" | |
echo " d. Enter 'csrutil enable'" | |
echo " e. Enter 'reboot'" | |
echo " * Wait for MacOS to boot and login as usual." | |
echo " * Open your Terminal and enter 'csrutil status' to verify that System Integrity Protection is enabled." | |
echo "------" | |
else | |
echo "MacOS System Integrity Protection must be DISABLED." | |
echo "------" | |
echo " * Disable executing the following steps:" | |
echo " a. Turn off your Mac (Apple > Shut Down)" | |
echo " b. Hold down Command-R and press the Power button until the Apple logo appears." | |
echo " c. Wait for the Recovery OS to boot, then choose menu: Utilities > Terminal" | |
echo " d. Enter 'csrutil disable'." | |
echo " e. Enter 'reboot'." | |
echo " * Wait for MacOS to boot and login with an administrator user." | |
echo " * Execute this script again." | |
echo "------" | |
exit 1 | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment