#!/bin/zsh 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 } printf "${BGreen} _________ .__ .__ ${Color_Off}\n" printf "${BGreen} / _____/__ ________ ___________| | __ __ _____ |__| ____ ${Color_Off}\n" printf "${BGreen} \_____ \| | \____ \_/ __ \_ __ \ | | | \/ \| |/ ___\ ${Color_Off}\n" printf "${BGreen} / \ | / |_> > ___/| | \/ |_| | / Y Y \ \ \___ ${Color_Off}\n" printf "${BGreen} /_______ /____/| __/ \___ >__| |____/____/|__|_| /__|\___ >${Color_Off}\n" printf "${BGreen} \/ |__| \/ http://superlumic.com \/ \/ ${Color_Off}\n\n" setStatusMessage "Checking if we need to ask for a sudo password" sudo -v export ANSIBLE_ASK_SUDO_PASS=True repo=$1 username=$USER if [ ! -z "$2" ]; then username=$2 fi function triggerError { printf "${BRed} --> $1 ${Color_Off}\n" 1>&2 exit 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 { # 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" --verbose rm /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress } setStatusMessage "Install the CLT" install_clt 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 & export HOMEBREW_CASK_OPTS="--appdir=/Applications" if [[ ! -f "/Library/Developer/CommandLineTools/usr/bin/clang" ]]; then setStatusMessage "Make sure Xcode or the CommandLineTools are installed!" fi /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)" brew install ansible setStatusMessage "Create necessary folders" sudo mkdir -p /usr/local/superlumic sudo mkdir -p /usr/local/superlumic/roles sudo mkdir -p /usr/local/superlumic/collections sudo chmod -R g+rwx /usr/local/superlumic sudo chgrp -R admin /usr/local/superlumic if [ -d "/usr/local/superlumic/config" ]; then setStatusMessage "Update your config from git" cd /usr/local/superlumic/config git pull -q else if [ ! -z "$repo" ]; then setStatusMessage "Getting your config from your fork" git clone -q $1 /usr/local/superlumic/config else setStatusMessage "Getting the default config" git clone -q https://github.com/superlumic/superlumic-config.git /usr/local/superlumic/config fi fi cd /usr/local/superlumic setStatusMessage "Create ansible.cfg" { echo '[defaults]'; echo 'roles_path=/usr/local/superlumic/roles:/usr/local/superlumic/config/roles'; echo 'deprecation_warnings=False'; echo 'nocows = True'; echo 'collections_paths = /usr/local/superlumic/collections';} > ansible.cfg setStatusMessage "Checking for encrypted vault files" if grep --silent -R "$ANSIBLE_VAULT;.*;AES256" /usr/local/superlumic/config/ ; then echo 'ask_vault_pass=yes' >> ansible.cfg setStatusMessage "Set Ansible to ask for the Vault Password" fi setStatusMessage "Get all the required roles" ansible-galaxy install -f -r config/requirements.yml if [ -f "config/$username.yml" ]; then setStatusMessage "Running the ansible playbook for $username" ansible-playbook -i "localhost," config/$username.yml $ANSIBLE_EXTRA_OPTS else if [ "travis" = "$username" ]; then setStatusMessage "Running the ansible playbook for $username but use roderik.yml as fallback" ansible-playbook -i "localhost," config/roderik.yml $ANSIBLE_EXTRA_OPTS else triggerError "No playbook for $username found" fi fi