forked from nuvolaris/nuvolaris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup.source
312 lines (271 loc) · 7.25 KB
/
setup.source
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
## NOTE! This script should be sourced, not executed.
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
if test -z "$BASH"
then echo "Please, source me using bash." ; kill -INT $$
fi
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
then echo "You must source this script with bash, not execute it." ; kill -INT $$
fi
# versions
export NODENV_VERSION=18.15.0
export PYENV_VERSION=3.11.1
export GOENV_VERSION=1.21.4
export DOCKER_VERSION=19
export JAVA_VERSION=8
# env
export PYENV_ROOT="$HOME/.pyenv"
export NODENV_ROOT="$HOME/.nodenv"
export GOENV_ROOT="$HOME/.goenv"
export NUV_INSTALL_DIR="/usr/nuvolaris"
# git config
export GIT_EDITOR=vim
# prompt
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'
}
export PS1="[\[\e[32m\]\w:\[\e[91m\]\$(parse_git_branch)\[\e[00m\]]\n$ "
# Preflight checks
die() {
echo ERROR: "$@"
kill -INT $$
}
ok() {
echo OK: "$@"
}
ko() {
echo KO: "$@"
}
if ! which gcc >/dev/null
then die "Please install development tools"
else ok gcc
fi
if ! which git >/dev/null
then die "Please install git"
else ok git
fi
if test -S /var/run/docker.sock
then
if ! which docker >/dev/null
then die "Please install docker and assign access to this user"
else
DOCKER_CUR_VERSION=$(docker version -f '{{.Server.Version}}' | awk -F. '{print $1}')
if [[ $DOCKER_CUR_VERSION -lt $DOCKER_VERSION ]]
then die "required at least docker $DOCKER_VERSION, you have $DOCKER_CUR_VERSION"
else ok docker
fi
fi
fi
if ! which java >/dev/null
then die "Please install java"
else
JAVA_CUR_VERSION=$(java -version 2>&1 | awk 'NR==1 { gsub("\"", "", $3) ; split($3,a,"."); print(a[1] == "1" ? a[2] : a[1]) }' )
if [[ $JAVA_CUR_VERSION -lt $JAVA_VERSION ]]
then die "required at least java $JAVA_VERSION, you have java $JAVA_CUR_VERSION"
else ok java
fi
fi
if ! which wsk >/dev/null
then echo "*** Please install wsk ***"
else ok wsk
fi
# Install Go
if test -e $GOENV_ROOT/$GOENV_VERSION
then ok goenv
else rm -Rvf $GOENV_ROOT
git clone https://github.com/syndbg/goenv.git $GOENV_ROOT
touch $GOENV_ROOT/$GOENV_VERSION
fi
export GOBIN="$HOME/.local/bin"
export PATH="$GOBIN:$GOENV_ROOT/bin:$PATH"
eval "$(goenv init -)"
goenv install $GOENV_VERSION -s && touch $GOENV_ROOT/$GOENV_VERSION
# Install Node
if test -e $NODENV_ROOT/$NODENV_VERSION
then ok nodenv
else rm -Rvf $NODENV_ROOT
git clone https://github.com/nodenv/nodenv.git $NODENV_ROOT
mkdir "$NODENV_ROOT/plugins"
git clone https://github.com/nodenv/node-build.git "$NODENV_ROOT"/plugins/node-build
fi
export PATH="$NODENV_ROOT/bin:$PATH"
eval "$(nodenv init -)"
nodenv install $NODENV_VERSION -s && touch $NODENV_ROOT/$NODENV_VERSION
# Install Python
if test -e $PYENV_ROOT/$PYENV_VERSION
then ok pyenv
else rm -Rvf $PYENV_ROOT
git clone https://github.com/pyenv/pyenv.git $PYENV_ROOT
fi
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init --path)"
eval "$(pyenv init -)"
pyenv install $PYENV_VERSION -s && touch $PYENV_ROOT/$PYENV_VERSION
# install task
if ! which task >/dev/null
then go install github.com/go-task/task/v3/cmd/task@latest
else ok task
fi
# install yq
if ! which yq >/dev/null
then go install github.com/mikefarah/yq/v4@latest
else ok yq
fi
# install virtualenv
if ! which virtualenv >/dev/null
then pip install virtualenv
else ok virtualenv
fi
# install httpie
if ! which http >/dev/null
then pip install httpie
else ok httpie
fi
# install ipython
if ! which ipython >/dev/null
then pip install ipython
else ok httpie
fi
# install xonsh
if ! which xonsh >/dev/null
then pip install xonsh[full]
else ok xonsh
fi
# install addlicense
if ! which license-eye >/dev/null
then go install github.com/apache/skywalking-eyes/cmd/license-eye@latest
else ok license-eye
fi
# add git hook for checking licenses
if [[ -e .git ]] && ! [[ -e .git-hooks/pre-push ]]
then
mkdir -p .git-hooks
cat <<EOF >.git-hooks/pre-push
#!/bin/sh
if test -e .licenserc.yaml
then license-eye header check
fi
EOF
chmod +x .git-hooks/pre-push
git config core.hooksPath .git-hooks
fi
# install poetry
if ! which poetry >/dev/null
then curl -sSL https://install.python-poetry.org | python3 -
else ok poetry
fi
# install jest
if ! which jest >/dev/null
then npm install -g jest
else ok jest
fi
export PATH="$(nodenv prefix)/bin:$PATH"
# install zx
if ! which zx >/dev/null
then npm install -g zx
else ok zx
fi
# install antora
if ! which antora >/dev/null
then npm i -g @antora/[email protected] @antora/[email protected]
else ok antora
fi
# install coursier - commented out as not required for now
#if ! which cs >/dev/null
#then curl -sfLo $HOME/.local/bin/cs https://git.io/coursier-cli-"$(uname | tr LD ld)"
# chmod +x $HOME/.local/bin/cs
#else ok coursier
#fi
#eval "$(cs setup --env 2>/dev/null)"
# install func
#if ! which func >/dev/null
#then
# pushd /tmp
# git clone https://github.com/knative-sandbox/kn-plugin-func.git
# cd kn-plugin-func
# make
# mv func $GOBIN/func
# popd
# rm -Rvf /tmp/kn-plugin-func
#else ok func
#fi
# load gcloud sdk
if test -d ~/.local/google-cloud-sdk; then
source ~/.local/google-cloud-sdk/completion.bash.inc
source ~/.local/google-cloud-sdk/path.bash.inc
fi
# install hcloud
if ! which hcloud >/dev/null
then go install github.com/hetznercloud/cli/cmd/hcloud@latest
else ok hcloud
fi
# install linode-cli
if ! which linode-cli >/dev/null
then pip install linode-cli
else ok linode-cli
fi
if ! test -e $GOBIN/z.sh
then curl -sL https://raw.githubusercontent.com/rupa/z/master/z.sh >$GOBIN/z.sh
else ok z
fi
source $GOBIN/z.sh
if ! which godaddy-cli >/dev/null
then go install github.com/Cabemo/[email protected]
else ok go-daddy
fi
# install go tools for VSCode
for REF in \
github.com/cweill/gotests/[email protected] \
github.com/fatih/[email protected] \
github.com/josharian/[email protected] \
github.com/haya14busa/goplay/cmd/[email protected] \
github.com/go-delve/delve/cmd/dlv@latest \
honnef.co/go/tools/cmd/staticcheck@latest \
golang.org/x/tools/gopls@latest
do CMD="$(basename ${REF%%@*})"
if which $CMD >/dev/null
then ok $CMD
else go install $REF
fi
done
# Check existence of nuv cli installed via deb and add it to the classpath
if test -e $NUV_INSTALL_DIR
then
export PATH="$PATH:$NUV_INSTALL_DIR"
ok nuv
else
ko $NUV_INSTALL_DIR
fi
# Check for kubectl
if ! which kubectl >/dev/null
then die "Please install kubectl"
else ok kubectl
fi
# replace
if ! which replace >/dev/null
then npm install -g replace
else ok replace
fi
# extra
if test -e ~/.localrc
then source ~/.localrc
fi
# setup
if test -e Taskfile.yml
then task setup
fi