WaldMeister Posted March 12, 2015 Share Posted March 12, 2015 Hi, I'm currently working on a script to automatically patch the files to get the HD4600 working. The script works as intended, but has no checks. What i would like to do is check for a value in a plist or binary, if present, continue patching, if the value is not found, skip the file. Did some research, but failed to get it working. Any help would be appreciated. #!/bin/bash #Definitions p5000=/System/Library/Extensions/AppleIntelHD5000Graphics.kext/Contents/Info.plist b5000=/System/Library/Extensions/AppleIntelHD5000Graphics.kext/Contents/MacOS/AppleIntelHD5000Graphics pazul=/System/Library/Extensions/AppleIntelFramebufferAzul.kext/Contents/Info.plist bazul=/System/Library/Extensions/AppleIntelFramebufferAzul.kext/Contents/MacOS/AppleIntelFramebufferAzul if [ $(id -u) != 0 ]; then echo "You need to run this script as root. Type sudo -s, enter password and run this script again." exit fi #Inject ID to AppleIntelHD5000Graphics Info.plist echo "Patching $p5000" sudo sed -i.bak 's/0412/0416/g' $p5000 echo "Info.plist patched" #Patch AppleIntelHD5000Graphics.kext binary echo "Patching $b5000" sudo perl -pi -e 's|\x86\x80\x12\x04|\x86\x80\x16\x04|g' -i.bak $b5000 echo "AppleIntelHD5000 binary patched" #Inject ID to AppelIntelFramebufferAzul Info.plist echo "Patching $pazul" sudo sed -i.bak 's/0412/0416/g' $pazul echo "Info.plist patched" #Patch AppleIntelFramebufferAzul binary echo "Patching $bazul" sudo perl -pi -e 's|\x60\x00\x00\x00\x00\x60\xD9|\x90\x00\x00\x00\x00\x80\xD9|g' -i.bak $bazul echo "AppleIntelFramebufferAzul binary patched" #Update caches echo "Updating caches" sudo touch /System/Library/Extensions sudo kextcache -u / echo "Finished" Example: #Inject ID to AppleIntelHD5000Graphics Info.plist echo "Patching $p5000" if 0412 found then sudo sed -i.bak 's/0412/0416/g' $p5000 echo "Info.plist patched" else skip file echo " file skipped" I tried defaults read /System/Library/Extensions/AppleIntelHD5000Graphics.kext/Contents/Info | grep, but somehow i can not get comparison to that output to work. Link to comment https://www.insanelymac.com/forum/topic/305027-need-help-completing-a-bash-script/ Share on other sites More sharing options...
MacUser2525 Posted March 13, 2015 Share Posted March 13, 2015 I am failing to see why you need test it always comes back as true on my unpatched system. $ grep 0412 /System/Library/Extensions/AppleIntelHD5000Graphics.kext/Contents/MacOS/AppleIntelHD5000Graphics Binary file /System/Library/Extensions/AppleIntelHD5000Graphics.kext/Contents/MacOS/AppleIntelHD5000Graphics matches $ grep 0412 /System/Library/Extensions/AppleIntelFramebufferAzul.kext/Contents/MacOS/AppleIntelFramebufferAzul Binary file /System/Library/Extensions/AppleIntelFramebufferAzul.kext/Contents/MacOS/AppleIntelFramebufferAzul matches $ grep 0412 /System/Library/Extensions/AppleIntelFramebufferAzul.kext/Contents/Info.plist <string>0x0c268086 0x0c168086 0x0c068086 0x0d268086 0x0a268086 0x0a2e8086 0x0a168086 0x04268086 0x04168086 0x04068086 0x0d228086 0x04128086</string> $ grep 0412 /System/Library/Extensions/AppleIntelHD5000Graphics.kext/Contents/Info.plist <string>0x00908086 0x00918086 0x00928086 0x0c268086 0x0c168086 0x0c068086 0x0c228086 0x0d268086 0x0a268086 0x0a168086 0x04268086 0x04168086 0x04068086 0x0d228086 0x04128086 0x0a2e8086</string> Unless of course the output is different on something other than a Mavericks system. Link to comment https://www.insanelymac.com/forum/topic/305027-need-help-completing-a-bash-script/#findComment-2119367 Share on other sites More sharing options...
WaldMeister Posted March 13, 2015 Author Share Posted March 13, 2015 This is on Yosemite, converting the 0412 to 0416, the patch works, but if already patched, it should skip the file, needs to test if patched. This is not about the grep command! Link to comment https://www.insanelymac.com/forum/topic/305027-need-help-completing-a-bash-script/#findComment-2119378 Share on other sites More sharing options...
calibre™ Posted March 13, 2015 Share Posted March 13, 2015 perl will just skip if non found Link to comment https://www.insanelymac.com/forum/topic/305027-need-help-completing-a-bash-script/#findComment-2119379 Share on other sites More sharing options...
Recommended Posts