-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
install
executable file
·361 lines (299 loc) · 9.94 KB
/
install
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
#!/usr/bin/env bash
# CI handling
CI=${CI:-False}
if [[ -n ${CI} ]]; then
sudo() {
"$@"
}
fi
BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "${BASEDIR}/.installer/utils.sh"
source "${BASEDIR}/.installer/git.sh"
if [[ "$(uname)" == "Darwin" ]]; then
source "${BASEDIR}/.installer/install_mac.sh"
else
source "${BASEDIR}/.installer/install_arch.sh"
fi
install_links() {
local cmd
if command -v dotbot >/dev/null; then
cmd="dotbot"
else
cmd="${BASEDIR}/dotbot/bin/dotbot"
fi
"${cmd}" -q -d "${BASEDIR}" -c "${BASEDIR}/install.conf.yaml"
}
post_install() {
gem install \
sqlint \
neovim \
2>/dev/null 1>/dev/null
gem environment
pipx ensurepath
pipx install \
cfn-lint \
flake8 \
pyinfra \
pywal \
wakatime \
yamllint
pipx install awsume[saml,fuzy]
pipx inject awsume \
awsume-console-plugin
pipx install httpie
pipx inject httpie \
httpie-aws-auth
pipx install ansible --include-deps
pipx inject ansible \
paramiko
pipx inject flake8 \
flake8-bugbear==21.11.29 \
flake8-commas==2.1.0 \
flake8-quotes==3.3.1 \
flake8-print==4.0.0 \
flake8-bandit==2.1.2 \
flake8-comprehensions==3.7.0
wal --theme base16-atelier-dune -n --vte
wal-vtop >/dev/null
}
_env_binary() {
# fetches path to binary of given *env
# nodenv, jenv etc etc etc
local env
env="${1}"
if ! command -v "${env}" >/dev/null 2>&1; then
env_bin="${HOME}/.${env}/bin/${env}"
else
env_bin=$(command -v "${env}")
fi
echo "${env_bin}"
}
configure_envs() {
configure_pyenv
configure_jenv
configure_goenv
configure_nodenv
}
configure_nodenv() {
local nodenv
local nodenv_root
nodenv=$(_env_binary "nodenv")
nodenv_root=$($nodenv root)
if [ ! -f "${nodenv_root}/version" ]; then
echo "Installing latest Node"
$nodenv latest install -s 14
$nodenv global "$($nodenv latest --print-installed)"
"${nodenv_root}/versions/$($nodenv latest --print-installed)/bin/npm" install --global --production "${BASEDIR}/package.json"
else
log_done "Node -> $(cat "${nodenv_root}/version")" "[ ]"
fi
$nodenv rehash
}
configure_goenv() {
local goenv
local goenv_root
goenv=$(_env_binary "goenv")
goenv_root=$($goenv root)
if [ ! -f "${goenv_root}/version" ]; then
echo "Installing latest GO"
$goenv latest install -s 1 &&
$goenv global "$($goenv latest --print-installed)"
go="${goenv_root}/versions/$($goenv latest --print-installed)/bin/go"
$go get -u \
golang.org/x/lint/golint \
golang.org/x/tools/gopls \
github.com/golangci/golangci-lint/cmd/golangci-lint \
github.com/stamblerre/gocode \
github.com/cpuguy83/go-md2man
command -v shfmt >/dev/null || GO111MODULE=on $go get mvdan.cc/sh/v3/cmd/shfmt
else
log_done "Go -> $(cat "${goenv_root}/version")" "[ ]"
fi
$goenv rehash
}
configure_pyenv() {
local pyenv
local pyenv_root
local python_icon="[ ]"
local neovim_icon="[ ]${python_icon}"
pyenv=$(_env_binary "pyenv")
pyenv_root=$($pyenv root)
if [ ! -f "${pyenv_root}/version" ]; then
log_notice "Installing latest Python" "${python_icon}"
for py_major in {2,3}; do
$pyenv latest install -s "${py_major}"
"${pyenv_root}/versions/$($pyenv latest --print-installed "${py_major}")/bin/pip" install --upgrade pip
"${pyenv_root}/versions/$($pyenv latest --print-installed "${py_major}")/bin/pip" install \
-r "${BASEDIR}/requirements/system.txt" \
-r "${BASEDIR}/requirements/utils.txt"
log_done "Installed Python ${py_major}" "${python_icon}"
done
$pyenv global "$($pyenv latest --print-installed)"
else
log_done "Python -> $(cat "${pyenv_root}/version")"
fi
for py_major in {2,3}; do
if [ ! -d "${pyenv_root}/versions/neovim${py_major}" ]; then
log_notice "Initializing neovim setup for Python ${py_major}" "${neovim_icon}"
$pyenv virtualenv "$($pyenv latest --print "${py_major}")" "neovim${py_major}"
"${pyenv_root}/versions/neovim${py_major}/bin/pip" install --upgrade pip
"${pyenv_root}/versions/neovim${py_major}/bin/pip" install -r "${BASEDIR}/requirements/neovim.txt"
else
local neovim_py_version
neovim_py_version="$(
"${pyenv_root}/versions/neovim${py_major}/bin/python" \
--version \
2>&1 |
awk '{print $2}'
)"
log_done "neovim${py_major} -> ${neovim_py_version}" "${neovim_icon}"
fi
done
$pyenv rehash
}
configure_jenv() {
local jenv
local jenv_root
jenv=$(_env_binary "jenv")
jenv_root=$($jenv root)
if [ ! -d "${jenv_root}/_versions/" ]; then
mkdir "${jenv_root}/_versions/"
fi
if [ ! -f "${jenv_root}/version" ]; then
echo "Installing latest Java"
local javaVersion
local downloadUrl
local archiveName
local jdkVersion
local releaseType
if [[ "$(uname)" == "Darwin" ]]; then
# if latest is the one as from brew, do not download
# but use brew provided
if command -v java >/dev/null 2>&1; then
if test -h /usr/libexec/java_home; then
log_info "Using brew provided java"
"${jenv}" add $(/usr/libexec/java_home)
fi
fi
else
javaVersion="$(http https://api.adoptopenjdk.net/v3/info/available_releases | jq -r '.most_recent_feature_release')"
releaseType="ga"
downloadUrl=$(
http \
"https://api.adoptopenjdk.net/v3/assets/feature_releases/${javaVersion}/${releaseType}" \
architecture==x64 \
sort_method==DATE \
sort_order==DESC \
image_type==jdk \
jvw_impl==hotspot \
os==linux \
project==jdk \
vendor==adoptopenjdk |
jq -r '.[0]["binaries"][0]["package"]["link"]'
)
archiveName=$(echo "${downloadUrl}" | awk -F "/" '{print $NF}')
if [ ! -f "/tmp/${archiveName}" ]; then
aria2c \
-d "/tmp" \
-o "${archiveName}" \
-j 5 \
"${downloadUrl}"
fi
jdkVersion=$(tar -tf "/tmp/${archiveName}" | head -n 1 | sed -e 's|/||g')
tar -xzf "/tmp/${archiveName}" -C "${jenv_root}/_versions/" && {
$jenv add "${jenv_root}/_versions/${jdkVersion}"
$jenv global "$($jenv versions | grep "${javaVersion}" | head -n 1 | awk -F' ' '{print $1}')"
}
if command -v java >/dev/null 2>&1; then
if command -v update-alternatives >/dev/null 2>&1; then
echo "Enabling default java"
local default_java_home
default_java_home=$(update-alternatives --query java | grep Best | awk '{print $2}' | sed -e 's|bin/java||g')
if [ -d "${default_java_home}" ]; then
$jenv add "${default_java_home}"
fi
fi
fi
fi
$jenv enable-plugin export >/dev/null
$jenv enable-plugin maven >/dev/null
else
log_done "Java -> $(cat "${jenv_root}/version")" "[ ]"
fi
$nodenv package-hooks install --all
$jenv rehash
}
configure_nvim() {
local goenv pyenv nodenv jenv new_path old_path
goenv=$(_env_binary "goenv")
pyenv=$(_env_binary "pyenv")
nodenv=$(_env_binary "nodenv")
jenv=$(_env_binary "jenv")
old_path="${PATH}"
new_path="${PATH}:$($goenv root)/shims:$($pyenv root)/shims:$($nodenv root)/shims:$($jenv root)/shims"
export PATH="${new_path}"
nvim --headless +PlugInstall +qall!
nvim --headless +UpdateRemotePlugins +qall!
export PATH="${old_path}"
unset goenv
unset pyenv
unset nodenv
unset jenv
unset new_path
}
configure_wakatime() {
local wakatime_api_key=""
local wakatime_hostname=""
local icon="[ ]"
wakatime_hostname="$(hostname)"
while [[ $# -gt 0 ]]; do
arg="${1}"
case "${arg}" in
--wakatime-api-key)
wakatime_api_key="${2}"
shift
shift
;;
--wakatime-hostname)
wakatime_hostname="${2}"
shift
shift
;;
--force)
if test -f "${HOME}/.wakatime.cfg"; then
mv -f "${HOME}/.wakatime.cfg{,.bak}" >/dev/null ;
fi
shift
;;
esac
done
if [ ! -f "${HOME}/.wakatime.cfg" ]; then
log_notice "Configuring Wakatime" "${icon}"
if [ -z "${wakatime_api_key}" ]; then
log_die "--wakatime-api-key required..." "${icon}"
else
install -m 666 "${BASEDIR}/wakatime.cfg" "${HOME}/.wakatime.cfg"
sed -e "
s|%API_KEY%|${wakatime_api_key}|g;
s|%HOSTNAME%|${wakatime_hostname}|g;
" -i "${HOME}/.wakatime.cfg"
log_done "Wakatime configured" "${icon}"
fi
else
log_done "Wakatime configured" "${icon}"
fi
}
if ((SHLVL > 1)); then
echo "kornicameister/dotfiles"
if ((EUID == 0)) && [[ -z ${CI:-} ]]; then
log_die "Altough root is required to install packages, ./install must not be launched as root" "${icon}" 3
fi
install_packages
install_links
configure_envs
configure_git "$@"
configure_nvim
configure_wakatime "$@"
post_install
screenfetch
fi