Last active
January 14, 2019 18:34
-
-
Save dieterdemeyer/09e7666079cf579bbcd8 to your computer and use it in GitHub Desktop.
Wrapper around ansible osx provisioning
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 | |
BGreen='\e[1;32m' # Green | |
BRed='\e[1;31m' # Red | |
Color_Off='\e[0m' # Text Reset | |
function setStatusMessage { | |
printf "${IRed} --> ${BGreen}$1${Color_Off}\n" 1>&2 | |
} | |
function triggerError { | |
printf "${BRed} --> $1 ${Color_Off}\n" 1>&2 | |
exit 1 | |
} | |
printf "${BGreen} _ _ _ _ ${Color_Off}\n" | |
printf "${BGreen} __ _ _ __ ___(_) |__ ___ ___ | |_ ___| |_ _ __ __ _ _ __ ${Color_Off}\n" | |
printf "${BGreen} / _ | '_ \/ __| | '_ \ / _ \ / _ \| __/ __| __| '__/ _ | '_ \ ${Color_Off}\n" | |
printf "${BGreen}| (_| | | | \__ \ | |_) | (_) | (_) | |_\__ \ |_| | | (_| | |_) |${Color_Off}\n" | |
printf "${BGreen} \__,_|_| |_|___/_|_.__/ \___/ \___/ \__|___/\__|_| \__,_| .__/ ${Color_Off}\n" | |
printf "${BGreen} |_| ${Color_Off}\n" | |
setStatusMessage "Checking if we need to ask for a sudo password" | |
if sudo -n true; then | |
export ANSIBLE_ASK_SUDO_PASS=False | |
else | |
sudo -v | |
export ANSIBLE_ASK_SUDO_PASS=True | |
fi | |
repo=$1 | |
# Check whether a command exists - returns 0 if it does, 1 if it does not | |
function exists { | |
if command -v $1 >/dev/null 2>&1 | |
then | |
return 0 | |
else | |
return 1 | |
fi | |
} | |
# credits https://github.com/boxcutter/osx/blob/master/script/xcode-cli-tools.sh | |
function install_clt { | |
# Get and install Xcode CLI tools | |
OSX_VERS=$(sw_vers -productVersion | awk -F "." '{print $2}') | |
# on 10.9+, we can leverage SUS to get the latest CLI tools | |
if [ "$OSX_VERS" -ge 9 ]; then | |
# create the placeholder file that's checked by CLI updates' .dist code | |
# in Apple's SUS catalog | |
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress | |
# find the CLI Tools update | |
PROD=$(softwareupdate -l | grep "\*.*Command Line" | head -n 1 | awk -F"*" '{print $2}' | sed -e 's/^ *//' | tr -d '\n') | |
# install it | |
softwareupdate -i "$PROD" -v | |
rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress | |
# on 10.7/10.8, we instead download from public download URLs, which can be found in | |
# the dvtdownloadableindex: | |
# https://devimages.apple.com.edgekey.net/downloads/xcode/simulators/index-3905972D-B609-49CE-8D06-51ADC78E07BC.dvtdownloadableindex | |
else | |
[ "$OSX_VERS" -eq 7 ] && DMGURL=http://devimages.apple.com.edgekey.net/downloads/xcode/command_line_tools_for_xcode_os_x_lion_april_2013.dmg | |
[ "$OSX_VERS" -eq 7 ] && ALLOW_UNTRUSTED=-allowUntrusted | |
[ "$OSX_VERS" -eq 8 ] && DMGURL=http://devimages.apple.com.edgekey.net/downloads/xcode/command_line_tools_for_osx_mountain_lion_april_2014.dmg | |
TOOLS=clitools.dmg | |
curl "$DMGURL" -o "$TOOLS" | |
TMPMOUNT=`/usr/bin/mktemp -d /tmp/clitools.XXXX` | |
hdiutil attach "$TOOLS" -mountpoint "$TMPMOUNT" | |
installer $ALLOW_UNTRUSTED -pkg "$(find $TMPMOUNT -name '*.mpkg')" -target / | |
hdiutil detach "$TMPMOUNT" | |
rm -rf "$TMPMOUNT" | |
rm "$TOOLS" | |
exit | |
fi | |
} | |
setStatusMessage "Keep-alive: update existing sudo time stamp until we are finished" | |
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null & | |
# NOT WORKING ON MACOS HIGH SIERRA -> INSTALL MANUALLY: xcode-select --install | |
#if [[ ! -f "/Library/Developer/CommandLineTools/usr/bin/clang" ]]; then | |
# setStatusMessage "Install the CLT" | |
# install_clt | |
#fi | |
# Install Ansible | |
if ! exists pip; then | |
setStatusMessage "Install PIP" | |
sudo easy_install --quiet pip | |
else | |
setStatusMessage "Updating PIP" | |
sudo pip install --upgrade pip | |
fi | |
# TODO: change this to use virtualenv ? | |
if ! exists ansible; then | |
setStatusMessage "Install Ansible" | |
sudo pip install -q ansible | |
fi | |
setStatusMessage "Create necessary folders" | |
sudo mkdir -p /opt/ansible-osx-provisioning | |
sudo chmod -R g+rwx /opt/ansible-osx-provisioning | |
sudo chgrp -R admin /opt/ansible-osx-provisioning | |
if [ -d "/opt/ansible-osx-provisioning/inventory" ]; then | |
setStatusMessage "Update from git" | |
cd /opt/ansible-osx-provisioning | |
git pull -q origin master | |
else | |
if [ ! -z "$repo" ]; then | |
setStatusMessage "Getting your config from your fork" | |
git clone -q $1 /opt/ansible-osx-provisioning | |
else | |
triggerError "No repo found..." | |
fi | |
fi | |
cd /opt/ansible-osx-provisioning | |
#setStatusMessage "Create ansible.cfg" | |
##{ echo '[defaults]'; echo 'roles_path=/opt/ansible-osx-provisioning/roles:/opt/ansible-osx-provisioning/config/roles'; } > ansible.cfg | |
#setStatusMessage "Get all the required roles" | |
#ansible-galaxy install -f -r config/requirements.yml -p roles | |
#setStatusMessage "Provisioning in progress..." | |
#ansible-playbook macbook-work.yml --tags homebrew --ask-become-pass | |
#ansible-playbook macbook-work.yml --tags base --ask-become-pass | |
#ansible-playbook macbook-work.yml --tags sudoers --ask-become-pass | |
#ansible-playbook macbook-work.yml --tags git --ask-become-pass | |
#ansible-playbook macbook-work.yml --tags dotfiles --ask-become-pass | |
#ansible-playbook macbook-work.yml --tags vim --ask-become-pass | |
#ansible-playbook macbook-work.yml --tags rbenv --ask-become-pass | |
#ansible-playbook macbook-work.yml --tags iterm2 --ask-become-pass | |
#ansible-playbook macbook-work.yml --tags osx --ask-become-pass | |
#ansible-playbook macbook-work.yml --tags personal --ask-become-pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment