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