summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrei Vagin <avagin@google.com>2020-04-09 01:11:20 -0700
committergVisor bot <gvisor-bot@google.com>2020-04-09 01:12:27 -0700
commit1ebfdcc86c1b066a044a64e1f34b679f327a1f36 (patch)
treec0a0597067c6ddc3950e1ef715eda7f8c03dce2d
parent21e438d257861eadc1dafcee914e4a51cffd3852 (diff)
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
-rwxr-xr-xscripts/common.sh22
1 files changed, 15 insertions, 7 deletions
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
}