read -p "Ensure "RecoveryHDUpdate.dmg" and "InstallESD.dmg" are in your Downloads folder and press [Enter]"

#access dmtest from RecoveryHDUpdate.pkg
rm -rf /private/tmp/RecoveryHDUpdate
echo "Expanding RecoveryHDUpdate.pkg"
hdiutil attach -nobrowse ~/Downloads/RecoveryHDUpdate.dmg
pkgutil --expand /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update/RecoveryHDUpdate.pkg /tmp/RecoveryHDUpdate

#access BaseSystem.dmg and BaseSystem.chunklist
echo "Expanding InstallESD.dmg"
hdiutil attach -nobrowse ~/Downloads/InstallESD.dmg

#build Recovery partition
echo "Building Recovery Partition. Please Wait"
/tmp/RecoveryHDUpdate/RecoveryHDUpdate.pkg/Scripts/Tools/dmtest ensureRecoveryPartition / /Volumes/OS\ X\ Install\ ESD/BaseSystem.dmg 0 0 /Volumes/OS\ X\ Install\ ESD/BaseSystem.chunklist

#cleanup
echo "Cleaning up"
hdiutil eject /Volumes/Mac\ OS\ X\ Lion\ Recovery\ HD\ Update
hdiutil eject /Volumes/OS\ X\ Install\ ESD/
sudo touch /Library/Preferences/SystemConfiguration/com.apple.Boot.plist
sudo kextcache -f -u /
exit 0