Merge pull request #3991 from gkurz/fix-kata-deploy-binaries-sh

tools/packaging: Fix error path in `kata-deploy-binaries.sh -s`
This commit is contained in:
snir911 2022-03-30 11:51:43 +03:00 committed by GitHub
commit f1a88371c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@
set -o errexit
set -o nounset
set -o pipefail
set -o errtrace
readonly project="kata-containers"
@ -64,6 +65,7 @@ version: The kata version that will be use to create the tarball
options:
-h|--help : Show this help
-s : Silent mode (produce output in case of failure only)
--build=<asset> :
all
cloud-hypervisor
@ -195,6 +197,18 @@ handle_build() {
tar tvf "${tarball_name}"
}
silent_mode_error_trap() {
local stdout="$1"
local stderr="$2"
local t="$3"
local log_file="$4"
exec 1>&${stdout}
exec 2>&${stderr}
error "Failed to build: $t, logs:"
cat "${log_file}"
exit 1
}
main() {
local build_targets
local silent
@ -247,11 +261,15 @@ main() {
(
cd "${builddir}"
if [ "${silent}" == true ]; then
if ! handle_build "${t}" &>"$log_file"; then
error "Failed to build: $t, logs:"
cat "${log_file}"
exit 1
fi
local stdout
local stderr
# Save stdout and stderr, to be restored
# by silent_mode_error_trap() in case of
# build failure.
exec {stdout}>&1
exec {stderr}>&2
trap "silent_mode_error_trap $stdout $stderr $t \"$log_file\"" ERR
handle_build "${t}" &>"$log_file"
else
handle_build "${t}"
fi