* Fixed chattr command to set immutability instead of removing it
* Refactored EFI var detection
* Added comments
This commit is contained in:
2Shirt 2018-05-12 14:53:36 -06:00
parent dc7c9ec3e6
commit cf565451ef

View file

@ -16,34 +16,36 @@ BLUE='\033[34m'
echo '## Mac dGPU Disable Tool ##' echo '## Mac dGPU Disable Tool ##'
echo '' echo ''
for f in /sys/firmware/efi/efivars/gfx*; do # Check for current variables
if [[ -e "$f" ]]; then for prefix in gfx gpu; do
echo -e "${YELLOE}Detected:${CLEAR} $f" for var in /sys/firmware/efi/efivars/${prefix}*; do
needs_nvram_reset="yes" # The test below is to avoid empty or nonexistent paths
fi if [[ -e "${var}" ]]; then
done echo -e "${YELLOW}Detected:${CLEAR} $f"
needs_nvram_reset="yes"
for f in /sys/firmware/efi/efivars/gpu*; do fi
if [[ -e "$f" ]]; then done
echo -e "${YELLOE}Detected:${CLEAR} $f"
needs_nvram_reset="yes"
fi
done done
echo "" echo ""
if [[ ! -e "/sys/firmware/efi/efivars" ]]; then if [[ ! -e "/sys/firmware/efi/efivars" ]]; then
# Probably booted legacy
echo -e "${RED}ERROR:${CLEAR} EFIVARS not found" echo -e "${RED}ERROR:${CLEAR} EFIVARS not found"
elif cmp "$SOURCE" "$DEST" >/dev/null 2>&1; then elif cmp "$SOURCE" "$DEST" >/dev/null 2>&1; then
echo -e "${YELLOW}Discrete GPU already disabled${CLEAR}" # EFI var matches desired state
echo -e "${ORANGE}Discrete GPU already disabled${CLEAR}"
elif [[ "$needs_nvram_reset" == "yes" ]]; then 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 "${RED}ERROR:${CLEAR} Detected the above EFIVARS"
echo -e "Please reboot and reset the NVRAM" echo -e "Please reboot and reset the NVRAM"
else else
# No gfx/gpu EFI vars detected so we can apply the fix
cp "$SOURCE" "$DEST" cp "$SOURCE" "$DEST"
chattr -i "$DEST" chattr +i "$DEST"
umount /sys/firmware/efi/efivars umount /sys/firmware/efi/efivars
sync sync
echo -e "${GREEN}Discrete GPU successfully disabled${CLEAR}" echo -e "${GREEN}Discrete GPU successfully disabled${CLEAR}"
mount -t efivarfs efivarfs /sys/firmware/efi/efivars
fi fi
echo "" echo ""
read -p "Press Enter to poweroff the system... " -r unusedvar read -p "Press Enter to poweroff the system... " -r unusedvar