forked from geerlingguy/mac-dev-playbook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap_remote.sh
executable file
·99 lines (76 loc) · 2.73 KB
/
bootstrap_remote.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/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
# Clone the repository to your local drive.
if [ -d ~/tmp_laptop ]; then
fancy_echo "tmp_laptop repo dir exists. Removing ..."
rm -rf ~/tmp_laptop
fi
mkdir ~/tmp_laptop
cd ~/tmp_laptop
fancy_echo "Cloning mac-dev-playbook repo ..."
git clone https://github.com/Anima-t3d/mac-dev-playbook.git
fancy_echo "Changing to mac-dev-playbook repo dir ..."
cd ~/tmp_laptop/mac-dev-playbook
mkdir ~/tmp_laptop/mac-dev-playbook/roles
cd ~/tmp_laptop/mac-dev-playbook/roles
fancy_echo "Cloning ansible-role-visual-studio-code-extensions repo ..."
git clone https://github.com/donaldaverill/ansible-role-visual-studio-code-extensions.git
mv ~/tmp_laptop/mac-dev-playbook/roles/ansible-role-visual-studio-code-extensions ~/tmp_laptop/mac-dev-playbook/roles/visual-studio-code-extensions
cd ~/tmp_laptop/mac-dev-playbook
cp config_template.yml config.yml
# 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
fancy_echo "Removing ~/tmp_laptop ..."
rm -rf ~/tmp_laptop