forked from cortexlabs/cortex
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcortex.sh
More file actions
executable file
·567 lines (499 loc) · 17.5 KB
/
Copy pathcortex.sh
File metadata and controls
executable file
·567 lines (499 loc) · 17.5 KB
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
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
#!/bin/bash
# Copyright 2019 Cortex Labs, Inc.
#
# Licensed 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.
set -e
####################
### FLAG PARSING ###
####################
flag_help=false
positional_args=()
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-c|--config)
export CORTEX_CONFIG="$2"
shift
shift
;;
-h|--help)
flag_help="true"
shift
;;
*)
positional_args+=("$1")
shift
;;
esac
done
set -- "${positional_args[@]}"
positional_args=()
for i in "$@"; do
case $i in
-c=*|--config=*)
export CORTEX_CONFIG="${i#*=}"
shift
;;
-h=*|--help=*)
flag_help="true"
;;
*)
positional_args+=("$1")
shift
;;
esac
done
set -- "${positional_args[@]}"
if [ "$flag_help" == "true" ]; then
show_help
exit 0
fi
for arg in "$@"; do
if [[ "$arg" == -* ]]; then
echo "unknown flag: $arg"
show_help
exit 1
fi
done
arg1=${1:-""}
arg2=${2:-""}
arg3=${3:-""}
set -u
#####################
### CONFIGURATION ###
#####################
export CORTEX_VERSION_BRANCH_STABLE=master
export CORTEX_CONFIG="${CORTEX_CONFIG:-""}"
if [ "$CORTEX_CONFIG" != "" ]; then
if [ ! -f "$CORTEX_CONFIG" ]; then
echo "Cortex config file does not exist: $CORTEX_CONFIG"
exit 1
fi
source $CORTEX_CONFIG
fi
export AWS_ACCESS_KEY_ID="${AWS_ACCESS_KEY_ID:-""}"
export AWS_SECRET_ACCESS_KEY="${AWS_SECRET_ACCESS_KEY:-""}"
export CORTEX_AWS_ACCESS_KEY_ID="${CORTEX_AWS_ACCESS_KEY_ID:-""}"
export CORTEX_AWS_SECRET_ACCESS_KEY="${CORTEX_AWS_SECRET_ACCESS_KEY:-""}"
export CORTEX_LOG_GROUP="${CORTEX_LOG_GROUP:-cortex}"
export CORTEX_BUCKET="${CORTEX_BUCKET:-""}"
export CORTEX_REGION="${CORTEX_REGION:-us-west-2}"
export CORTEX_CLUSTER="${CORTEX_CLUSTER:-cortex}"
export CORTEX_NODE_TYPE="${CORTEX_NODE_TYPE:-m5.large}"
export CORTEX_NODES_MIN="${CORTEX_NODES_MIN:-2}"
export CORTEX_NODES_MAX="${CORTEX_NODES_MAX:-5}"
export CORTEX_IMAGE_MANAGER="${CORTEX_IMAGE_MANAGER:-cortexlabs/manager:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_FLUENTD="${CORTEX_IMAGE_FLUENTD:-cortexlabs/fluentd:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_STATSD="${CORTEX_IMAGE_STATSD:-cortexlabs/statsd:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_OPERATOR="${CORTEX_IMAGE_OPERATOR:-cortexlabs/operator:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_TF_SERVE="${CORTEX_IMAGE_TF_SERVE:-cortexlabs/tf-serve:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_TF_API="${CORTEX_IMAGE_TF_API:-cortexlabs/tf-api:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_TF_SERVE_GPU="${CORTEX_IMAGE_TF_SERVE_GPU:-cortexlabs/tf-serve-gpu:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_ONNX_SERVE="${CORTEX_IMAGE_ONNX_SERVE:-cortexlabs/onnx-serve:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_ONNX_SERVE_GPU="${CORTEX_IMAGE_ONNX_SERVE_GPU:-cortexlabs/onnx-serve-gpu:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_CLUSTER_AUTOSCALER="${CORTEX_IMAGE_CLUSTER_AUTOSCALER:-cortexlabs/cluster-autoscaler:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_NVIDIA="${CORTEX_IMAGE_NVIDIA:-cortexlabs/nvidia:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_METRICS_SERVER="${CORTEX_IMAGE_METRICS_SERVER:-cortexlabs/metrics-server:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_ISTIO_CITADEL="${CORTEX_IMAGE_ISTIO_CITADEL:-cortexlabs/istio-citadel:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_ISTIO_GALLEY="${CORTEX_IMAGE_ISTIO_GALLEY:-cortexlabs/istio-galley:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_ISTIO_PILOT="${CORTEX_IMAGE_ISTIO_PILOT:-cortexlabs/istio-pilot:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_ISTIO_PROXY="${CORTEX_IMAGE_ISTIO_PROXY:-cortexlabs/istio-proxy:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_IMAGE_DOWNLOADER="${CORTEX_IMAGE_DOWNLOADER:-cortexlabs/downloader:$CORTEX_VERSION_BRANCH_STABLE}"
export CORTEX_ENABLE_TELEMETRY="${CORTEX_ENABLE_TELEMETRY:-""}"
export CORTEX_TELEMETRY_URL="${CORTEX_TELEMETRY_URL:-"https://telemetry.cortexlabs.dev"}"
function set_aws_credentials_from_cli() {
if ! command -v aws >/dev/null; then
return
fi
if [ ! -f $HOME/.aws/credentials ]; then
return
fi
if ! grep -Fxq "[default]" "$HOME/.aws/credentials"; then
return
fi
export AWS_ACCESS_KEY_ID=$(aws --profile default configure get aws_access_key_id)
export AWS_SECRET_ACCESS_KEY=$(aws --profile default configure get aws_secret_access_key)
}
function set_aws_credentials() {
if [ "$AWS_ACCESS_KEY_ID" != "" ] && [ "$AWS_SECRET_ACCESS_KEY" != "" ]; then
true
elif [ "$AWS_ACCESS_KEY_ID" == "" ] && [ "$AWS_SECRET_ACCESS_KEY" != "" ]; then
echo -e "\nPlease run \`export AWS_ACCESS_KEY_ID=***\`"
exit 1
elif [ "$AWS_ACCESS_KEY_ID" != "" ] && [ "$AWS_SECRET_ACCESS_KEY" == "" ]; then
echo -e "\nPlease run \`export AWS_SECRET_ACCESS_KEY=***\`"
exit 1
else
set_aws_credentials_from_cli
fi
if [ "$AWS_ACCESS_KEY_ID" == "" ] || [ "$AWS_SECRET_ACCESS_KEY" == "" ]; then
echo -e "\nPlease run \`export AWS_ACCESS_KEY_ID=***; export AWS_SECRET_ACCESS_KEY=***\`"
exit 1
fi
if [ "$CORTEX_AWS_ACCESS_KEY_ID" != "" ] && [ "$CORTEX_AWS_SECRET_ACCESS_KEY" != "" ]; then
true
elif [ "$CORTEX_AWS_ACCESS_KEY_ID" != "" ] || [ "$CORTEX_AWS_SECRET_ACCESS_KEY" != "" ]; then
echo -e "\nPlease export both CORTEX_AWS_ACCESS_KEY_ID and CORTEX_AWS_SECRET_ACCESS_KEY"
exit 1
fi
export CORTEX_AWS_ACCESS_KEY_ID="${CORTEX_AWS_ACCESS_KEY_ID:-$AWS_ACCESS_KEY_ID}"
export CORTEX_AWS_SECRET_ACCESS_KEY="${CORTEX_AWS_SECRET_ACCESS_KEY:-$AWS_SECRET_ACCESS_KEY}"
}
if [ "$arg2" != "cli" ]; then
set_aws_credentials
fi
function validate_install() {
if [[ $CORTEX_NODE_TYPE == *nano ]] || [[ $CORTEX_NODE_TYPE == *micro ]] || [[ $CORTEX_NODE_TYPE == *small ]] || [[ $CORTEX_NODE_TYPE == *medium ]]; then
echo -e "\nCortex does not support nano, micro, small, or medium instances - please specify a larger instance type"
exit 1
fi
}
if [ "$arg1" = "install" ] && [ "$arg2" = "" ] && [ "$arg3" = "" ]; then
validate_install
echo
echo "○ cluster name: $CORTEX_CLUSTER"
echo "○ region: $CORTEX_REGION"
echo "○ bucket: "${CORTEX_BUCKET:-autogenerate}""
echo "○ log group: $CORTEX_LOG_GROUP"
echo "○ instance type: $CORTEX_NODE_TYPE"
echo "○ min nodes: $CORTEX_NODES_MIN"
echo "○ max nodes: $CORTEX_NODES_MAX"
echo "○ AWS access key ID: ****************${AWS_ACCESS_KEY_ID:16}"
if [ "$CORTEX_AWS_ACCESS_KEY_ID" != "$AWS_ACCESS_KEY_ID" ]; then
echo "○ AWS access key ID: ****************${CORTEX_AWS_ACCESS_KEY_ID:16} (Operator)"
fi
while true; do
echo
read -p "Is the configuration above correct? [Y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
break
elif [[ $REPLY =~ ^[Nn]$ ]]; then
exit 1
fi
echo "Unexpected value, please enter \"Y\" or \"n\""
done
fi
##########################
### TOP-LEVEL COMMANDS ###
##########################
function install_eks() {
echo
docker run -it --entrypoint /root/install_eks.sh \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
-e CORTEX_CLUSTER=$CORTEX_CLUSTER \
-e CORTEX_REGION=$CORTEX_REGION \
-e CORTEX_NODE_TYPE=$CORTEX_NODE_TYPE \
-e CORTEX_NODES_MIN=$CORTEX_NODES_MIN \
-e CORTEX_NODES_MAX=$CORTEX_NODES_MAX \
$CORTEX_IMAGE_MANAGER
}
function uninstall_eks() {
echo
docker run -it --entrypoint /root/uninstall_eks.sh \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
-e CORTEX_CLUSTER=$CORTEX_CLUSTER \
-e CORTEX_REGION=$CORTEX_REGION \
$CORTEX_IMAGE_MANAGER
}
function install_cortex() {
echo
docker run -it -v $HOME/.cortex:/.cortex --entrypoint /root/install_cortex.sh \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
-e CORTEX_AWS_ACCESS_KEY_ID=$CORTEX_AWS_ACCESS_KEY_ID \
-e CORTEX_AWS_SECRET_ACCESS_KEY=$CORTEX_AWS_SECRET_ACCESS_KEY \
-e CORTEX_CLUSTER=$CORTEX_CLUSTER \
-e CORTEX_REGION=$CORTEX_REGION \
-e CORTEX_NODE_TYPE=$CORTEX_NODE_TYPE \
-e CORTEX_LOG_GROUP=$CORTEX_LOG_GROUP \
-e CORTEX_BUCKET=$CORTEX_BUCKET \
-e CORTEX_IMAGE_FLUENTD=$CORTEX_IMAGE_FLUENTD \
-e CORTEX_IMAGE_STATSD=$CORTEX_IMAGE_STATSD \
-e CORTEX_IMAGE_OPERATOR=$CORTEX_IMAGE_OPERATOR \
-e CORTEX_IMAGE_TF_SERVE=$CORTEX_IMAGE_TF_SERVE \
-e CORTEX_IMAGE_TF_API=$CORTEX_IMAGE_TF_API \
-e CORTEX_IMAGE_TF_SERVE_GPU=$CORTEX_IMAGE_TF_SERVE_GPU \
-e CORTEX_IMAGE_ONNX_SERVE=$CORTEX_IMAGE_ONNX_SERVE \
-e CORTEX_IMAGE_ONNX_SERVE_GPU=$CORTEX_IMAGE_ONNX_SERVE_GPU \
-e CORTEX_IMAGE_CLUSTER_AUTOSCALER=$CORTEX_IMAGE_CLUSTER_AUTOSCALER \
-e CORTEX_IMAGE_NVIDIA=$CORTEX_IMAGE_NVIDIA \
-e CORTEX_IMAGE_METRICS_SERVER=$CORTEX_IMAGE_METRICS_SERVER \
-e CORTEX_IMAGE_ISTIO_CITADEL=$CORTEX_IMAGE_ISTIO_CITADEL \
-e CORTEX_IMAGE_ISTIO_GALLEY=$CORTEX_IMAGE_ISTIO_GALLEY \
-e CORTEX_IMAGE_ISTIO_PILOT=$CORTEX_IMAGE_ISTIO_PILOT \
-e CORTEX_IMAGE_ISTIO_PROXY=$CORTEX_IMAGE_ISTIO_PROXY \
-e CORTEX_IMAGE_DOWNLOADER=$CORTEX_IMAGE_DOWNLOADER \
-e CORTEX_ENABLE_TELEMETRY=$CORTEX_ENABLE_TELEMETRY \
$CORTEX_IMAGE_MANAGER
}
function uninstall_operator() {
echo
docker run -it --entrypoint /root/uninstall_operator.sh \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
-e CORTEX_CLUSTER=$CORTEX_CLUSTER \
-e CORTEX_REGION=$CORTEX_REGION \
$CORTEX_IMAGE_MANAGER
}
function info() {
echo
docker run -it --entrypoint /root/info.sh \
-e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \
-e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \
-e CORTEX_CLUSTER=$CORTEX_CLUSTER \
-e CORTEX_REGION=$CORTEX_REGION \
$CORTEX_IMAGE_MANAGER
}
################
### CHECK OS ###
################
case "$OSTYPE" in
darwin*) PARSED_OS="darwin" ;;
linux*) PARSED_OS="linux" ;;
*) echo -e "\nerror: only mac and linux are supported"; exit 1 ;;
esac
#############################
### DEPENDENCY MANAGEMENT ###
#############################
function check_dep_curl() {
if ! command -v curl >/dev/null; then
echo -e "\nerror: please install \`curl\`"
exit 1
fi
}
function install_cli() {
set -e
echo -e "Installing CLI (/usr/local/bin/cortex) ..."
check_dep_curl
CORTEX_SH_TMP_DIR="$HOME/.cortex-sh-tmp"
rm -rf $CORTEX_SH_TMP_DIR && mkdir -p $CORTEX_SH_TMP_DIR
curl -s -o $CORTEX_SH_TMP_DIR/cortex https://s3-us-west-2.amazonaws.com/get-cortex/$CORTEX_VERSION_BRANCH_STABLE/cli/$PARSED_OS/cortex
chmod +x $CORTEX_SH_TMP_DIR/cortex
if [ $(id -u) = 0 ]; then
mv -f $CORTEX_SH_TMP_DIR/cortex /usr/local/bin/cortex
else
ask_sudo
sudo mv -f $CORTEX_SH_TMP_DIR/cortex /usr/local/bin/cortex
fi
rm -rf $CORTEX_SH_TMP_DIR
echo -e "\n✓ Installed CLI"
bash_profile_path=$(get_bash_profile)
if [ ! "$bash_profile_path" = "" ]; then
if ! grep -Fxq "source <(cortex completion)" "$bash_profile_path"; then
echo
read -p "Would you like to modify your bash profile ($bash_profile_path) to enable cortex command completion and the cx alias? [Y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "\nsource <(cortex completion)" >> $bash_profile_path
echo "✓ Your bash profile ($bash_profile_path) has been updated"
echo
echo "Note: \`bash_completion\` must be installed on your system for cortex command completion to function properly"
echo
echo "Command to update your current terminal session:"
echo " source $bash_profile_path"
else
echo "Your bash profile has not been modified. If you would like to modify it manually, add this line to your bash profile:"
echo " source <(cortex completion)"
echo "Note: \`bash_completion\` must be installed on your system for cortex command completion to function properly"
fi
fi
else
echo -e "\nIf your would like to enable cortex command completion and the cx alias, add this line to your bash profile:"
echo " source <(cortex completion)"
echo "Note: \`bash_completion\` must be installed on your system for cortex command completion to function properly"
fi
}
function uninstall_cli() {
set -e
rm -rf $HOME/.cortex
if ! command -v cortex >/dev/null; then
echo -e "\nThe CLI is not installed"
return
fi
if [[ ! -f /usr/local/bin/cortex ]]; then
echo -e "\nThe CLI was not found at /usr/local/bin/cortex, please uninstall it manually"
return
fi
if [ $(id -u) = 0 ]; then
rm /usr/local/bin/cortex
else
ask_sudo
sudo rm /usr/local/bin/cortex
fi
echo -e "\n✓ Uninstalled CLI"
bash_profile_path=$(get_bash_profile)
if [ ! "$bash_profile_path" = "" ]; then
if grep -Fxq "source <(cortex completion)" "$bash_profile_path"; then
echo
read -p "Would you like to remove \"source <(cortex completion)\" from your bash profile ($bash_profile_path)? [Y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
sed '/^source <(cortex completion)$/d' "$bash_profile_path" > "${bash_profile_path}_cortex_modified" && mv -f "${bash_profile_path}_cortex_modified" "$bash_profile_path"
echo "✓ Your bash profile ($bash_profile_path) has been updated"
fi
fi
fi
}
function get_bash_profile() {
if [ "$PARSED_OS" = "darwin" ]; then
if [ -f $HOME/.bash_profile ]; then
echo $HOME/.bash_profile
return
elif [ -f $HOME/.bashrc ]; then
echo $HOME/.bashrc
return
fi
else
if [ -f $HOME/.bashrc ]; then
echo $HOME/.bashrc
return
elif [ -f $HOME/.bash_profile ]; then
echo $HOME/.bash_profile
return
fi
fi
echo ""
}
function ask_sudo() {
if ! sudo -n true 2>/dev/null; then
echo -e "\nPlease enter your sudo password"
fi
}
function prompt_for_email() {
if [ "$CORTEX_ENABLE_TELEMETRY" != "false" ]; then
echo
read -p "Email address [press enter to skip]: "
echo
if [[ ! -z "$REPLY" ]]; then
curl -k -X POST -H "Content-Type: application/json" $CORTEX_TELEMETRY_URL/support -d '{"email_address": "'$REPLY'", "source": "cortex.sh"}' >/dev/null 2>&1 || true
fi
fi
}
function prompt_for_telemetry() {
if [ "$CORTEX_ENABLE_TELEMETRY" != "true" ] && [ "$CORTEX_ENABLE_TELEMETRY" != "false" ]; then
while true; do
echo
read -p "Would you like to help improve Cortex by anonymously sending error reports and cluster usage stats to the dev team? [Y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
export CORTEX_ENABLE_TELEMETRY=true
break
elif [[ $REPLY =~ ^[Nn]$ ]]; then
export CORTEX_ENABLE_TELEMETRY=false
break
fi
echo "Unexpected value, please enter \"Y\" or \"n\""
done
fi
}
function confirm_for_uninstall() {
while true; do
echo
read -p "Are you sure you want to uninstall Cortex? (Your cluster will be spun down and all APIs will be deleted) [Y/n] " -n 1 -r
echo
if [[ $REPLY =~ ^[Yy]$ ]]; then
break
elif [[ $REPLY =~ ^[Nn]$ ]]; then
exit 0
fi
echo "Unexpected value: $REPLY. Please enter \"Y\" or \"n\""
done
}
############
### HELP ###
############
function show_help() {
echo "
Usage:
./cortex.sh command [sub-command] [flags]
Available Commands:
install install Cortex
uninstall uninstall Cortex
update update Cortex
info information about Cortex
install cli install the Cortex CLI
uninstall cli uninstall the Cortex CLI
Flags:
-c, --config path to a Cortex config file
-h, --help
"
}
######################
### ARG PROCESSING ###
######################
if [ -z "$arg1" ]; then
show_help
exit 0
fi
if [ "$arg1" = "install" ]; then
if [ ! "$arg3" = "" ]; then
echo -e "\nerror: too many arguments for install command"
show_help
exit 1
elif [ "$arg2" = "" ]; then
prompt_for_telemetry && install_eks && install_cortex
elif [ "$arg2" = "cli" ]; then
prompt_for_email && install_cli
elif [ "$arg2" = "cortex" ]; then # Undocumented (just for dev)
install_cortex
elif [ "$arg2" = "" ]; then
echo -e "\nerror: missing subcommand for install"
show_help
exit 1
else
echo -e "\nerror: invalid subcommand for install: $arg2"
show_help
exit 1
fi
elif [ "$arg1" = "uninstall" ]; then
if [ ! "$arg3" = "" ]; then
echo -e "\nerror: too many arguments for uninstall command"
show_help
exit 1
elif [ "$arg2" = "" ]; then
confirm_for_uninstall && uninstall_eks
elif [ "$arg2" = "cli" ]; then
uninstall_cli
elif [ "$arg2" = "" ]; then
echo -e "\nerror: missing subcommand for uninstall"
show_help
exit 1
else
echo -e "\nerror: invalid subcommand for uninstall: $arg2"
show_help
exit 1
fi
elif [ "$arg1" = "update" ]; then
if [ ! "$arg2" = "" ]; then
echo -e "\nerror: too many arguments for get command"
show_help
exit 1
else
uninstall_operator && install_cortex
fi
elif [ "$arg1" = "info" ]; then
if [ ! "$arg2" = "" ]; then
echo -e "\nerror: too many arguments for get command"
show_help
exit 1
else
info
fi
else
echo -e "\nerror: unknown command: $arg1"
show_help
exit 1
fi