#!/bin/bash # Spareboot Mac checkup. Read only. # Read this before you run it: https://spareboot.com/mac/check # It prints a short block you can paste into that page. # Reads: model id, macOS version, memory, CPU brand, free space on /, # battery cycle count and condition, and the pending softwareupdate list. # It does not print a serial number. It does not ask for an administrator password. It does not write a file. macos=$(sw_vers -productVersion 2>/dev/null || true) model=$(sysctl -n hw.model 2>/dev/null || true) bytes=$(sysctl -n hw.memsize 2>/dev/null || echo 0) case "$bytes" in ""|*[!0-9]*) bytes=0 ;; esac ram_gb=$((bytes / 1024 / 1024 / 1024)) brand=$(sysctl -n machdep.cpu.brand_string 2>/dev/null || true) arm=$(sysctl -n hw.optional.arm64 2>/dev/null || echo 0) chip=intel if [ "$arm" = "1" ]; then chip=apple fi case "$brand" in *[Aa]pple*) chip=apple ;; esac disk=$(df -g / 2>/dev/null | awk 'NR==2 { print $4 }') cycles=none battery=none if ioreg -rn AppleSmartBattery >/dev/null 2>&1; then raw=$(ioreg -rn AppleSmartBattery 2>/dev/null || true) cycles=$(printf '%s\n' "$raw" | awk -F'= ' '/"CycleCount"/ { gsub(/[^0-9]/, "", $2); print $2; exit }') battery=$(printf '%s\n' "$raw" | awk -F'= ' '/"BatteryHealthCondition"|"BatteryHealth"/ { gsub(/"/, "", $2); gsub(/^[ \t]+|[ \t]+$/, "", $2); if ($2 != "") { print $2; exit } }') if [ -z "$cycles" ]; then cycles=none; fi if [ -z "$battery" ]; then battery=none; fi fi updates=unknown upd=$(softwareupdate -l 2>&1 || true) if printf '%s\n' "$upd" | grep -q 'No new software available'; then updates=0 elif printf '%s\n' "$upd" | grep -q '^\*'; then updates=$(printf '%s\n' "$upd" | grep -c '^\*' || true) fi printf '%s\n' "Spareboot read this Mac. Paste the block below into the checkup page. Nothing was changed." printf '%s\n' "SPAREBOOT-MAC 1" printf '%s\n' "macos=${macos}" printf '%s\n' "model=${model}" printf '%s\n' "chip=${chip}" printf '%s\n' "ram_gb=${ram_gb}" printf '%s\n' "disk_free_gb=${disk}" printf '%s\n' "battery_cycles=${cycles}" printf '%s\n' "battery=${battery}" printf '%s\n' "updates=${updates}" printf '%s\n' "END"