-
Notifications
You must be signed in to change notification settings - Fork 160
Expand file tree
/
Copy pathinstall.sh
More file actions
147 lines (130 loc) · 4.06 KB
/
install.sh
File metadata and controls
147 lines (130 loc) · 4.06 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
#!/bin/bash
set -eo pipefail
echo "Getting kubectl-testkube plugin"
if [ ! -z "${DEBUG}" ];
then set -x
fi
_check_required_tools() {
local MISSING_TOOLS=""
for CMD in curl jq; do
if ! which "${CMD}" &>/dev/null; then
MISSING_TOOLS="${MISSING_TOOLS}${CMD} "
fi
done
if [[ ${MISSING_TOOLS} != "" ]]; then
echo "Missing required tools: ${MISSING_TOOLS}"
echo Please install these using your package manager and try again.
exit 1
fi
}
_detect_arch() {
case $(uname -m) in
amd64|x86_64) echo "x86_64"
;;
arm64|aarch64) echo "arm64"
;;
i386) echo "i386"
;;
*) echo "Unsupported processor architecture";
return 1
;;
esac
}
_detect_os(){
case $(uname) in
Linux) echo "Linux"
;;
Darwin) echo "Darwin"
;;
Windows) echo "Windows"
;;
esac
}
_download_url() {
local arch
local os
local tag
local version
arch="$(_detect_arch)"
os="$(_detect_os)"
if [ -z "$TESTKUBE_VERSION" ]; then
if [ "$1" = "beta" ]; then
tag="$(
curl -s "https://api.github.com/repos/kubeshop/testkube/releases" \
2>/dev/null \
| jq -r '.[].tag_name | select(test("beta"))' \
| head -n 1 \
)"
if [ -z "$tag" ]; then
echo "No beta releases found. Installing latest release" >&2
tag="$(
curl -s "https://api.github.com/repos/kubeshop/testkube/releases/latest" \
2>/dev/null \
| jq -r '.tag_name' \
)"
fi
else
tag="$(
curl -s "https://api.github.com/repos/kubeshop/testkube/releases/latest" \
2>/dev/null \
| jq -r '.tag_name' \
)"
fi
else
tag="$TESTKUBE_VERSION"
fi
version="${tag/#v/}" # remove leading v if present
# Normalize the tag format based on the version number when a version is explicitly provided.
# Starting from 2.4.0, release tags dropped the 'v' prefix.
# For auto-detected versions fetched from the API, the tag already has the correct format.
if [ -n "$TESTKUBE_VERSION" ]; then
# Only attempt numeric comparison when the version looks like a full numeric semver (X.Y.Z).
# Strip any pre-release/build suffix (e.g. "2.4.0-beta" -> "2.4.0") before validation.
local major minor normalized_version
normalized_version="${version%%-*}"
if [[ "$normalized_version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
major=$(echo "$normalized_version" | cut -d. -f1)
minor=$(echo "$normalized_version" | cut -d. -f2)
if [ "$major" -lt 2 ] || { [ "$major" -eq 2 ] && [ "$minor" -lt 4 ]; }; then
tag="v${version}"
else
tag="${version}"
fi
fi
fi
echo "https://github.com/kubeshop/testkube/releases/download/${tag}/testkube_${version:-1}_${os}_$arch.tar.gz"
}
_check_required_tools
if [ "$1" = "beta" ]; then
url="$(_download_url "beta")"
echo "Downloading testkube from URL: $url"
curl -sSLf "$url" > testkube.tar.gz
else
echo "Downloading testkube from URL: $(_download_url)"
curl -sSLf "$(_download_url)" > testkube.tar.gz
fi
INSTALL_DIR=/usr/local/bin
echo "Installing testkube into ${INSTALL_DIR}"
INSTALL_PREFIX=""
if ! [[ -w "$INSTALL_DIR" ]]; then
echo -e "\e[1;38;5;208m"
echo "Looks like the current user does not have write access to ${INSTALL_DIR}"
echo "You might be prompted to enter your password below by sudo"
echo -e "\e[0m"
INSTALL_PREFIX=sudo
fi
tar -xzf testkube.tar.gz kubectl-testkube
rm testkube.tar.gz
${INSTALL_PREFIX} mv kubectl-testkube ${INSTALL_DIR}/kubectl-testkube
${INSTALL_PREFIX} ln -sf ${INSTALL_DIR}/kubectl-testkube ${INSTALL_DIR}/testkube
${INSTALL_PREFIX} ln -sf ${INSTALL_DIR}/kubectl-testkube ${INSTALL_DIR}/tk
echo "kubectl-testkube installed in:"
echo "- ${INSTALL_DIR}/kubectl-testkube"
echo "- ${INSTALL_DIR}/testkube"
echo "- ${INSTALL_DIR}/tk"
echo ""
if ! which helm &>/dev/null || ! which kubectl &>/dev/null; then
echo "You'll also need to install \`helm\` and \`kubectl\`."
echo "- Install Helm: https://helm.sh/docs/intro/install/"
echo "- Install kubectl: https://kubernetes.io/docs/tasks/tools/#kubectl"
fi