Last active
June 18, 2023 23:57
-
-
Save tylermilner/19c350f4bdf264f3f6d3cd351ed61fb7 to your computer and use it in GitHub Desktop.
A script to aid in setting up a Mac for use as a GitHub Actions self-hosted runner.
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
#!/bin/bash | |
# The name of the runner user account | |
RUNNER_USERNAME="runner" | |
RUNNER_FULLNAME="$RUNNER_USERNAME" | |
# Check for sudo access | |
echo "Checking for root access..." | |
# Check if running as root | |
if [ $EUID != 0 ]; then | |
>&2 echo "Script requires super user privileges. Re-run the script using 'sudo'. Exiting..." | |
exit 1 | |
fi | |
echo "Root access confirmed" | |
# Prompt for the password of the runner user account | |
read -s -p "Enter the password for the runner user account: " RUNNER_PASSWORD | |
echo # No-op to make sure next 'echo' happens on a new line | |
# Create the user account | |
echo "Setting up '$RUNNER_USERNAME' user account..." | |
sysadminctl -addUser "$RUNNER_USERNAME" -fullName "$RUNNER_FULLNAME" -password "$RUNNER_PASSWORD" -admin | |
echo "User account '$RUNNER_USERNAME' created" | |
# Check macOS version | |
MACOS_VERSION=$(sw_vers -productVersion) | |
MAJOR_VERSION=$(echo "$MACOS_VERSION" | cut -d '.' -f 1) | |
# Setup the user account to auto-login for macOS >= 13 | |
# On macOS < 13, auto-login will need to be setup manually in the UI | |
if [ "$MAJOR_VERSION" -ge 13 ]; then | |
echo "Setting up '$RUNNER_USERNAME' user account to auto-login..." | |
sysadminctl -autologin set -userName "$RUNNER_USERNAME" -password "$RUNNER_PASSWORD" | |
sysadminctl -autologin status | |
else | |
echo "macOS < 13 detected. You will need to setup auto-login manually." | |
fi | |
# Disable Spotlight search | |
# echo "Disabling Spotlight..." | |
# launchctl unload -w /System/Library/LaunchDaemons/com.apple.metadata.mds.plist || true | |
# Disable sleep | |
echo "Disabling sleep (error output is normal)..." | |
# These commands produce error output in the terminal, but they can likely be ignored | |
# See https://github.com/LnL7/nix-darwin/issues/359#issuecomment-1408968833 | |
systemsetup -setsleep Never | |
systemsetup -setharddisksleep Never | |
systemsetup -setcomputersleep Never | |
# Disable screen saver and login window after timeout | |
echo "Disabling screen saver and login window after timeout..." | |
defaults write com.apple.screensaver loginWindowIdleTime 0 | |
defaults write com.apple.screensaver idleTime 0 | |
# Turn off animations | |
echo "Disabling animations..." | |
# Disable dock app launch animations | |
defaults write com.apple.dock launchanim -bool false | |
# All done | |
echo "All done." | |
# Prompt to reboot the system | |
read -p "The system needs to be rebooted to complete the setup. Would you like to reboot now? (y/n)" REBOOT | |
if [[ $REBOOT =~ ^[Yy]$ ]]; then | |
echo "Rebooting..." | |
shutdown -r now | |
else | |
echo "Reboot when you get a chance." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment