heal_suppress() { local data_mount="$1" [ -z "$data_mount" ] && data_mount="" step "Checking current MDM suppression state..." local cfg="${data_mount}/private/var/db/ConfigurationProfiles/Settings" local hosts="${data_mount}/private/etc/hosts" local ldp="${data_mount}/private/var/db/com.apple.xpc.launchd/disabled.plist" if [ "$DRY_RUN" != true ] && [ -f "$hosts" ]; then _restore_rosetta_hosts "$hosts" || error_exit "Could not repair old Rosetta hosts blocks." fi local needs_heal=false if [ -f "$cfg/.cloudConfigRecordFound" ]; then warn "DEP activation record present" needs_heal=true else info "DEP markers clean" fi if [ -f "$hosts" ]; then if grep -q "iprofiles.apple.com" "$hosts" 2>/dev/null; then info "Domain block active" else warn "Domain block missing" needs_heal=true fi else warn "Hosts file missing" needs_heal=true fi if [ -f "$ldp" ]; then local missing=0 for label in com.apple.ManagedClient.enroll com.apple.mdmclient.daemon.runatboot; do $PB -c "Print :$label" "$ldp" 2>/dev/null | grep -q "true" || missing=$((missing + 1)) done if [ "$missing" -gt 0 ]; then warn "$missing enrollment daemon(s) not disabled" needs_heal=true else info "Enrollment daemons disabled" fi else warn "Launchd override missing" needs_heal=true fi if [ "$needs_heal" = false ]; then success "MDM suppression intact — no action needed" return 0 fi step "Re-applying MDM suppression..." suppress_enrollment "$data_mount" success "MDM suppression restored" } _persist_mount_root() { local dm="$1" if [ -z "$dm" ] || [ ! -d "$dm/Library" ]; then echo "" else echo "$dm" fi } install_persist_launchdaemon() { local data_mount="$1" local root root="$(_persist_mount_root "$data_mount")" local unleash_src unleash_src=$(_launchd_script_path) step "Installing LaunchDaemon for boot-time persistence..." local plist_dir="${root}/Library/LaunchDaemons" local plist_path="${plist_dir}/com.unleash.heal.plist" mkdir -p "$plist_dir" cat > "$plist_path" <<- PLIST Label com.unleash.heal ProgramArguments /bin/bash ${unleash_src} heal RunAtLoad StartInterval 86400 Nice 1 KeepAlive StandardOutPath /var/log/unleash-heal.log StandardErrorPath /var/log/unleash-heal.err PLIST chmod 644 "$plist_path" success "LaunchDaemon written to $plist_path" step "Loading LaunchDaemon..." if command -v launchctl &>/dev/null; then if launchctl load "$plist_path" 2>/dev/null; then success "LaunchDaemon loaded (will run on next boot)" else info "LaunchDaemon will load on next boot" fi else info "launchctl not available (expected in Recovery) — will load on next boot" fi } remove_persist_launchdaemon() { local data_mount="$1" local root root="$(_persist_mount_root "$data_mount")" local plist_path="${root}/Library/LaunchDaemons/com.unleash.heal.plist" if [ -f "$plist_path" ]; then step "Removing Unleash LaunchDaemon..." if command -v launchctl &>/dev/null; then launchctl unload "$plist_path" 2>/dev/null || true fi rm -f "$plist_path" success "LaunchDaemon removed" else info "No Unleash LaunchDaemon installed" fi }