#!/bin/bash # SOURCE=/root/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9 DEST=/sys/firmware/efi/efivars/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9 needs_nvram_reset="no" # Colors CLEAR='\033[0m' RED='\033[31m' GREEN='\033[32m' YELLOW='\033[33m' ORANGE='\033[31;1m' BLUE='\033[34m' # Functions function beep () { echo -ne '\007' } function beeps_bad () { # SOS-like? beep sleep 0.25s beep sleep 0.25s beep sleep 0.5s beep sleep 0.5s beep sleep 0.5s beep sleep 0.5s beep sleep 0.25s beep sleep 0.25s beep } function beeps_good () { # Two quick beeps beep sleep 0.25s beep } echo '## Mac dGPU Disable Tool ##' echo '' # Check for current variables for prefix in gfx gpu; do for var in /sys/firmware/efi/efivars/${prefix}*; do # The test below is to avoid empty or nonexistent paths if [[ -e "${var}" ]]; then echo -e "${YELLOW}Detected:${CLEAR} $var" needs_nvram_reset="yes" fi done done echo "" if [[ ! -e "/sys/firmware/efi/efivars" ]]; then # Probably booted legacy echo -e "${RED}ERROR:${CLEAR} EFIVARS not found" beeps_bad elif cmp "$SOURCE" "$DEST" >/dev/null 2>&1; then # EFI var matches desired state echo -e "${GREEN}Discrete GPU already disabled${CLEAR}" beeps_good elif [[ "$needs_nvram_reset" == "yes" ]]; then # One or more gfx/gpu EFI vars detected echo -e "${RED}ERROR:${CLEAR} Detected the above EFIVARS" echo -e "Please reboot and reset the NVRAM" beeps_bad else # No gfx/gpu EFI vars detected so we can apply the fix cp "$SOURCE" "$DEST" chattr +i "$DEST" umount /sys/firmware/efi/efivars sync echo -e "${GREEN}Discrete GPU successfully disabled${CLEAR}" mount -t efivarfs efivarfs /sys/firmware/efi/efivars beeps_good fi echo "" read -p "Press Enter to poweroff the system... " -r unusedvar poweroff