Created
August 13, 2019 05:40
-
-
Save boldfield/395ad19828472d4796b22915b5e11afc to your computer and use it in GitHub Desktop.
Bash script to bootstrap a new Mac OS Machine
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 | |
# CHECKPOINTING -- INCOMPLETE SCRIPT | |
# A script to bootstrap a new Mac OS machine from scratch using ansible and | |
# the approach taken here: https://github.com/geerlingguy/mac-dev-playbook#installation | |
# To use this script, for that repo, update to reflect requirements to your system, and | |
# change the following to your github username: | |
GITHUB_USER=boldfield | |
# Location that temporary files will be stored. Directory will be removed | |
# at the end of the script. | |
BOOTSTRAP_DIR="/tmp/bootstrap" | |
# Make sure to add the install location for pip to our path | |
# Assumes python2.7, which is currently the default for MacOS | |
PATH="$PATH:/Users/$USER/Library/Python/2.7/bin/" | |
# Evaluate required commands | |
PIP=$(command -v pip) | |
ANSIBLE=$(command -v ansible) | |
CURL=$(command -v curl) # Avoid any aliasing which may be in place | |
# PIP installation requirements | |
GET_PIP="${BOOTSTRAP_DIR}/get-pip.py" | |
GET_PIP_URL="https://bootstrap.pypa.io/get-pip.py" | |
# XCode installation requirements | |
XCODE_CLI_DIR="/Library/Developer/CommandLineTools/" | |
function install_xcode_cli() { | |
echo "Checking for xcode cli tools..." | |
if [[ ! -d "$XCODE_CLI_DIR" ]] | |
then | |
if ! xcode-select --install | |
then | |
return 1 | |
fi | |
else | |
echo "XCode CLI already installed, continuing." | |
fi | |
return 0 | |
} | |
function install_deps() { | |
echo "Checking for install dependencies..." | |
if [[ ! -d "$BOOTSTRAP_DIR" ]] | |
then | |
mkdir "$BOOTSTRAP_DIR" | |
fi | |
if [[ -z "$PIP" ]] | |
then | |
if [[ ! -f "$GET_PIP" ]] | |
then | |
if ! $CURL GET_PIP_URL -o $GET_PIP | |
then | |
return 1 | |
fi | |
fi | |
if ! python $GET_PIP --user | |
then | |
return 1 | |
fi | |
else | |
echo "Found pip already installed, continuing: $PIP" | |
fi | |
echo "Dependency check complete..." | |
return 0 | |
} | |
function install_ansible() { | |
echo "Installing ansible..." | |
if [[ -z "$ANSIBLE" ]] | |
then | |
# See the following for CFLAGS/CPPFLAGS settings: https://bit.ly/2yXV4Ul | |
CFLAGS=-Qunused-arguments CPPFLAGS=-Qunused-arguments $PIP install --user ansible | |
else | |
echo "Found ansible already installed, continuing: $ANSIBLE" | |
fi | |
echo "Ansible installed!" | |
return 0 | |
} | |
function cleanup() { | |
if [[ -d "$BOOTSTRAP_DIR" ]] | |
then | |
rm -r "$BOOTSTRAP_DIR" | |
fi | |
} | |
############################# | |
#### MAIN BODY OF SCRIPT #### | |
# XCode requirements | |
if ! install_xcode_cli | |
then | |
echo "Failed to install xcode cli, exiting!" | |
exit 1 | |
fi | |
# PIP/python requirements | |
if ! install_deps | |
then | |
echo "Failed to install dependencies, exiting!" | |
exit 1 | |
fi | |
# Refresh location of pip | |
PIP=$(command -v pip) | |
# Ansible requirements | |
if ! install_ansible | |
then | |
echo "Failed to install ansible, exiting!" | |
exit 1 | |
fi | |
# Refresh location of ansible | |
ANSIBLE=$(command -v ansible) | |
# Clean up our mess | |
if ! cleanup | |
then | |
echo "Failed to cleanup but otherwise successful, exiting with success" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment