This repository has been archived by the owner on Mar 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
/
setup.sh
executable file
·413 lines (401 loc) · 13.8 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
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
#!/bin/bash
# shellcheck disable=SC2046 disable=SC2143
# Check sudo availability
sudo_command=$(command -v sudo)
## Linux install cases
if [[ ${OSTYPE} == 'linux'* ]]; then
echo "--> This is a Linux build"
## apt-based systems
if command -v apt >/dev/null 2>&1; then
echo "--> Checking system packages and installing any missing packages"
# Update apt before starting, in case this is a new container
APTPACKAGES=" \
curl \
python \
openssl \
jq \
"
for package in $APTPACKAGES; do
if ! dpkg -s "$package" >/dev/null; then
echo "--> Apt installing $package"
(${sudo_command} apt update && ${sudo_command} apt install -y "$package") || {
echo >&2 "--> $package install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> $package already installed"
fi
done
if ! command -v az >/dev/null 2>&1; then
echo "--> Attempting to install Azure-CLI with deb packages"
curl -sL https://aka.ms/InstallAzureCLIDeb | ${sudo_command} bash || {
echo >&2 "--> Azure-CLI install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> Azure-CLI already installed"
fi
if ! command -v kubectl >/dev/null 2>&1; then
echo "--> Attempting to install kubectl with deb packages"
${sudo_command} apt-get update && ${sudo_command} apt-get install -y apt-transport-https
curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | ${sudo_command} apt-key add -
echo "deb https://apt.kubernetes.io/ kubernetes-xenial main" | ${sudo_command} tee -a /etc/apt/sources.list.d/kubernetes.list
(${sudo_command} apt-get update && ${sudo_command} apt-get install -y kubectl) || {
echo >&2 "--> kubectl install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> kubectl already installed"
fi
## yum-based systems
elif command -v yum >/dev/null 2>&1; then
if [ $(grep -iq centos /etc/redhat-release) ]; then
echo "***************************************************************"
echo "* You appear to be running CentOS. A required package, jq, is *"
echo "* not available from core repositories but can be installed *"
echo "* from the epel-release repository. If a jq install fails, *"
echo "* run the following command as root (or with sudo) to enable *"
echo "* the epel repository: *"
echo "* *"
echo "* yum -y install epel-release *"
echo "* *"
echo "***************************************************************"
fi
echo "--> Checking system packages and installing any missing packages"
YUMPACKAGES=" \
jq \
curl \
python \
tar \
which \
openssl \
"
for package in $YUMPACKAGES; do
if ! rpm -q "$package" >/dev/null; then
echo "--> Yum installing $package"
${sudo_command} yum install -y "$package" || {
echo >&2 "--> $package install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> $package already installed"
fi
done
if ! command -v az >/dev/null 2>&1; then
echo "--> Attempting to install Azure-CLI with yum packages"
${sudo_command} rpm --import https://packages.microsoft.com/keys/microsoft.asc
${sudo_command} sh -c 'echo -e "[azure-cli]\nname=Azure CLI\nbaseurl=https://packages.microsoft.com/yumrepos/azure-cli\nenabled=1\ngpgcheck=1\ngpgkey=https://packages.microsoft.com/keys/microsoft.asc" > /etc/yum.repos.d/azure-cli.repo'
${sudo_command} yum install -y azure-cli || {
echo >&2 "--> Azure-CLI install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> Azure-CLI already installed"
fi
if ! command -v kubectl >/dev/null 2>&1; then
echo "--> Attempting to install kubectl with yum packages"
echo "[kubernetes]
name=Kubernetes
baseurl=https://packages.cloud.google.com/yum/repos/kubernetes-el7-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
" | ${sudo_command} tee /etc/yum.repos.d/kubernetes.repo
${sudo_command} yum install -y kubectl || {
echo >&2 "--> kubectl install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> kubectl already installed"
fi
## zypper-based systems
elif command -v zypper >/dev/null 2>&1; then
echo "--> Checking system packages and installing any missing packages"
ZYPPERPACKAGES=" \
curl \
python \
tar \
which \
jq \
openssl \
"
for package in $ZYPPERPACKAGES; do
if ! rpm -q "$package" >/dev/null; then
echo "--> Zypper installing $package"
${sudo_command} zypper install -y "$package" || {
echo >&2 "--> $package install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> $package already installed"
fi
done
if ! command -v az >/dev/null 2>&1; then
echo "--> Attempting to install Azure-CLI with zypper packages"
${sudo_command} rpm --import https://packages.microsoft.com/keys/microsoft.asc
${sudo_command} zypper addrepo --name 'Azure CLI' --check https://packages.microsoft.com/yumrepos/azure-cli azure-cli
${sudo_command} zypper install --from azure-cli -y azure-cli || {
echo >&2 "--> azure-cli install failed; please install manually and re-run this script."
exit 1
}
# The az-cli installer misses python-xml dependency on suse
${sudo_command} zypper install -y python-xml || {
echo >&2 "--> python-xml install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> Azure-CLI already installed"
fi
if ! command -v kubectl >/dev/null 2>&1; then
echo "--> Attempting to install kubectl with zypper packages"
zypper ar -f https://download.opensuse.org/tumbleweed/repo/oss/ factory
zypper install -y kubectl || {
echo >&2 "--> kubectl install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> kubectl already installed"
fi
## pacman-based systems
elif command -v pacman >/dev/null 2>&1; then
echo "--> Checking system packages and installing any missing packages"
PACMANPACKAGES=" \
curl \
python \
tar \
which \
jq \
gcc \
awk \
grep \
openssl \
kubectl \
"
for package in $PACMANPACKAGES; do
if ! pacman -Q "$package" 2>/dev/null; then
echo "--> pacman installing $package"
${sudo_command} pacman -Sy --noconfirm "$package" || {
echo >&2 "--> $package install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> $package already installed"
fi
done
if ! command -v az >/dev/null 2>&1; then
echo "--> Attempting to install Azure-CLI with curl"
curl -L https://aka.ms/InstallAzureCli | sh || {
echo >&2 "--> Azure-CLI install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> Azure-CLI already installed"
fi
## Mystery linux system without any of our recognised package managers
else
command -v curl >/dev/null 2>&1 || {
echo >&2 "curl not found; please install and re-run this script."
exit 1
}
command -v awk >/dev/null 2>&1 || {
echo >&2 "awk not found; please install and re-run this script."
exit 1
}
command -v grep >/dev/null 2>&1 || {
echo >&2 "grep not found; please install and re-run this script."
exit 1
}
command -v python >/dev/null 2>&1 || {
echo >&2 "python not found; please install and re-run this script."
exit 1
}
command -v jq >/dev/null 2>&1 || {
echo >&2 "jq not found; please install and re-run this script."
exit 1
}
echo "--> Attempting to install Azure-CLI with curl"
if ! command -v az >/dev/null 2>&1; then
curl -L https://aka.ms/InstallAzureCli | sh || {
echo >&2 "--> Azure-CLI install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> Azure-CLI already installed"
fi
echo "--> Attempting to install kubectl with curl"
if ! command -v kubectl >/dev/null 2>&1; then
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl || {
echo >&2 "--> kubectl download failed; please install manually and re-run this script."
exit 1
}
chmod +x ./kubectl
${sudo_command} mv ./kubectl /usr/local/bin/kubectl
else
echo "--> kubectl already installed"
fi
fi
## Helm isn't well packaged for Linux, alas
command -v curl >/dev/null 2>&1 || {
echo >&2 "curl not found; please install and re-run this script."
exit 1
}
command -v awk >/dev/null 2>&1 || {
echo >&2 "awk not found; please install and re-run this script."
exit 1
}
command -v grep >/dev/null 2>&1 || {
echo >&2 "grep not found; please install and re-run this script."
exit 1
}
command -v python >/dev/null 2>&1 || {
echo >&2 "python not found; please install and re-run this script."
exit 1
}
command -v tar >/dev/null 2>&1 || {
echo >&2 "tar not found; please install and re-run this script."
exit 1
}
command -v which >/dev/null 2>&1 || {
echo >&2 "which not found; please install and re-run this script."
exit 1
}
echo "--> Helm doesn't have a system package; attempting to install with curl"
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
## Installing on OS X
elif [[ ${OSTYPE} == 'darwin'* ]]; then
echo "--> This is a MacOS build"
if command -v brew >/dev/null 2>&1; then
echo "--> Checking brew packages and installing any missing packages"
BREWPACKAGES=" \
curl \
python \
azure-cli \
kubernetes-cli \
helm \
jq \
"
brew update
for package in $BREWPACKAGES; do
if ! brew ls --versions "$package" >/dev/null; then
echo "--> Brew installing $package"
brew install "$package" || {
echo >&2 "--> $package install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> $package is already installed"
fi
done
else
command -v curl >/dev/null 2>&1 || {
echo >&2 "curl not found; please install and re-run this script."
exit 1
}
command -v python >/dev/null 2>&1 || {
echo >&2 "python not found; please install and re-run this script."
exit 1
}
command -v tar >/dev/null 2>&1 || {
echo >&2 "tar not found; please install and re-run this script."
exit 1
}
command -v which >/dev/null 2>&1 || {
echo >&2 "which not found; please install and re-run this script."
exit 1
}
echo "--> Attempting to install Azure-CLI with curl"
if ! command -v az >/dev/null 2>&1; then
curl -L https://aka.ms/InstallAzureCli | sh || {
echo >&2 "--> Azure-CLI install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> Azure-CLI already installed"
fi
echo "--> Attempting to install kubectl with curl"
if ! command -v kubectl >/dev/null 2>&1; then
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl || {
echo >&2 "--> kubectl download failed; please install manually and re-run this script."
exit 1
}
chmod +x ./kubectl
${sudo_command} mv ./kubectl /usr/local/bin/kubectl
else
echo "--> kubectl already installed"
fi
echo "--> Attempting to install helm with curl"
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
fi
else
echo "--> This is a Windows build"
## chocolatey-based systems
if command -v choco >/dev/null 2>&1; then
echo "--> Checking chocolatey packages and installing any missing packages"
CHOCPACKAGES=" \
curl \
python \
azure-cli \
kubernetes-cli \
kubernetes-helm \
jq \
"
choco upgrade chocolatey -y
for package in $CHOCPACKAGES; do
if ! choco search --local-only "$package" >/dev/null; then
echo "--> Choco installing $package"
choco install "$package" || {
echo >&2 "--> $package install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> $package is already installed"
fi
done
else
command -v curl >/dev/null 2>&1 || {
echo >&2 "curl not found; please install and re-run this script."
exit 1
}
command -v python >/dev/null 2>&1 || {
echo >&2 "python not found; please install and re-run this script."
exit 1
}
command -v tar >/dev/null 2>&1 || {
echo >&2 "tar not found; please install and re-run this script."
exit 1
}
command -v which >/dev/null 2>&1 || {
echo >&2 "which not found; please install and re-run this script."
exit 1
}
echo "--> Attempting to install Azure-CLI with curl"
if ! command -v az >/dev/null 2>&1; then
curl -L https://aka.ms/InstallAzureCli | sh || {
echo >&2 "--> Azure-CLI install failed; please install manually and re-run this script."
exit 1
}
else
echo "--> Azure-CLI already installed"
fi
echo "--> Attempting to install kubectl with curl"
if ! command -v kubectl >/dev/null 2>&1; then
curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/darwin/amd64/kubectl || {
echo >&2 "--> kubectl download failed; please install manually and re-run this script."
exit 1
}
chmod +x ./kubectl
${sudo_command} mv ./kubectl /usr/local/bin/kubectl
else
echo "--> kubectl already installed"
fi
echo "--> Attempting to install helm with curl"
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh
fi
fi