#!/bin/sh

IFS=$'\n'				# important!
PATCH="/Volumes/PATCHER"	        # path to the patched extensions
LEO="/Volumes/Leopard"			# path to Leopard installation

echo Deleting OSSMGR.plist...
cd $LEO/System/Library/LaunchDaemons/
rm -rf ossmgr.plist
echo Success !!

sleep 1

echo Replacing mach_kernel...
cd $LEO
rm -rf mach_kernel
cp -R $PATCH/mach_kernel $LEO/mach_kernel
chmod -R 644 $LEO/mach_kernel
chown -R root:wheel $LEO/mach_kernel
echo Success !!

sleep 1

echo Deleting necessary kernel extensions...
cd $LEO/System/Library/Extensions/
mv AppleACPIPlatform.kext AppleACPIPlatform.kext.post
mv AppleIntelIntegratedFramebuffer.kext AppleIntelIntegratedFramebuffer.kext.post
mv ApplePS2Controller.kext ApplePS2Controller.kext.post
mv AppleSMBIOS.kext AppleSMBIOS.kext.post
mv dsmos.kext dsmos.kext.post

mv IOATAFamily.kext IOATAFamily.kext.post
mv IOAHCIFamily.kext IOAHCIFamily.kext.post
mv AppleAC97Audio.kext AppleAC97Audio.kext.post
mv AppleAHCIPort.kext AppleAHCIPort.kext.post
mv AppleAzaliaAudio.kext AppleAzaliaAudio.kext.post
mv AppleVIA.kext AppleVIA.kext.post
mv AppleVIAATA.kext AppleVIAATA.kext.post
mv IOHDIXController.kext IOHDIXController.kext.post


# Deleting file to Boot speed-up?...
mv AppleHWSensor.kext AppleHWSensor.kext.post

echo Success !!

sleep 1

echo Adding patched kernel extensions...
cd $PATCH/ext
cp -R * $LEO/System/Library/Extensions
chmod -R 755 $LEO/System/Library/Extensions/* && chown -R root:wheel $LEO/System/Library/Extensions/*
echo Success !!
      5
sleep 1

read -n 1 -s -p "Remove AppleIntelCPUPowerManagement.kext? [Y/N]"$'\n'; case $REPLY in y|Y) rm -rf $LEO/System/Library/Extensions/AppleIntelCPUPowerManagement.kext && echo "Deleted" ;; n|N) echo "Leaving be";; esac

sleep 1

#read -n 1 -s -p "Replace IOATAFamily.kext? [Y/N]"$'\n'; case $REPLY in y|Y) rm -rf $LEO/System/Library/Extensions/IOATAFamily.kext && cp -R $EXT/IOATAFamily.kext $LEO/System/Library/Extensions && echo "Replaced." ;; n|N) echo "Leaving be";; esac

sleep 1

echo All patches applied successfully !!
read -n 1 -s -p "Reboot? [Y/N]"$'\n'; case $REPLY in y|Y) printf "Rebooting in 3..."; sleep 1; printf " 2..."; sleep 1; printf " 1...\n" sleep 1; reboot;; n|N) echo "You must reboot manually";; esac
