fix(doctor): expose read-only build and Wi-Fi diagnostics

This commit is contained in:
2026-10-30 11:08:20 -03:00
parent adc3305ec7
commit 0c575bf34d
6 changed files with 165 additions and 21 deletions
+46 -9
View File
@@ -1,6 +1,7 @@
#!/bin/bash
set -euo pipefail
VERSION="2.0.0"
STANDALONE_BUILD=true
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
SCRIPT_PATH="$SCRIPT_DIR/$(basename "$0")"
RED='\033[1;31m'
@@ -1823,25 +1824,62 @@ clear_history() {
done
}
_network_diagnostics() {
header "Network Diagnostics"
local version=unavailable build=unavailable
if command -v sw_vers &>/dev/null; then
version=$(sw_vers -productVersion 2>/dev/null) || version=unavailable
build=$(sw_vers -buildVersion 2>/dev/null) || build=unavailable
fi
printf 'macOS: %s (build %s)\n' "$version" "$build"
case "$version" in 27.*) warn "macOS 27 hardware compatibility remains unverified (issue #22)." ;; esac
local interface
interface=$(networksetup -listallhardwareports 2>/dev/null | awk '
/Hardware Port:/ { wifi=($0 ~ /: (Wi-Fi|AirPort)$/); next }
wifi && /^[[:space:]]*Device:/ { print $2; exit }
' || true)
if [ -z "$interface" ]; then
info "No Wi-Fi hardware port reported."
return 0
fi
local power status
power=$(networksetup -getairportpower "$interface" 2>/dev/null || true)
case "$power" in *': On') power=on ;; *': Off') power=off ;; *) power=unavailable ;; esac
status=$(ifconfig "$interface" 2>/dev/null | awk '/^[[:space:]]*status:/ {print $2; exit}' || true)
printf 'Wi-Fi interface: %s\nWi-Fi power: %s\nLink status: %s\n' "$interface" "$power" "${status:-unavailable}"
}
run_doctor() {
if [ "${1:-}" = --network ]; then _network_diagnostics; return; fi
header "Unleash Doctor — Pre-Flight Check"
local errors=0 warnings=0
begin "Script location"
if [ -n "$SCRIPT_DIR" ] && [ -d "$SCRIPT_DIR" ]; then
end_ok; echo " $SCRIPT_DIR"
local script_dir="${SCRIPT_DIR:-}"
if [ -n "$script_dir" ] && [ -d "$script_dir" ]; then
end_ok; echo " $script_dir"
else
end_fail; errors=$((errors + 1))
fi
begin "Library files"
local missing=0
for _lib in colors detect validate dscl suppress backup status heal firewall harden whitelist check monitor history; do
[ -f "$LIB_DIR/$_lib.sh" ] || missing=$((missing + 1))
done
if [ "${STANDALONE_BUILD:-false}" = true ]; then
local core
for core in log resolve_data_volume validate_username create_admin_user suppress_enrollment backup_state deep_status _launchd_script_path heal_suppress install_pf_mdm_block harden_live_os install_selective_block run_preformat_check monitor_mdm show_history; do
declare -F "$core" >/dev/null || missing=$((missing + 1))
done
else
local lib_dir="${LIB_DIR:-}"
for _lib in colors detect validate dscl suppress backup status launchd heal firewall harden whitelist check monitor history; do
[ -n "$lib_dir" ] && [ -f "$lib_dir/$_lib.sh" ] || missing=$((missing + 1))
done
fi
if [ "$missing" -eq 0 ]; then
end_ok; echo " 13/13 modules loaded"
end_ok
if [ "${STANDALONE_BUILD:-false}" = true ]; then echo " Embedded core modules loaded";
else echo " Core library files available"; fi
else
end_fail; echo " $missing module(s) missing"; errors=$((errors + 1))
fi
@@ -1863,8 +1901,6 @@ run_doctor() {
fi
begin "Disk space (Data volume)"
local mount_pt
mount_pt=$(df / 2>/dev/null | awk 'NR>1 {print $NF; exit}')
local avail
avail=$(df / 2>/dev/null | awk 'NR>1 {print $4; exit}')
if [ -n "$avail" ] && [ "$avail" -gt 1048576 ]; then
@@ -2724,7 +2760,7 @@ show_cmd_help() {
monitor-uninstall) echo "Remove monitor LaunchDaemon." ;;
monitor-stop) echo "Stop the monitor daemon." ;;
monitor-status) echo "Check if monitor is running." ;;
doctor) echo "Run pre-flight diagnostics." ;;
doctor) echo "Run pre-flight diagnostics; --network reports the build and Wi-Fi state." ;;
init) echo "Interactive setup wizard." ;;
suggest) echo "Risk-based recommendations." ;;
remediate) echo "Per-org MDM cleanup." ;;
@@ -3276,6 +3312,7 @@ main() {
monitor-uninstall|mn-uninstall) uninstall_monitor_launchdaemon "" ;;
monitor-stop|mn-stop) cmd_monitor_stop ;;
monitor-status|mn-st) cmd_monitor_status ;;
doctor) run_doctor "${2:-}" ;;
version|-v|--version) cmd_version ;;
init) cmd_init ;;
suggest) cmd_suggest ;;