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