-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
04ca130
commit f49abe5
Showing
1 changed file
with
46 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,9 +3,7 @@ | |
# purge-nvda.sh | ||
# Author(s): Mayank Kumar (mayankk2308, github.com / mac_editor, egpu.io) | ||
# License: Specified in LICENSE.md. | ||
# Version: 3.0.3 | ||
|
||
# Re-written for scalability and better user interaction. | ||
# Version: 3.0.4 | ||
|
||
# ----- COMMAND LINE ARGS | ||
|
||
|
@@ -28,7 +26,7 @@ BIN_CALL=0 | |
SCRIPT_FILE="" | ||
|
||
# Script version | ||
SCRIPT_MAJOR_VER="3" && SCRIPT_MINOR_VER="0" && SCRIPT_PATCH_VER="3" | ||
SCRIPT_MAJOR_VER="3" && SCRIPT_MINOR_VER="0" && SCRIPT_PATCH_VER="4" | ||
SCRIPT_VER="${SCRIPT_MAJOR_VER}.${SCRIPT_MINOR_VER}.${SCRIPT_PATCH_VER}" | ||
|
||
# User input | ||
|
@@ -58,11 +56,13 @@ NVDA_STARTUP_WEB_PLIST="${TP_EXT}NVDAStartupWeb.kext${PLIST_FILE}" | |
NV_GUID="FA4CE28D-B62F-4C99-9CC3-6815686E30F9" | ||
IG_POWER_PREF="%01%00%00%00" | ||
DG_POWER_PREF="%00%00%00%00" | ||
PN_STATE="purge-nvda-last-gfx-config" | ||
|
||
# Patch status | ||
AMD_PATCH_STATUS=0 | ||
NVDA_OPT_PATCH_STATUS=0 | ||
NVDA_SUP_PATCH_STATUS=0 | ||
PN_LAST_GFX_CONFIG=1 | ||
PLIST_PATCHED=0 | ||
|
||
# PlistBuddy Configuration | ||
|
@@ -151,18 +151,23 @@ check_macos_version() { | |
# Check patch status | ||
check_patch() { | ||
BOOT_ARGS_DATA="$(nvram boot-args 2>/dev/null)" | ||
PN_LAST_CONFIG_DATA="$(nvram "${PN_STATE}" 2>/dev/null)" | ||
[[ "${BOOT_ARGS_DATA}" =~ "nv_disable=1" ]] && AMD_PATCH_STATUS=1 | ||
[[ "${BOOT_ARGS_DATA}" =~ "agc=-1" ]] && NVDA_SUP_PATCH_STATUS=1 | ||
[[ -f "${NVDA_STARTUP_WEB_PLIST}" && "$($PlistBuddy -c "Print ${NV_DRV_KEY}" "${NVDA_STARTUP_WEB_PLIST}" 2>/dev/null)" == "${MODERN_NV_GPU_DEVICE_IDS}" ]] && NVDA_OPT_PATCH_STATUS=1 | ||
[[ "${PN_LAST_CONFIG_DATA}" =~ "${IG_POWER_PREF}" ]] && PN_LAST_GFX_CONFIG=0 | ||
} | ||
|
||
# Print patch status | ||
check_system_status() { | ||
FIX_STATES=("Disabled" "Enabled") | ||
GFX_STATES=("Integrated" "Discrete") | ||
echo -e "\n>> ${BOLD}System Status${NORMAL}\n" | ||
echo -e "${BOLD}AMD Fix${NORMAL}: ${FIX_STATES[$AMD_PATCH_STATUS]}" | ||
echo -e "${BOLD}NVDA eGPU Optimization${NORMAL}: ${FIX_STATES[$NVDA_OPT_PATCH_STATUS]}" | ||
echo -e "${BOLD}NVDA Suppression${NORMAL}: ${FIX_STATES[$NVDA_SUP_PATCH_STATUS]}\n" | ||
echo -e "${BOLD}AMD Fix${NORMAL} ${FIX_STATES[${AMD_PATCH_STATUS}]}" | ||
echo -e "${BOLD}NVDA eGPU Optimization${NORMAL} ${FIX_STATES[${NVDA_OPT_PATCH_STATUS}]}" | ||
echo -e "${BOLD}NVDA Suppression${NORMAL} ${FIX_STATES[${NVDA_SUP_PATCH_STATUS}]}" | ||
echo -e "${BOLD}Mux Last Intent${NORMAL} ${GFX_STATES[${PN_LAST_GFX_CONFIG}]}\n" | ||
echo -e "The ${BOLD}Mux Last Intent${NORMAL} state refers to what the script intended last\ntime, and not necessarily whether the script succeeded or not,\nas the actual mux value is \"consumed\" and cannot be tracked.\nBy default, the intent is ${BOLD}Discrete${NORMAL}.\n" | ||
} | ||
|
||
# Cumulative system check | ||
|
@@ -185,6 +190,7 @@ sanitize_system() { | |
echo -e "System sanitized." | ||
} | ||
|
||
# Patch NVIDIA drivers | ||
patch_nv_plists() { | ||
echo -e "${BOLD}Patching NVIDIA driver configuration...${NORMAL}" | ||
[[ ! -f "${NVDA_STARTUP_WEB_PLIST}" ]] && echo -e "${BOLD}NVIDIA Web Drivers${NORMAL} must already be installed.\n" && return | ||
|
@@ -205,13 +211,22 @@ update_nvram() { | |
[[ "${BOOT_ARG}" != "-no-set" ]] && nvram boot-args="${BOOT_ARG}" | ||
nvram "${NV_GUID}:gpu-power-prefs"="${POWER_PREFS}" | ||
nvram "${NV_GUID}:gpu-active"="${POWER_PREFS}" | ||
nvram "${PN_STATE}"="${POWER_PREFS}" | ||
nvram -s | ||
sleep 1 | ||
sleep 5 | ||
echo -e "NVRAM configured." | ||
} | ||
|
||
# Patch execution routine | ||
execute_patch() { | ||
update_nvram "${1}" "${2}" | ||
echo -e "\n${BOLD}System ready.${NORMAL} Reboot to apply changes.\n" | ||
prompt_reboot | ||
} | ||
|
||
# ----- RECOVERY SYSTEM | ||
|
||
# Revert PLIST configuration | ||
revert_nv_plists() { | ||
echo -e "${BOLD}Reverting NVIDIA driver configuration...${NORMAL}" | ||
$PlistBuddy -c "Set ${NV_DRV_KEY} ${ORIGINAL_PCI_MATCH_VALUE}" "${NVDA_STARTUP_OFFICIAL_PLIST}" 1>/dev/null 2>&1 | ||
|
@@ -221,6 +236,7 @@ revert_nv_plists() { | |
sanitize_system | ||
} | ||
|
||
# Uninstall NVRAM changes | ||
uninstall() { | ||
echo -e "\n${BOLD}>> Uninstall${NORMAL}\n" | ||
echo -e "${BOLD}Uninstalling...${NORMAL}" | ||
|
@@ -257,6 +273,22 @@ first_time_setup() { | |
|
||
# ----- USER INTERFACE | ||
|
||
# Prompt reboot | ||
prompt_reboot() { | ||
read -n1 -p "${BOLD}Reboot now${NORMAL}? [Y/N]: " INPUT | ||
if [[ "${INPUT}" == "Y" ]] | ||
then | ||
echo -e "\n\n${BOLD}Rebooting...${NORMAL}" | ||
reboot 1>/dev/null 2>&1 | ||
elif [[ "${INPUT}" == "N" ]] | ||
then | ||
echo -e "\n\nReboot aborted.\n" | ||
else | ||
echo -e "\n\nInvalid selection.\n" | ||
prompt_reboot | ||
fi | ||
} | ||
|
||
# Request donation | ||
donate() { | ||
open "https://www.paypal.com/cgi-bin/webscr?cmd=_donations&[email protected]&lc=US&item_name=Development%20of%20PurgeNVDA&no_note=0¤cy_code=USD&bn=PP-DonationsBF:btn_donate_SM.gif:NonHostedGuest" | ||
|
@@ -300,26 +332,23 @@ process_args() { | |
case "${1}" in | ||
-fa|--fix-amd|1) | ||
echo -e "\n>> ${BOLD}AMD eGPUs${NORMAL}\n" | ||
update_nvram "nv_disable=1" "${IG_POWER_PREF}" | ||
echo -e "\n${BOLD}System ready.${NORMAL} Reboot to apply changes.\n";; | ||
execute_patch "nv_disable=1" "${IG_POWER_PREF}";; | ||
-on|--optimize-nv|2) | ||
echo -e "\n>> ${BOLD}NVIDIA eGPUs${NORMAL}\n" | ||
patch_nv_plists | ||
[[ $PLIST_PATCHED == 0 ]] && ask_menu && return | ||
update_nvram "" "${IG_POWER_PREF}" | ||
echo -e "\n${BOLD}System ready.${NORMAL} Reboot to apply changes.\n";; | ||
execute_patch "" "${IG_POWER_PREF}";; | ||
-u|--uninstall|3) | ||
uninstall;; | ||
uninstall | ||
prompt_reboot;; | ||
-s|--status|4) | ||
check_system_status;; | ||
-sn|--suppress-nv|5) | ||
echo -e "\n>> ${BOLD}Suppress NVIDIA GPUs${NORMAL}\n" | ||
update_nvram "agc=-1" "${IG_POWER_PREF}" | ||
echo -e "\n${BOLD}System ready.${NORMAL} Reboot to apply changes.\n";; | ||
execute_patch "agc=-1" "${IG_POWER_PREF}";; | ||
-mi|--mux-igpu|6) | ||
echo -e "\n>> ${BOLD}Set Mux to iGPU${NORMAL}\n" | ||
update_nvram "-no-set" "${IG_POWER_PREF}" | ||
echo -e "\n${BOLD}System ready.${NORMAL} Reboot to apply changes.\n";; | ||
execute_patch "-no-set" "${IG_POWER_PREF}";; | ||
-d|--donate|d|D) | ||
donate;; | ||
0) | ||
|