#!/bin/bash
# =============================================================
#  IT CARE — DEVICE SCAN (Mac)
#  Read-only: this script looks, it does not change anything.
#  It writes one report file to your Desktop, then stops.
#  Review the code in any text editor before running.
# =============================================================
out="$HOME/Desktop/IT-Care-Scan-$(date +%Y-%m-%d).txt"

{
echo "BY FIVE IT — DEVICE SCAN REPORT"
echo "Generated: $(date)"
echo "This report was produced by a read-only scan. Nothing on this"
echo "computer was changed, and no files or passwords are included."
echo
echo "==================== SYSTEM ===================="
sw_vers
echo
echo "Model: $(sysctl -n hw.model 2>/dev/null)"
echo

echo "==================== DISK SPACE ===================="
df -h / | awk 'NR==2 {print "Total: "$2"   Used: "$3"   Available: "$4" ("$5" used)"}'
echo

echo "==================== DISK ENCRYPTION (FileVault) ===================="
fdesetup status 2>/dev/null || echo "Unable to check — may need one confirmation click."
echo

echo "==================== BACKUP (Time Machine) ===================="
latest=$(tmutil latestbackup 2>/dev/null)
if [ -n "$latest" ]; then
  echo "Latest backup: $latest"
else
  echo "No recent Time Machine backup found."
fi
tmutil destinationinfo 2>/dev/null | sed -n '1,8p' | grep -v "tmutil:"
echo

echo "==================== SOFTWARE UPDATES ===================="
last=$(defaults read /Library/Preferences/com.apple.SoftwareUpdate LastSuccessfulDate 2>/dev/null)
if [ -n "$last" ]; then echo "Last successful update check: $last"; else echo "Last update check: unknown"; fi
echo "Recent update history:"
softwareupdate --history 2>/dev/null | tail -5
echo

echo "==================== FIREWALL ===================="
fw=$(defaults read /Library/Preferences/com.apple.alf globalstate 2>/dev/null)
if [ -z "$fw" ]; then
  fw=$(/usr/libexec/ApplicationFirewall/socketfilterfw --getglobalstate 2>/dev/null | grep -oE "(enabled|disabled)" | head -1)
  [ "$fw" = "enabled" ] && fw=2
  [ "$fw" = "disabled" ] && fw=0
fi
case "$fw" in
  0) echo "Firewall: OFF  ← worth fixing" ;;
  1) echo "Firewall: ON (for specific services)" ;;
  2) echo "Firewall: ON (block all incoming)" ;;
  *) echo "Firewall: unknown" ;;
esac
echo

echo "==================== SCREEN LOCK ===================="
pmset -g custom 2>/dev/null | grep -iE "displaysleep|sleep" | head -4
echo "(Shorter display-sleep = better automatic screen lock.)"
echo

echo "==================== LAPTOP BATTERY HEALTH ===================="
system_profiler SPPowerDataType 2>/dev/null | grep -E "Cycle Count|Condition|Charge Remaining" | head -4
echo

echo "==================== EXTERNAL / MOUNTED DRIVES ===================="
drives=$(df -h | grep "/Volumes" | grep -v "Macintosh HD")
if [ -n "$drives" ]; then echo "$drives"; else echo "None mounted."; fi
echo

echo "==================== END OF REPORT ===================="
} > "$out" 2>&1

echo ""
echo "✓ Done — report saved to: $out"
echo "  Email it to quinton@byfiveit.com (or just show it during your session)."
open "$out" 2>/dev/null
