-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.sh
executable file
·75 lines (63 loc) · 1.96 KB
/
setup.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/bash
set -euo pipefail
# Variables for internal script usage
CURRENT_DIR=$(pwd)
DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
HOMEBREW_DOWNLOAD_URL=https://raw.githubusercontent.com/Homebrew/install/master/install
cleanup() {
cd "$CURRENT_DIR" &>/dev/null
}
source_bash_utils() {
# shellcheck disable=SC1090
# shellcheck disable=SC1091
source "$DIRECTORY/bash_utils.sh"
}
install_ansible_dependencies() {
info "Installing Ansible dependencies if necessary..."
local ansible_dependencies=(python ansible jq)
for dependency in ${ansible_dependencies[*]}; do
brew install "$dependency" 2>&1 | tee -a "$LOG_FILE" || brew upgrade "$dependency" 2>&1 | tee -a "$LOG_FILE"
done
}
install_homebrew() {
info "Checking for Homebrew, and installing if necessary"
if test ! "$(command -v brew &>/dev/null)"; then
info 'Installing homebrew...'
ruby -e "$(curl -fsSL $HOMEBREW_DOWNLOAD_URL)" 2>&1 | tee -a "$LOG_FILE"
else
info 'Homebrew installed.'
fi
}
install_xcode() {
info "Checking for xcode, and installing if necessary"
if ! [[ -d /Library/Developer/CommandLineTools/Library/ ]]; then
info 'Installing xcode...'
xcode-select --install
while [ ! -d /Library/Developer/CommandLineTools/Library/ ] ;
do
sleep 2
done
else
info 'Xcode already installed.'
fi
}
run_ansible() {
info "Running ansible to continue with local setup..."
pushd "${DIRECTORY}/ansible" &>/dev/null
ANSIBLE_CONFIG=ansible.cfg ANSIBLE_LOG_PATH=$LOG_FILE ansible-playbook playbooks/darwin_bootstrap.yml -v --ask-become-pass
popd
}
trap_signals() {
trap "{ debug 'Running cleanup'; cleanup; }" EXIT
trap "{ debug 'Running cleanup'; cleanup; fatal 'User interrupt detected. Exitting...'; }" SIGINT
trap "{ debug 'Running cleanup'; cleanup; fatal 'There was an error'}" ERR
}
main() {
trap_signals
source_bash_utils
install_xcode
install_homebrew
install_ansible_dependencies
run_ansible
}
main