From 1ebfdcc86c1b066a044a64e1f34b679f327a1f36 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Thu, 9 Apr 2020 01:11:20 -0700 Subject: kokoro: fix handling of apt-get errors When a command is called as if expression, its error code can be get only in this if block. For example, the next script prints 0: if ( false ); then true fi echo $? PiperOrigin-RevId: 305638629 --- scripts/common.sh | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'scripts/common.sh') diff --git a/scripts/common.sh b/scripts/common.sh index 735a383de..bc6ba71e8 100755 --- a/scripts/common.sh +++ b/scripts/common.sh @@ -89,12 +89,20 @@ function install_runsc() { # be correct, otherwise this may result in a loop that spins until time out. function apt_install() { while true; do - if (sudo apt-get update && sudo apt-get install -y "$@"); then - break - fi - result=$? - if [[ $result -ne 100 ]]; then - return $result - fi + sudo apt-get update && + sudo apt-get install -y "$@" && + true + result="${?}" + case $result in + 0) + break + ;; + 100) + # 100 is the error code that apt-get returns. + ;; + *) + exit $result + ;; + esac done } -- cgit v1.2.3