-
Notifications
You must be signed in to change notification settings - Fork 4
/
setup.sh
executable file
·196 lines (175 loc) · 6.16 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
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
#!/bin/bash
brewCasks="1password iterm2 slack brave-browser
visual-studio-code steam vlc qbittorrent zoom
docker dbeaver-community surfshark"
brews="go git bat zsh z vim wget curl htop pipenv gcc tree
jq postgresql@14 coreutils r rsync tmux watch
gdrive goreleaser rename hub sqlite
mysql-client fswatch"
npmGlobals="vercel http-server npm-check-updates pnpm"
# don't check home brew for updates
HOMEBREW_NO_AUTO_UPDATE=1
# ask for sudo up front so we don't need to ask for passwords later
sudo -v
main() {
setupMacosDefaults
setupBrew
setupBrewCasks $brewCasks
setupBrews $brews
setupGit
setupNvm
setupNpmGlobals $npmGlobals
setupGo
setupOhMyZsh
echo "complete"
}
# ----------- functions -------------
containsElement() {
local e match="$1"
shift
for e; do [[ "$e" == "$match" ]] && return 0; done
return 1
}
setupOhMyZsh() {
# # Oh My Zsh
echo -n "installing oh my zsh... "
if [ ! -d "/Users/will/.oh-my-zsh" ]; then
echo -n " downloading... "
output=$(sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended 2>&1)
failed=$?
if [ ! $failed ]; then
echo failed
echo $failed
echo $output
exit 1
fi
echo "source ~/.zshrc-ext" >>~/.zshrc
chsh -s /usr/local/bin/zsh
echo "plugins=(git colored-man colorize pip python brew osx zsh-syntax-highlighting)" >~/.zshrc-ext
echo ". $(brew --prefix)/etc/profile.d/z.sh" >>~/.zshrc-ext
echo "disable r functions" >>~/.zshrc-ext
fi
echo "done"
}
setupNvm() {
echo -n "installing nvm... "
if [ ! -d "$HOME/.nvm" ]; then
NVM_DIR=""
nvmLatest=$(curl -sL https://github.com/nvm-sh/nvm/releases/latest | egrep -so "[0-9]*\.[0-9]*\.[0-9]*" | head -n 1 | tr -s " ")
nodeLatest=$(curl -sL https://github.com/nodejs/node/releases/latest | egrep -so "[0-9]*\.[0-9]*\.[0-9]*" | head -n 1 | tr -s " ")
echo -n " nvm: $nvmLatest node: $nodeLatest "
curl -s -o- "https://raw.githubusercontent.com/nvm-sh/nvm/v${nvmLatest}/install.sh" | bash >/dev/null 2>&1
NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install --no-progress $nodeLatest >/dev/null 2>&1
fi
echo "done"
}
setupNpmGlobals() {
npmGlobals=("$@")
for i in ${npmGlobals[@]}; do
echo -n "installing $i... "
npm list -g $i >/dev/null 2>&1
contains=$?
if [ $contains -ne 0 ]; then
echo -n "downloading... "
output=$(npm install -g $i 2>&1)
failed=$?
if [ $failed -ne 0 ]; then
echo -n "$output"
exit 1
fi
fi
echo "done"
done
}
setupGo() {
# Go paths
echo 'export GOPATH="${HOME}/.go"' >>~/.zshrc-ext
echo 'export GOROOT="$(brew --prefix golang)/libexec"' >>~/.zshrc-ext
echo 'export PATH="$PATH:${GOPATH}/bin:${GOROOT}/bin"' >>~/.zshrc-ext
}
setupGit() {
email=$(git config --global user.email)
username=$(git config --global user.name)
echo -n "setting up git... "
if [ "$username" == "" ]; then
echo ""
echo "enter username:"
read gitUsername
git config --global user.name "$gitUsername"
fi
if [ "$email" == "" ]; then
echo ""
echo "enter email:"
read email
git config --global user.email "$email"
fi
git config --global pager.branch false
if [ ! -f ~/.ssh/id_rsa ]; then
echo ""
echo "generating public private key pair with email $email"
ssh-keygen -t rsa -b 4096 -C "$email" -q -N "" -f ~/.ssh/id_rsa
fi
echo "done"
}
setupBrews() {
brews=("$@")
echo "--- brew brews ---"
installedBrews=$(brew list)
for i in ${brews[@]}; do
echo -n "installing $i... "
containsElement $i ${installedBrews[@]}
contains=$?
if [ $contains -ne 0 ]; then
echo -n " downloading... "
output=$(brew install $i >/dev/null)
failed=$?
if [ $failed -ne 0 ]; then
echo -n "$output"
exit 1
fi
fi
echo "done"
done
}
setupBrew() {
# Install Brew
echo -n "installing brew... "
command -v brew >/dev/null 2>&1 || {
echo >&2 "Installing Homebrew Now"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
}
echo "done"
}
setupMacosDefaults() {
# Annoying macos stuff
echo -n "setting key repeat... "
defaults write -g InitialKeyRepeat -int 13 # normal minimum is 15 (225 ms)
defaults write -g KeyRepeat -int 2 # normal minimum is 2 (30 ms)
echo "done"
echo -n "cleaning toolbar... "
defaults write com.apple.dock persistent-apps -array
echo "done"
}
setupBrewCasks() {
brewCasks=("$@")
echo "--- brew casks ---"
installedBrews=$(brew list)
for i in ${brewCasks[@]}; do
echo -n "installing $i... "
containsElement $i ${installedBrews[@]}
contains=$?
if [ $contains -ne 0 ]; then
echo -n "downloading... "
output=$(brew install --cask $i >/dev/null)
failed=$?
if [ $failed -ne 0 ]; then
echo -n "$output"
exit 1
fi
fi
echo "done"
done
}
main