#!/bin/bash
# change extension to .sh or .command
nvda_md5_current="$(md5 -q /System/Library/Extensions/NVDAGF100HalWeb.kext/Contents/MacOS/NVDAGF100HalWeb)"

nvda_md5_10_10_5web=e0f4bc47dc44af304808bf388f1675bf
nvda_md5_10_10_5web_patched=710e0ad4d89fab2dd96325f1b5320cf9

if [ "$nvda_md5_current" = "$nvda_md5_10_10_5web_patched" ]; then
	echo "Detected patched NVIDIA driver on 10.10.5 WEB, no action taken."
fi

if [ "$nvda_md5_current" = "$nvda_md5_10.10.5WEB" ]; then
	echo "Detected unpatched NVIDIA driver on 10.10.5 WEB, patching."
	sudo perl -i.bak -pe '$oldLimit1 = qr"\xC7\x82\xF8\x00\x00\x00\x88\x84\x02\x00"s;$newLimit1 = "\xC7\x82\xF8\x00\x00\x00\x80\x1A\x06\x00";$oldLimit2 = qr"\xC7\x82\x80\x00\x00\x00\x88\x84\x02\x00"s;$newLimit2 = "\xC7\x82\x80\x00\x00\x00\x80\x1A\x06\x00";s/$oldLimit1/$newLimit1/g;s/$oldLimit2/$newLimit2/g' /System/Library/Extensions/NVDAGF100HalWeb.kext/Contents/MacOS/NVDAGF100HalWeb
	sudo touch /System/Library/Extensions
fi