diff --git a/build-iso b/build-iso new file mode 100644 index 0000000..90d3c77 --- /dev/null +++ b/build-iso @@ -0,0 +1,43 @@ +#!/bin/bash +# + +# Prep build env +rsync -ahvPS /usr/share/archiso/configs/releng/ temp/ +echo 'bc' > temp/packages.both +rm temp/airootfs/etc/systemd/scripts/choose-mirror +rm temp/airootfs/etc/systemd/system/choose-mirror.service +rm temp/airootfs/etc/systemd/system/etc-pacman.d-gnupg.mount +rm temp/airootfs/etc/systemd/system/pacman-init.service +rm temp/airootfs/etc/udev/rules.d/81-dhcpcd.rules +rmdir --ignore-fail-on-non-empty temp/airootfs/etc/udev/rules.d +rmdir --ignore-fail-on-non-empty temp/airootfs/etc/udev +cp mac-dgpu-disable-tool temp/airootfs/root/ +printf "\x07\x00\x00\x00\x01\x00\x00\x00" \ + > temp/airootfs/root/gpu-power-prefs-fa4ce28d-b62f-4c99-9cc3-6815686e30f9 +chown -R root:root temp + +# Adjust boot menus +sed -i 's/timeout 3/timeout 1/' temp/efiboot/loader/loader.conf +sed -i 's/Arch Linux archiso x86_64/Mac dGPU Disable Tool/' temp/efiboot/loader/entries/* + +sed -i '/BACKGROUND/d' temp/syslinux/* +echo 'PROMPT 1' >> temp/syslinux/archiso_head.cfg +echo 'TIMEOUT 1' >> temp/syslinux/archiso_head.cfg +echo 'DEFAULT arch64' >> temp/syslinux/archiso_head.cfg +sed -i -r 's/Arch Linux( \(x86_64\)|)( live medium|)/Mac dGPU Disable Tool/' temp/syslinux/* +sed -i '/allows/d' temp/syslinux/* + +# Add nomodeset boot option +sed -i -r 's/^(options.*)$/\1 nomodeset/' temp/efiboot/loader/entries/archiso* +sed -i -r 's/^(APPEND arch.*)$/\1 nomodeset/' temp/syslinux/*cfg + +# Modify live env +echo '' >> temp/airootfs/etc/motd +sed -i '/mirror/d' temp/airootfs/root/customize_airootfs.sh +sed -i '/usermod/d' temp/airootfs/root/customize_airootfs.sh +sed -i '/ssh/d' temp/airootfs/root/customize_airootfs.sh +echo 'echo "~/mac-dgpu-disable-tool" >> /root/.bashrc' \ + >> temp/airootfs/root/customize_airootfs.sh + +temp/build.sh -N dgpu -L DGPU -v + diff --git a/mac-dgpu-disable-tool b/mac-dgpu-disable-tool new file mode 100644 index 0000000..2fbc94a --- /dev/null +++ b/mac-dgpu-disable-tool @@ -0,0 +1,50 @@ +#!/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' + +echo '## Mac dGPU Disable Tool ##' +echo '' + +for f in /sys/firmware/efi/efivars/gfx*; do + if [[ -e "$f" ]]; then + echo -e "${YELLOE}Detected:${CLEAR} $f" + needs_nvram_reset="yes" + fi +done + +for f in /sys/firmware/efi/efivars/gpu*; do + if [[ -e "$f" ]]; then + echo -e "${YELLOE}Detected:${CLEAR} $f" + needs_nvram_reset="yes" + fi +done + +echo "" +if [[ ! -e "/sys/firmware/efi/efivars" ]]; then + echo -e "${RED}ERROR:${CLEAR} EFIVARS not found" +elif cmp "$SOURCE" "$DEST" >/dev/null 2>&1; then + echo -e "${YELLOW}Discrete GPU already disabled${CLEAR}" +elif [[ "$needs_nvram_reset" == "yes" ]]; then + echo -e "${RED}ERROR:${CLEAR} Detected the above EFIVARS" + echo -e "Please reboot and reset the NVRAM" +else + cp "$SOURCE" "$DEST" + chattr -i "$DEST" + umount /sys/firmware/efi/efivars + sync + echo -e "${GREEN}Discrete GPU successfully disabled${CLEAR}" +fi +echo "" +read -p "Press Enter to poweroff the system... " -r unusedvar +poweroff