enos(cloud-init): fix synchronize-repos (#30013)

`$?` in bash is wonky. When you evaluate an expression in an `if`
statement the `$?` variable is only set the actual value in blocks
scoped in the statement. Therefore, since we rely on it in
synchronize-repos we have to evaluate the rest of the function in a
scope of that statement.

Signed-off-by: Ryan Cragun <me@ryan.ec>
This commit is contained in:
Ryan Cragun 2025-03-24 16:02:24 -06:00 committed by GitHub
parent 8d0743c16d
commit 77e48e837e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -107,30 +107,31 @@ synchronize_repos() {
wait_for_cloud_init() {
if output=$(sudo cloud-init status --wait); then
return 0
else
res=$?
case $res in
2)
{
echo "WARNING: cloud-init did not complete successfully but recovered."
echo "Exit code: $res"
echo "Output: $output"
echo "Here are the logs for the failure:"
cat /var/log/cloud-init-*
} 1>&2
return 0
;;
*)
{
echo "cloud-init did not complete successfully."
echo "Exit code: $res"
echo "Output: $output"
echo "Here are the logs for the failure:"
cat /var/log/cloud-init-*
} 1>&2
return 1
;;
esac
fi
res=$?
case $res in
2)
{
echo "WARNING: cloud-init did not complete successfully but recovered."
echo "Exit code: $res"
echo "Output: $output"
echo "Here are the logs for the failure:"
cat /var/log/cloud-init-*
} 1>&2
return 0
;;
*)
{
echo "cloud-init did not complete successfully."
echo "Exit code: $res"
echo "Output: $output"
echo "Here are the logs for the failure:"
cat /var/log/cloud-init-*
} 1>&2
return 1
;;
esac
}
# Wait for cloud-init if it exists