-
Notifications
You must be signed in to change notification settings - Fork 4
/
provision
executable file
·163 lines (134 loc) · 4.69 KB
/
provision
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/env bash
set -eu
set -o pipefail
: "${DOTFILES_PATH:="$HOME/dotfiles"}"
: "${DOTFILES_BRANCH:=master}"
: "${DOTFILES_NOEDIT_SECRETS:=0}"
#=== Steps
#==============================================================================================
print_header() {
printf "\e[34m"
echo '--------------------------------------------------------------------------------'
echo ' '
echo ' 888 888 .d888 d8b 888 '
echo ' 888 888 d88P" Y8P 888 '
echo ' 888 888 888 888 '
echo ' .d88888 .d88b. 888888 888888 888 888 .d88b. .d8888b '
echo ' d88" 888 d88""88b 888 888 888 888 d8P Y8b 88K '
echo ' 888 888 888 888 888 888 888 888 88888888 "Y8888b. '
echo ' Y88b 888 Y88..88P Y88b. 888 888 888 Y8b. X88 '
echo ' "Y88888 "Y88P" "Y888 888 888 888 "Y8888 88888P" '
echo ' '
echo ' Harder, Better, Faster, Stronger '
echo ' '
echo ' github.com/creasty/dotfiles '
echo ' '
echo '--------------------------------------------------------------------------------'
printf "\e[0m\n"
}
check_os() {
if [ "$(uname -s)" != "Darwin" ]; then
echo "Sorry, this script is intended only for OS X"
exit 1
fi
}
clone_or_update_repo() {
local git_dir="$DOTFILES_PATH/.git"
if [ -d "$git_dir" ]; then
echo 'Updating repo...'
if [ "$(git --git-dir="$git_dir" symbolic-ref --short HEAD 2> /dev/null)" != "master" ]; then
echo 'skip (working on a non-master branch)'
return
fi
if ! git --git-dir="$git_dir" diff --no-ext-diff --quiet --exit-code > /dev/null 2>&1; then
echo 'skip (unstaged changes present)'
return
fi
if ! git --git-dir="$git_dir" diff-index --cached --quiet HEAD -- > /dev/null 2>&1; then
echo 'skip (uncommitted changes present)'
return
fi
git --git-dir="$git_dir" pull origin master
git --git-dir="$git_dir" submodule sync
echo 'done'
elif ! [ -d "$DOTFILES_PATH" ]; then
echo 'Cloning repo...'
git clone --recursive https://github.com/creasty/dotfiles.git --branch "$DOTFILES_BRANCH" "$DOTFILES_PATH"
echo 'done'
fi
}
accept_xcode_license() {
echo 'Agreeing to Xcode license...'
if ! [[ "$(/usr/bin/xcrun clang 2>&1 || true)" =~ 'license' ]]; then
echo 'skip (already approved)'
return
fi
sudo xcodebuild -license accept
echo 'done'
}
install_rosetta2() {
echo 'Installing Rosetta 2...'
if [ -d /usr/libexec/rosetta ]; then
echo 'skip (already installed)'
return
fi
sudo softwareupdate --install-rosetta --agree-to-license
echo 'done'
}
load_envs() {
export ANYENV_INIT_CACHE_DISABLED=1
# shellcheck source=/dev/null
. "$DOTFILES_PATH/shell/profile"
}
install_homebrew() {
command -v 'brew' > /dev/null 2>&1 && return
echo 'Installing homebrew...'
NONINTERACTIVE=1 HAVE_SUDO_ACCESS=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo 'done'
}
install_python3() {
command -v 'python3' > /dev/null 2>&1 && return
python3 --version > /dev/null 2>&1 && return
echo 'Installing python3...'
brew install [email protected]
echo 'done'
}
install_ansible() {
command -v 'ansible' > /dev/null 2>&1 && return
echo 'Installing ansible...'
brew install ansible
echo 'done'
}
run_provisioning() {
echo 'Provisioning...'
cd "$DOTFILES_PATH/provisioning"
if ! [ -f ./secrets.yml ]; then
cp ./secrets{.sample,}.yml
[ "$DOTFILES_NOEDIT_SECRETS" -eq 0 ] && vim ./secrets.yml
fi
ansible-playbook \
-i 'localhost,' \
--extra-vars "home_path=$HOME" \
--extra-vars "dotfiles_path=$DOTFILES_PATH" \
--extra-vars "homebrew_prefix=$HOMEBREW_PREFIX" \
--extra-vars '@config.yml' \
--extra-vars '@secrets.yml' \
"$@" \
playbook.yml
echo 'done'
}
#=== Entrypoint
#==============================================================================================
main() {
print_header
check_os
clone_or_update_repo
accept_xcode_license
install_rosetta2
load_envs
install_homebrew
install_python3
install_ansible
run_provisioning "$@"
}
main "$@"