#!/bin/bash # Run through MDM as root with the affected user signed in. set -u APP="/Applications/Silmaril.app" UNINSTALLER="$APP/Contents/Helpers/SilmarilUninstaller" if [[ "$(/usr/bin/id -u)" -ne 0 ]]; then echo "Run the Silmaril uninstall script as root through MDM." >&2 exit 77 fi console_uid="$(/usr/bin/stat -f %u /dev/console)" || exit 69 case "$console_uid" in ''|*[!0-9]*) echo "Cannot identify the signed-in user. No removal was attempted." >&2 exit 69 ;; esac if [[ "$console_uid" -le 500 ]]; then echo "The affected user must be signed in. No removal was attempted." >&2 exit 69 fi if [[ ! -x "$UNINSTALLER" ]]; then echo "The bundled Silmaril uninstaller is unavailable. Review the installed app and any previous uninstall receipt." >&2 exit 69 fi if "$UNINSTALLER" --managed --user "$console_uid" --json; then result=0 else result=$? fi case "$result" in 0) echo "Silmaril removal completed." >&2 ;; 2) echo "Silmaril reported remaining items (exit 2). Review the JSON receipt for the affected components and required actions." >&2 ;; *) echo "Silmaril removal did not complete (exit $result). Review the uninstaller output before retrying." >&2 ;; esac exit "$result"