-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh.in
323 lines (248 loc) · 8.89 KB
/
install.sh.in
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
#!/bin/sh
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you 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.
#
troubleshooting_url="https://skupper.io/install/troubleshooting.html"
@burly@
# func <version> <output-dir> -> release_version=<version>, release_file=<file>
fetch_skupper_release() {
local version="$1"
local output_dir="$2"
assert test -d "${output_dir}"
assert program_is_available awk
assert program_is_available curl
assert program_is_available uname
log "Determining your OS an architecture"
case $(uname -s) in
# CYGWIN*) local operating_system=windows ;;
Darwin) local operating_system=mac ;;
Linux) local operating_system=linux ;;
*) fail "Unknown operating system: $(uname -s)" ;;
esac
case $(uname -m) in
aarch64) local architecture=arm64 ;;
arm64) local architecture=arm64 ;;
armv7l) local architecture=arm32 ;;
i386) local architecture=i386 ;;
i686) local architecture=i386 ;;
x86_64) local architecture=amd64 ;;
*) fail "Unknown architecture: $(uname -m)" ;;
esac
log "Operating system: ${operating_system}"
log "Architecture: ${architecture}"
local release_version_file="${output_dir}/release-version.txt"
case "${version}" in
latest)
log "Looking up the latest release version"
run curl -sf "https://skupper.io/data/install.json" \
| awk 'match($0, /"version": "[0-9]+\.[0-9]+\.[0-9]+"/) { print substr($0, RSTART+12, RLENGTH-13) }' \
>| "${release_version_file}"
;;
main)
echo "main-release" >| "${release_version_file}"
;;
*)
echo "${version}" >| "${release_version_file}"
;;
esac
release_version="$(cat "${release_version_file}")"
log "Release version: ${release_version}"
log "Release version file: ${release_version_file}"
local release_file_name="skupper-cli-${release_version}-${operating_system}-${architecture}.tgz"
# release_file is "returned"
release_file="${output_dir}/${release_file_name}"
assert test -n "${release_file}"
assert test -n "${release_file_name}"
assert test -n "${release_version}"
if [ ! -e "${release_file}" ] || [ "${release_version}" = "main-release" ]
then
log "Downloading the ${release_version} release"
local release_url="https://github.com/skupperproject/skupper/releases/download/${release_version}/${release_file_name}"
if ! run curl -sfL --show-error -o "${release_file}" "${release_url}"
then
fail "No release found at ${release_url}"
fi
else
log "Using the cached release archive"
fi
log "Archive file: ${release_file}"
# release_version is "returned"
release_version="$(cat "${release_version_file}")"
assert test -n "${release_version}"
assert test -f "${release_file}"
}
usage() {
local error="${1:-}"
if [ -n "${error}" ]
then
printf "%b %s\n\n" "$(red "ERROR:")" "${*}"
fi
cat <<EOF
Usage: install.sh [OPTION...]
Install the Skupper command-line tool
Options:
-h, --help Print this help text and exit
--version VERSION Select the version (default "latest")
--scheme SCHEME Select an installation scheme (default "home")
--interactive Operate in interactive mode
--verbose Print detailed logging to the console
Versions:
latest The latest release
main The latest CI/CD release from main
X.Y.Z A specific version
Schemes:
home Install to ~/.local/bin
opt Install to /opt/skupper/bin
EOF
if [ -n "${error}" ]
then
exit 1
fi
exit 0
}
require_option_arg() {
local opt="$1"
local optarg="$2"
if [ -z "${optarg}" ]
then
usage "Option ${opt} is missing a required argument"
fi
case "${optarg}" in
-*) usage "Option ${opt} is missing a required argument" ;;
*) : ;;
esac
}
main() {
enable_strict_mode
if [ -n "${DEBUG:-}" ]
then
enable_debug_mode
fi
local version=latest
local scheme=home
local interactive=
local verbose=
while [ $# -gt 0 ]
do
case "$1" in
-h|--help) usage ;;
--version)
require_option_arg "$1" "${2:-}"
version="$2"
shift
;;
--scheme)
require_option_arg "$1" "${2:-}"
scheme="$2"
shift
;;
--interactive) interactive=1 ;;
--verbose) verbose=1 ;;
*) usage "Unknown option: ${1}" ;;
esac
shift
done
case "${scheme}" in
home) local skupper_bin_dir="${TEST_INSTALL_PREFIX:-}${HOME}/.local/bin" ;;
opt) local skupper_bin_dir="${TEST_INSTALL_PREFIX:-}/opt/skupper/bin" ;;
*) usage "Unknown installation scheme: ${scheme}" ;;
esac
local work_dir="${TEST_INSTALL_PREFIX:-}${HOME}/.cache/skupper-install-script"
local log_file="${work_dir}/install.log"
local backup_dir="${work_dir}/backup"
mkdir -p "${work_dir}"
cd "${work_dir}"
init_logging "${log_file}" "${verbose}"
{
if [ -n "${interactive}" ]
then
print_section "Preparing to install"
print "This script will install the Skupper command to:"
print
print " ${skupper_bin_dir}/skupper"
print
print "It will save a backup of any existing installation to:"
print
print " ${backup_dir}"
print
print "Run \"install.sh -h\" to see the installation options."
print
ask_to_proceed
print
fi
print_section "Checking prerequisites"
check_writable_directories "${skupper_bin_dir}"
check_required_programs awk curl gzip tar
check_required_network_resources "https://github.com/" "https://skupper.io/"
print_result "OK"
print_section "Downloading the release"
fetch_skupper_release "${version}" "${work_dir}"
print_result "OK"
if [ -e "${skupper_bin_dir}/skupper" ]
then
print_section "Saving the existing installation to a backup"
if [ -e "${backup_dir}" ]
then
mv "${backup_dir}" "${backup_dir}.$(date +%Y-%m-%d).$(random_number)"
fi
run mkdir -p "${backup_dir}"
run mv "${skupper_bin_dir}/skupper" "${backup_dir}"
print_result "OK"
fi
print_section "Installing the Skupper command"
log "Extracting the command from the release archive"
extract_archive "${release_file}" "${work_dir}"
assert test -x skupper
log "Moving the command to its install location"
run mkdir -p "${skupper_bin_dir}"
run mv skupper "${skupper_bin_dir}"
print_result "OK"
print_section "Testing the installation"
log "Testing the Skupper command"
run "${skupper_bin_dir}/skupper" --help > /dev/null
print_result "OK"
print_section "Summary"
print_result "SUCCESS"
print "The Skupper command is now installed."
print
print " Version: ${release_version}"
print " Path: ${skupper_bin_dir}/skupper"
print
if [ "$(command -v skupper)" != "${skupper_bin_dir}/skupper" ]
then
print "$(yellow "NOTE:") The Skupper command is not on your path. To add it, use:"
print
if [ "${scheme}" = "home" ]
then
print " export PATH=\"\$HOME/.local/bin:\$PATH\""
else
print " export PATH=\"${skupper_bin_dir}:\$PATH\""
fi
print
fi
print "If you are trying Skupper for the first time, see the getting started guide:"
print
print " https://skupper.io/start/"
print
print "To uninstall Skupper, use:"
print
print " curl https://skupper.io/uninstall.sh | sh"
print
} >&6 2>&6
}
main "$@"