forked from islco/laptop
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmac
executable file
·230 lines (175 loc) · 4.53 KB
/
mac
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
#!/bin/sh
# Welcome to the Mariana Tek laptop script!
# Be prepared to turn your laptop (or desktop)
# into a fairly decent development machine.
#
# Utilities
#
append_to_file() {
local file="$1"
local text="$2"
if ! grep -qs "^$text$" "$file"; then
printf "\n%s\n" "$text" >> "$file"
fi
}
brew_install_or_upgrade() {
if brew list --formula | grep "^$1"; then
if brew outdated | grep "^$1 ("; then
fancy_echo "Upgrade $1 ..."
brew upgrade "$@"
else
fancy_echo "Already installed $1 ..."
fi
else
fancy_echo "Installing $1 ..."
brew install "$@"
fi
}
cask_install_or_skip() {
local app_name="$1"
local cask_name="$2"
if open -Ra "$app_name"; then
fancy_echo "$app_name is already installed - skipping"
else
brew install --cask $cask_name
fi
}
create_file() {
local file="$1"
if [ ! -f "$file" ]; then
touch "$file"
else
rm "$file"; touch "$file"
fi
}
curl_to_file() {
local file="$1"
local url="$2"
if [ ! -f "$file" ]; then
curl "$url" > "$file"
fi
}
exists() {
command -v "$1" >/dev/null 2>&1
}
fancy_echo() {
local fmt="$1"; shift
# shellcheck disable=SC2059
printf "\n$fmt\n" "$@"
}
# ============================================================================
# Begin script...
# ============================================================================
# shellcheck disable=SC2154
trap 'ret=$?; test $ret -ne 0 && printf "failed\n\n" >&2; exit $ret' EXIT
set -e
LAPTOPRC="$HOME/.laptoprc"
ZSHRC="$HOME/.zshrc"
OS_VERSION=${1:-$(sw_vers -productVersion)}
#
# Install MacOS developer tools
#
xcode-select -p > /dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Please install MacOS CommandLineTools..."
exit 1
fi
#
# Cleanup existing + problematic entries (non-brew)
#
# NVM
# https://github.com/nvm-sh/nvm/issues/298
rm -rf "$HOME/.nvm"
#
# Backup existing ZSH settings
#
if [ -f "$ZSHRC" ]; then
cp "$ZSHRC" "$HOME/.zshrc.bak"; create_file "$ZSHRC"
else
create_file "$ZSHRC"
fi
#
# Create laptop config file
#
create_file "$LAPTOPRC"
#
# Install Homebrew + set PATH
#
if ! command -v brew >/dev/null; then
fancy_echo "Please install Homebrew ..."
exit 1
else
fancy_echo "Homebrew already installed. Skipping ..."
fi
# shellcheck disable=SC2016
append_to_file "$LAPTOPRC" 'export PATH="/usr/local/bin:$PATH"'
append_to_file "$LAPTOPRC" 'export PATH="/usr/local/sbin:$PATH"'
#
# Update Homebrew
#
brew update
brew tap 'heroku/brew'
brew tap 'homebrew/cask-fonts'
#
# Install Homebrew formulae
#
## services
brew_install_or_upgrade 'postgresql@11'
append_to_file "$LAPTOPRC" 'export PATH="/usr/local/opt/postgresql@11/bin:$PATH"'
## command line utilities
brew_install_or_upgrade 'git'
brew_install_or_upgrade 'wget'
## zsh prompt
brew_install_or_upgrade 'starship'
append_to_file "$HOME/.zshrc" 'eval "$(starship init zsh)"'
mkdir -p ~/.config && touch ~/.config/starship.toml
#
# Install Homebrew casks
#
## Browsers
cask_install_or_skip 'Google Chrome' 'google-chrome'
## Git
cask_install_or_skip 'Github Desktop' 'github'
## Terminal
cask_install_or_skip 'iTerm' 'iterm2'
## Editors
cask_install_or_skip 'Visual Studio Code' 'visual-studio-code'
### configure VSCode
code --install-extension mikestead.dotenv # DotENV
code --install-extension batisteo.vscode-django # Django
code --install-extension EditorConfig.EditorConfig # EditorConfig
code --install-extension dbaeumer.vscode-eslint # ESlint
code --install-extension esbenp.prettier-vscode # Prettier
code --install-extension ms-python.python # Python
code --install-extension vscode-icons-team.vscode-icons # vscode-icons'
## Communication
cask_install_or_skip 'Slack' 'slack'
## Utilities
cask_install_or_skip 'Docker' 'docker'
brew install 'docker-compose'
## Security
cask_install_or_skip '1Password 7' '1password'
## Font for ZSH
if system_profiler SPFontsDataType | grep -i "Full Name: Meslo LG" > /dev/null 2>&1; then
brew uninstall --cask 'font-meslo-lg-nerd-font'; brew install --cask 'font-meslo-lg-nerd-font'
else
brew install --cask 'font-meslo-lg-nerd-font'
fi
#
# Load Homebrew .laptop.local overrides
#
if [ -f $HOME/.laptop.local ]; then
/bin/bash $HOME/.laptop.local
fi
#
# Copy default configs + postinstall files
#
curl_to_file "$HOME/.editorconfig" \
"https://raw.githubusercontent.com/Mariana-Tek/laptop/master/config/editorconfig"
#
# Load .laptoprc as last entry in ZSHRC
#
append_to_file "$ZSHRC" 'source $HOME/.laptoprc'
fancy_echo "Finished! Your shell will be automatically reloaded."
exec /bin/zsh