forked from geerlingguy/mac-dev-playbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.sh
executable file
·75 lines (60 loc) · 1.92 KB
/
bootstrap.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/bin/sh
# Inspired by:
# https://raw.githubusercontent.com/siyelo/laptop/master/install.sh
# This script bootstraps our OSX laptop to a point where we can run
# Ansible on localhost.
# 1. Installs
# - xcode
# - homebrew
# - ansible (via brew)
# - a few ansible galaxy playbooks (cask etc)
# 2. Kicks off the ansible playbook
# - main.yml
#
# It will ask you for your sudo password
fancy_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\n$fmt\n" "$@"
}
fancy_echo "Bootstrapping..."
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT
set -e
# Here we go.. ask for the administrator password upfront and run a
# keep-alive to update existing `sudo` time stamp until script has finished
sudo -v
while true; do sudo -n true; sleep 60; kill -0 "$$" || exit; done 2>/dev/null &
# Ensure Apple's command line tools are installed
if ! command -v cc >/dev/null; then
fancy_echo "Installing xcode ..."
xcode-select --install
else
fancy_echo "Xcode already installed. Skipping."
fi
if ! command -v brew >/dev/null; then
fancy_echo "Installing Homebrew..."
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" </dev/null
else
fancy_echo "Homebrew already installed. Skipping."
fi
# [Install Ansible](http://docs.ansible.com/intro_installation.html).
if ! command -v ansible >/dev/null; then
fancy_echo "Installing Ansible..."
brew install ansible
else
fancy_echo "Ansible already installed. Skipping."
fi
if ! command -v git >/dev/null; then
fancy_echo "Installing Git..."
brew install git
else
fancy_echo "Git already installed. Skipping."
fi
if [ -d ./roles ]; then
fancy_echo "Get fresh roles ..."
rm -rf ./roles
fi
# fancy_echo "Installing ansible requirements for this playbook..."
ansible-galaxy install -r requirements.yml
# fancy_echo "Running ansible playbook..."
ansible-playbook main.yml -i hosts --ask-sudo-pass -vvvv