-
Notifications
You must be signed in to change notification settings - Fork 10
/
krd_command.sh
executable file
·76 lines (68 loc) · 2.28 KB
/
krd_command.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
#!/bin/bash
# SPDX-license-identifier: Apache-2.0
##############################################################################
# Copyright (c) 2018
# All rights reserved. This program and the accompanying materials
# are made available under the terms of the Apache License, Version 2.0
# which accompanies this distribution, and is available at
# http://www.apache.org/licenses/LICENSE-2.0
##############################################################################
set -o errexit
set -o pipefail
set -o nounset
source _functions.sh
source _installers.sh
source _chart_installers.sh
source _uninstallers.sh
if [[ $KRD_DEBUG == "true" ]]; then
set -o xtrace
fi
if ! sudo -n "true"; then
echo ""
echo "passwordless sudo is needed for '$(id -nu)' user."
echo "Please fix your /etc/sudoers file. You likely want an"
echo "entry like the following one..."
echo ""
echo "$(id -nu) ALL=(ALL) NOPASSWD: ALL"
exit 1
fi
function join_by {
local delimiter=${1-}
local items=${2-}
if shift 2; then
printf %s "$items" "${@/#/$delimiter}"
fi
}
applications=(k8sgpt-operator local-ai kube-monkey haproxy)
valid_options=$(find . -maxdepth 1 -name "_*.sh" -exec grep -o "^function [a-z].*" {} + | awk '{printf "%s|", $2}')
valid_options+="install_$(join_by '|install_' "${applications[@]}")|uninstall_$(join_by '|uninstall_' "${applications[@]}")|"
function usage {
cat <<EOF
Usage: $0 [-a <${valid_options%?}>]
EOF
}
while getopts ":a:" OPTION; do
case $OPTION in
a)
eval "case \$OPTARG in
${valid_options%?})
echo \"::group::Running \$OPTARG...\"
[[ \" ${applications[*]} \" =~ [[:space:]]\${OPTARG#*install_}[[:space:]] ]] && _\${OPTARG/install_/install_app } || \$OPTARG
if [ \"\$KRD_ENABLE_TESTS\" == \"true\" ] && [ -f \$KRD_FOLDER/tests/\${OPTARG#*install_}.sh ] ; then
pushd \$KRD_FOLDER/tests
bash \${OPTARG#*install_}.sh
popd
fi
echo \"::endgroup::\"
;;
*)
echo Invalid action
usage
exit 1
esac"
;;
*)
usage
;;
esac
done