-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-osx.sh
executable file
·275 lines (216 loc) · 7.48 KB
/
setup-osx.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
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/bin/bash
set -e
# Colorize terminal
red='\e[0;31m'
no_color='\033[0m'
# Console step increment
i=1
# Get project directories
SCRIPT_PATH="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )"
# Default
INSTALL_AI="false"
INSTALL_BASE="false"
INSTALL_DEVOPS="false"
INSTALL_EXTRAS="false"
INSTALL_GO="false"
INSTALL_JS="false"
INSTALL_SECOPS="false"
INSTALL_COMPLETIONS="false"
COPY_DOTFILES="false"
REMOVE_TMP_CONTENT="false"
FULL_MODE_SETUP="true"
# Declare script helper
TEXT_HELPER="\nThis script aims to install a full setup for osx.
Following flags are available:
-c Install cli completions.
-d Copy dotfiles.
-l Run with lite mode, only major tools will be installed.
-p Install additional packages according to the given profile, available profiles are :
-> 'ai'
-> 'base'
-> 'devops'
-> 'extras' (for personnal use)
-> 'go'
-> 'js'
-> 'secops'
Default is no profile, this flag can be used with a CSV list (ex: -p "base,js").
-r Remove all tmp files after installation.
-h Print script help.\n\n"
print_help() {
printf "$TEXT_HELPER"
}
# Parse options
while getopts hcdlp:r flag; do
case "${flag}" in
c)
INSTALL_COMPLETIONS="true";;
d)
COPY_DOTFILES="true";;
l)
FULL_MODE_SETUP="false";;
p)
[[ "$OPTARG" =~ "ai" ]] && INSTALL_AI="true"
[[ "$OPTARG" =~ "base" ]] && INSTALL_BASE="true"
[[ "$OPTARG" =~ "devops" ]] && INSTALL_DEVOPS="true"
[[ "$OPTARG" =~ "extras" ]] && INSTALL_EXTRAS="true"
[[ "$OPTARG" =~ "go" ]] && INSTALL_GO="true"
[[ "$OPTARG" =~ "js" ]] && INSTALL_JS="true"
[[ "$OPTARG" =~ "secops" ]] && INSTALL_SECOPS="true";;
r)
REMOVE_TMP_CONTENT="true";;
h | *)
print_help
exit 0;;
esac
done
# utils
install_clt() {
printf "\n\n${red}Optional.${no_color} Installs Command Line Tools for Xcode from softwareupdate...\n\n"
# This temporary file prompts the 'softwareupdate' utility to list the Command Line Tools
touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress
PROD=$(softwareupdate -l | grep "\*.*Command Line" | tail -n 1 | sed 's/^[^C]* //')
softwareupdate -i "$PROD" --verbose;
printf "\Command Line Tools version installed :\n$PROD\n\n"
}
install_homebrew() {
printf "\n\n${red}Optional.${no_color} Installs homebrew...\n\n"
export NONINTERACTIVE=1
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
printf "\nhomebrew version installed :\n$(homebrew --version)\n\n"
}
if [ -z "$(xcode-select -p)" ]; then
while true; do
read -p "\nYou need Command Line Tools to run this script. Do you wish to install Command Line Tools?\n" yn
case $yn in
[Yy]*)
install_clt;;
[Nn]*)
exit;;
*)
echo "\nPlease answer yes or no.\n";;
esac
done
fi
if [ -z "$(brew --version)" ]; then
while true; do
read -p "You need homebrew to run this script. Do you wish to install homebrew?" yn
case $yn in
[Yy]*)
install_homebrew;;
[Nn]*)
exit;;
*)
printf "\nPlease answer y or n.\n";;
esac
done
fi
# Settings
printf "\nScript settings:
-> install ${red}full setup${no_color}: ${red}$FULL_MODE_SETUP${no_color}
-> install ${red}[ai]${no_color} profile: ${red}$INSTALL_AI${no_color}
-> install ${red}[base]${no_color} profile: ${red}$INSTALL_BASE${no_color}
-> install ${red}[devops]${no_color} profile: ${red}$INSTALL_DEVOPS${no_color}
-> install ${red}[extras]${no_color} profile: ${red}$INSTALL_EXTRAS${no_color}
-> install ${red}[go]${no_color} profile: ${red}$INSTALL_GO${no_color}
-> install ${red}[js]${no_color} profile: ${red}$INSTALL_JS${no_color}
-> install ${red}[secops]${no_color} profile: ${red}$INSTALL_SECOPS${no_color}\n"
export FULL_MODE_SETUP=$FULL_MODE_SETUP
# Install common
printf "\n${red}${i}.${no_color} Install commons\n\n"
brew update && brew install --formula \
ca-certificates \
curl \
gnupg \
gsed \
gzip \
jq \
unzip \
wget \
xz
# Install oh-my-zsh
if [ ! -d "$HOME/.oh-my-zsh" ]; then
printf "\n${red}${i}.${no_color} Install oh-my-zsh\n\n"
i=$(($i + 1))
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
fi
# Install base profile
if [[ "$INSTALL_BASE" = "true" ]]; then
printf "\n${red}${i}.${no_color} Install base profile\n\n"
i=$(($i + 1))
$SCRIPT_PATH/profiles/osx/setup-base.sh
fi
# Install extras profile
if [[ "$INSTALL_EXTRAS" = "true" ]]; then
printf "\n${red}${i}.${no_color} Install extras profile\n\n"
i=$(($i + 1))
$SCRIPT_PATH/profiles/osx/setup-extras.sh
fi
# Install devops profile
if [[ "$INSTALL_DEVOPS" = "true" ]]; then
printf "\n${red}${i}.${no_color} Install devops profile\n\n"
i=$(($i + 1))
$SCRIPT_PATH/profiles/osx/setup-devops.sh
fi
# Install secops profile
if [[ "$INSTALL_SECOPS" = "true" ]]; then
printf "\n${red}${i}.${no_color} Install secops profile\n\n"
i=$(($i + 1))
$SCRIPT_PATH/profiles/osx/setup-secops.sh
fi
# Install go profile
if [[ "$INSTALL_GO" = "true" ]]; then
printf "\n${red}${i}.${no_color} Install go profile\n\n"
i=$(($i + 1))
$SCRIPT_PATH/profiles/osx/setup-go.sh
fi
# Install js profile
if [[ "$INSTALL_JS" = "true" ]]; then
printf "\n${red}${i}.${no_color} Install javascript profile\n\n"
i=$(($i + 1))
$SCRIPT_PATH/profiles/osx/setup-js.sh
fi
# Install ai profile
if [[ "$INSTALL_AI" = "true" ]]; then
printf "\n${red}${i}.${no_color} Install ai profile\n\n"
i=$(($i + 1))
$SCRIPT_PATH/profiles/osx/setup-ai.sh
fi
# Copy dotfiles
if [[ "$COPY_DOTFILES" = "true" ]]; then
printf "\n${red}${i}.${no_color} Copy dotfiles\n\n"
i=$(($i + 1))
mkdir -p "$HOME/.config"
cp "$SCRIPT_PATH/../dotfiles/.zshrc" "$HOME/.zshrc" && gsed -i 's/^# alias sed=.*/alias sed="gsed"/g' "$HOME/.zshrc"
cp "$SCRIPT_PATH/../dotfiles/.oh-my-zsh/this-is-tobi.zsh-theme" "$HOME/.oh-my-zsh/custom/themes/this-is-tobi.zsh-theme"
cp "$SCRIPT_PATH/../dotfiles/.prototools" "$HOME/.proto/.prototools"
cp "$SCRIPT_PATH/../dotfiles/.gitconfig" "$HOME/.gitconfig"
cp -R $SCRIPT_PATH/../dotfiles/.continue/* "$HOME/.continue"
cp -R $SCRIPT_PATH/../dotfiles/.config/* "$HOME/.config"
# Install .vscode extensions
if [ -x "$(command -v code)" ]; then
cp "$SCRIPT_PATH/../dotfiles/.vscode/settings.json" "$HOME/Library/Application Support/Code/User/settings.json"
VSCODE_EXTENSIONS=($(cat "$SCRIPT_PATH/../dotfiles/.vscode/extensions.json" \
| grep -v '//' \
| grep -E '\S' \
| jq -r '.recommendations[]'))
for extension in ${VSCODE_EXTENSIONS[@]}; do
echo "$extension" | xargs -L 1 code --install-extension
done
fi
# Update brew links if architecture is arm64
if [ "$(uname -m)" = "arm64" ] || [ "$(uname -m)" = "aarch64" ]; then
gsed -i 's/\/usr\/local/\/opt\/homebrew/g' "$HOME/.zshrc"
fi
fi
# Install cli completions
if [[ "$INSTALL_COMPLETIONS" = "true" ]]; then
printf "\n${red}${i}.${no_color} Install cli completions\n\n"
i=$(($i + 1))
$SCRIPT_PATH/completions.sh
git clone https://github.com/zsh-users/zsh-completions ${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions && gsed -i 's|^# fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions/src|fpath+=${ZSH_CUSTOM:-${ZSH:-~/.oh-my-zsh}/custom}/plugins/zsh-completions/src|g' "$HOME/.zshrc"
fi
if [[ "$REMOVE_TMP_CONTENT" = "true" ]]; then
printf "\n${red}${i}.${no_color} Remove tmp files\n\n"
i=$(($i + 1))
rm -rf /tmp/*
fi