Skip to content

Instantly share code, notes, and snippets.

@robwilkerson
Last active May 31, 2024 19:40
Show Gist options
  • Save robwilkerson/b785752880575b7a6ca5abe9df71276e to your computer and use it in GitHub Desktop.
Save robwilkerson/b785752880575b7a6ca5abe9df71276e to your computer and use it in GitHub Desktop.
MacOS Bootstrap
#!/usr/bin/env bash
#
# Does the bare minimum that's required before we can begin to kick things off.
# We need homebrew to install git, git to configure the basics, and Proton Drive
# in order to pull down the rest of the MacOS configuration scripts.
#
# curl -sL https://gist.githubusercontent.com/robwilkerson/b785752880575b7a6ca5abe9df71276e/raw | bash
#
set -euxo pipefail
bash -c 'echo "Bootstrapping a (presumably) new MacOS device..."'
# Optionally, set a custom name for the computer
read -rp "Set the computer name ($(scutil --get HostName))" computer_name
if [ -n "${computer_name}" ]; then
scutil --set HostName "${computer_name}"
fi
# Install XCode's command line tools
if [ -z "$(xcode-select -p)" ]; then
xcode-select --install
fi
# Install Homebrew
echo | bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Install a few core essentials immediately
# git: version control
# proton-drive: cloud file storage; all additional init scripts are stored there
brew update
brew install git \
proton-drive
# Create a SSH key to use with Github
if [[ ! -f "${HOME}/.ssh/github-$(scutil --get HostName)" ]]; then
ssh-keygen -t ed25519 -N "" -C "Github SSH Key" -f "${HOME}/.ssh/github-$(scutil --get HostName)"
fi
# Add a SSH config entry for Github using the generated key
# This will allow us to clone the dotfiles repo, but will have to be run
# again to be sure that this computer's config gets this computer's key.
cat << EOF >> ~/.ssh/config
Host github.com
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/github-$(scutil --get HostName)
EOF
#
# Sign in to a few key applications
#
# Mac App Store
read -rsn1 -p "Please sign in to the App Store; press any key to launch"; echo
open '/System/Applications/App Store.app'
read -rsn1 -p "Once signed in to the App Store, press any key to continue."; echo
# Proton Drive (to pull init scripts)
read -rsn1 -p "Please sign in to Proton Drive; press any key to launch"; echo
open "/Applications/Proton Drive.app"
read -rsn1 -p "Once signed in to Proton Drive, press any key to continue."; echo
# Copy the public key to the clipboard and open the Github settings page
echo "Copying the public key to the clipboard and opening Github..."
cat "${HOME}/.ssh/github-$(scutil --get HostName).pub" | pbcopy
open https://github.com/settings/keys
read -rsn1 -p "Press any key to continue after adding the public key to Github"; echo
cat << EOF
The basics are in place! Give the macos-setup
scripts time to download and kick them off!
EOF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment