This repository was archived by the owner on Nov 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathget.sh
executable file
·215 lines (179 loc) · 7.99 KB
/
get.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
#!/bin/bash
########################################################################################################################
# get.keptn.sh / get.sh #
# Quickstart for installing Keptn CLI on several platforms #
# see https://github.com/keptn/get.keptn.sh for more details #
# #
# This script is licenced under Apache License 2.0, see https://github.com/keptn/get.keptn.sh/blob/master/LICENSE #
# In addition, parts of this script are copied from or inspired by: #
# * Istios Quickstart: https://github.com/istio/istio/blob/master/release/downloadIstioCandidate.sh #
# Apache License 2.0, https://github.com/istio/istio/blob/master/LICENSE #
# * Helm Quickstart: https://github.com/helm/helm/blob/master/scripts/get-helm-3 #
# Apache License 2.0, https://github.com/helm/helm/blob/master/LICENSE #
########################################################################################################################
# Define handy functions
get_latest_version(){
if [[ -n "$GITHUB_TOKEN" ]]; then
curl --silent -H "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/keptn/keptn/releases/latest" | grep tag_name | awk 'match($0, /[0-9]+.[0-9]+.[0-9]+[.\-A-Za-z0-9]*/) { print substr( $0, RSTART, RLENGTH )}'
else
curl --silent "https://api.github.com/repos/keptn/keptn/releases/latest" | grep tag_name | awk 'match($0, /[0-9]+.[0-9]+.[0-9]+[.\-A-Za-z0-9]*/) { print substr( $0, RSTART, RLENGTH )}'
fi
}
get_all_versions(){
if [[ -n "$GITHUB_TOKEN" ]]; then
curl --silent -H "Authorization: Bearer $GITHUB_TOKEN" "https://api.github.com/repos/keptn/keptn/releases" | grep tag_name | awk 'match($0, /[0-9]+.[0-9]+.[0-9]+[.\-A-Za-z0-9]*/) { print substr( $0, RSTART, RLENGTH )}'
else
curl --silent "https://api.github.com/repos/keptn/keptn/releases" | grep tag_name | awk 'match($0, /[0-9]+.[0-9]+.[0-9]+[.\-A-Za-z0-9]*/) { print substr( $0, RSTART, RLENGTH )}'
fi
}
print_after_installation_info(){
TARGET_DIR=${1:-""}
printf "\n"
printf "Keptn CLI installation completed successfully!"
printf "\n"
printf "You can check the Keptn CLI installation by running:"
printf "\n"
printf "\n"
printf "${TARGET_DIR}keptn --help"
printf "\n"
printf "\n"
printf "To install Keptn in your cluster, please follow the documentation at https://keptn.sh/docs/"
printf "\n"
printf "\n"
printf "Learn more on how to use Keptn in our tutorials at https://tutorials.keptn.sh/"
printf "\n"
printf "\n"
printf "Welcome aboard!"
printf "\n"
printf "\n"
}
runAsRoot() {
CMD="$*"
if [[ $EUID == 0 ]] || [[ ${USE_SUDO} == "false" ]]; then
$CMD
else
echo "Trying to run $CMD with sudo..."
sudo $CMD
fi
}
# Verify sudo is available
if ! [ -x "$(command -v sudo)" ]; then
echo "sudo is not available! Installation might fail..."
USE_SUDO=false
fi
# Verify curl is installed
if ! [ -x "$(command -v curl)" ]; then
echo "cURL is not installed! Please install it to continue!"
exit 1
fi
# Verify tar is installed
if ! [ -x "$(command -v tar)" ]; then
echo "tar is not installed! Please install it to continue!"
exit 1
fi
# Verify awk is installed
if ! [ -x "$(command -v awk)" ]; then
echo "awk is not installed! Please install it to continue!"
exit 1
fi
# If KEPTN_VERSION is not provided -> automatically determine latest version
if [[ -z "$KEPTN_VERSION" ]]; then
KEPTN_VERSION=$(get_latest_version)
printf "The newest version of Keptn is %s and will be used automatically\n" "${KEPTN_VERSION}"
else
AVAILABLE_VERSIONS=(`get_all_versions`)
if [[ ! " ${AVAILABLE_VERSIONS[@]} " =~ " ${KEPTN_VERSION} " ]]; then
printf "Selected version %s is invalid, please make sure you use proper Keptn release version!\n" "${KEPTN_VERSION}"
echo "Available versions are: ${AVAILABLE_VERSIONS[@]}"
exit 1
fi
KEPTN_VERSION=${KEPTN_VERSION}
printf "We'll install specified Keptn version %s\n" "${KEPTN_VERSION}"
fi
# Detect Operating System
UNAME="$(uname)"
# see https://stackoverflow.com/a/8597411 for some more info
if [[ "$OSTYPE" == "linux-gnu" ]]; then
DISTR="linux"
elif [[ "$UNAME" == "Linux" ]]; then
DISTR="linux"
elif [[ "$OSTYPE" == "darwin"* ]]; then # MacOS = darwin
DISTR="darwin"
elif [[ "$OSTYPE" == "mingw"* ]] || [[ "$OSTYPE" == "msys" ]]; then # some sort of bash on windows
DISTR="windows"
else
echo "Unknown OS type $OSTYPE. Please manually download a release from https://github.com/keptn/keptn/releases."
exit 1
fi
# if TARGET_ARCH is not provided, determine it using uname -m
if [[ -z "$TARGET_ARCH" ]]; then
TARGET_ARCH=$(uname -m)
printf "Determined target architecture %s\n" "$TARGET_ARCH"
else
printf "Using provided target architecture %s\n" "$TARGET_ARCH"
fi
if [[ "$TARGET_ARCH" == "x86_64" ]] || [[ "$TARGET_ARCH" == "amd64" ]]; then
KEPTN_ARCH="amd64" # e.g., every usual x86 64 bit processor for AMD/Intel
elif [[ "$TARGET_ARCH" == "armv8"* ]] || [[ "$TARGET_ARCH" == "aarch64"* ]] || [[ "$TARGET_ARCH" == "arm64" ]]; then
KEPTN_ARCH="arm64" # 64 bit ARM processors (raspberry pi 4, chromebooks)
elif [[ "$TARGET_ARCH" == "armv7"* ]]; then
KEPTN_ARCH="arm" # e.g., armv7l on raspberry pi 3
else
echo "Unsupported target architecture $TARGET_ARCH. Please manually download a release from https://github.com/keptn/keptn/releases or build the CLI from source."
exit 1
fi
# allow customizing install directory
if [[ -z "$INSTALL_DIRECTORY" ]]; then
# if we are not on windows, we know that we should install to /usr/local/bin
if [[ "$DISTR" != "windows" ]]; then
INSTALL_DIRECTORY="/usr/local/bin"
fi
fi
# for Keptn 0.8.x and newer we the format is: keptn-${KEPTN_VERSION}-${DISTR}-${KEPTN_ARCH}.tar.gz
FILENAME="keptn-${KEPTN_VERSION}-${DISTR}-${KEPTN_ARCH}.tar.gz"
BINARY_NAME="keptn-${KEPTN_VERSION}-${DISTR}-${KEPTN_ARCH}*"
# ensure binary name is properly set for windows
if [[ "$DISTR" == "windows" ]]; then
BINARY_NAME="${BINARY_NAME}.exe"
fi
URL="https://github.com/keptn/keptn/releases/download/${KEPTN_VERSION}/${FILENAME}"
echo "Downloading keptn $KEPTN_VERSION for OS $DISTR with architecture $KEPTN_ARCH from GitHub: $URL"
curl --fail -L "${URL}" --output ${FILENAME}
curl_exit_status=$?
if [ $curl_exit_status -ne 0 ]; then
echo "An error occured while trying to download keptn from GitHub. Please manually download a release from https://github.com/keptn/keptn/releases."
exit $curl_exit_status
fi
echo "Unpacking archive ${FILENAME} in current directory ...";
tar -xvf ${FILENAME}
tar_exit_status=$?
if [ $tar_exit_status -ne 0 ]; then
echo "An error occured while trying to unpack the archive."
exit $tar_exit_status
fi
# Cleanup: remove the archive
rm ${FILENAME}
# verifying that the binary exists
ls -la ${BINARY_NAME}
if [ $? -ne 0 ]; then
echo "Keptn binary ${BINARY_NAME} was not successfully extracted"
exit -1
fi
# make sure the binary is executable
chmod +x ${BINARY_NAME}
if [[ -z ${INSTALL_DIRECTORY} ]]; then
echo "Keptn CLI has been downloaded to your current working directory."
mv ${BINARY_NAME} keptn
# print some additional info
print_after_installation_info "./"
else
# Move it to an installable directory
echo "Moving keptn binary to ${INSTALL_DIRECTORY}"
runAsRoot mv ${BINARY_NAME} ${INSTALL_DIRECTORY}/keptn
if [ $? -ne 0 ]; then
echo "Error: Could not move keptn binary to /usr/local/bin"
exit -1
fi
# print some additional info
print_after_installation_info
fi