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
This commit is contained in:
Andrei Vagin
2020-04-09 01:12:27 -07:00
committed by gVisor bot
parent 21e438d257
commit 1ebfdcc86c
+15 -7
View File
@@ -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
}