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

nvda_md5_10_10_5web=2884ff3590c4df2c6d8b24d0e9d7fd5c
nvda_md5_10_10_5web_patched=b85c25726ce92eeccda13330d7b38e5c

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/NVDAGK100HalWeb.kext/Contents/MacOS/NVDAGK100HalWeb
	sudo touch /System/Library/Extensions
fi
