# Detect T2 MacBook models using PCI IDs
# Vendor: 106b (Apple), Device IDs: 1801 or 1802 (T2 Security Chip)
if lspci -nn | grep -q "106b:180[12]"; then
  echo "Detected MacBook with T2 chip. Installing support items..."

  sudo pacman -S --noconfirm --needed \
    linux-t2 \
    linux-t2-headers \
    apple-t2-audio-config \
    apple-bcm-firmware \
    t2fanrd \
    tiny-dfr

  echo "apple-bce" | sudo tee /etc/modules-load.d/t2.conf >/dev/null

  echo "MODULES+=(apple-bce usbhid hid_apple hid_generic xhci_pci xhci_hcd)" | sudo tee /etc/mkinitcpio.conf.d/apple-t2.conf >/dev/null

  cat <<EOF | sudo tee /etc/modprobe.d/brcmfmac.conf >/dev/null
# Fix for T2 MacBook WiFi connectivity issues
options brcmfmac feature_disable=0x82000
EOF

  sudo mkdir -p /etc/limine-entry-tool.d
  cat <<EOF | sudo tee /etc/limine-entry-tool.d/t2-mac.conf >/dev/null
# Generated by Omarchy installer for T2 Mac support
KERNEL_CMDLINE[default]+="intel_iommu=on iommu=pt pcie_ports=compat"
EOF
fi
