Add cleanup for temporary directory

Previously the temporary directory was removed via the RETURN trap
but this could be bypassed if the script exited early. Now we
explicitly clean up the directory in all exit paths.
This commit is contained in:
Damien
2026-05-26 17:42:24 +02:00
parent c7f44aa293
commit a6a3b421c5

View File

@@ -119,12 +119,12 @@ install_or_upgrade_bao() {
log_info "Downloading OpenBao ${tag} (${arch}) from ${url}..."
tmpdir=$(mktemp -d)
trap 'rm -rf "$tmpdir"' RETURN
curl -fsSL "$url" -o "${tmpdir}/bao.tar.gz"
tar -xzf "${tmpdir}/bao.tar.gz" -C "$tmpdir"
if [[ ! -f "${tmpdir}/bao" ]]; then
log_error "Archive did not contain expected 'bao' binary."
rm -rf "$tmpdir"
exit 1
fi
@@ -149,6 +149,8 @@ install_or_upgrade_bao() {
log_info "Restarting openbao service..."
rc-service openbao start
fi
rm -rf "$tmpdir"
}
# ============================================================