Secure OCaml removal sudo boundary

This commit is contained in:
Erik Melton committed 2026-09-04 20:18:48 +02:00
1 parent 493067741e
commit 1b7301916b
2 files changed
+286 -1

No files matched your search

+35 -1
View File
@@ -9,6 +9,35 @@ if [[ -z $1 ]]; then
exit 1
fi
cleanup_ocaml_sudo_credentials() {
local status=$?
trap - EXIT HUP INT TERM
if ! /usr/bin/sudo -k >/dev/null 2>&1; then
echo "Failed to invalidate sudo credentials after OCaml removal." >&2
(( status != 0 )) || status=1
fi
exit "$status"
}
begin_ocaml_sudo_boundary() {
trap cleanup_ocaml_sudo_credentials EXIT
trap 'exit 129' HUP
trap 'exit 130' INT
trap 'exit 143' TERM
/usr/bin/sudo -k >/dev/null || {
echo "Unable to start OCaml removal with a cold sudo credential state." >&2
exit 1
}
if ! /usr/bin/sudo -N -V >/dev/null 2>&1; then
echo "This sudo does not support --no-update; refusing to remove OCaml." >&2
exit 1
fi
}
remove_php() {
omarchy-pkg-drop php composer php-sqlite xdebug
}
@@ -87,10 +116,15 @@ dotnet)
mise rm -g dotnet
;;
ocaml)
begin_ocaml_sudo_boundary
echo -e "Removing OCaml...\n"
opam switch remove default -y 2>/dev/null || true
rm -rf ~/.opam 2>/dev/null || true
sudo rm -f /usr/local/bin/opam 2>/dev/null || true
if ! /usr/bin/sudo -N -- /usr/bin/rm -f /usr/local/bin/opam; then
echo "Failed to remove the system opam launcher." >&2
exit 1
fi
;;
clojure)
echo -e "Removing Clojure...\n"