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:
@@ -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"
|
||||
}
|
||||
|
||||
# ============================================================
|
||||
|
||||
Reference in New Issue
Block a user