<?xml version="1.0" encoding="UTF-8"?>
<installer-gui-script minSpecVersion="1">
    <options customize="never" hostArchitectures="i386" rootVolumeOnly="true"/>
    <title>SU_TITLE</title>
    <script>
</script>
    <installation-check script="InstallationCheck()"/>
    <script>
		var updateName = "ThunderBoltSoftwareUpdate";
		
		function MacBookProNeedsUpdate()
		{
			// check model
			var model = system.sysctl("hw.model");
			if (!model) return false;
			if ((model != "MacBookPro8,1") &amp;&amp; (model != "MacBookPro8,2") &amp;&amp; (model != "MacBookPro8,3")) 
			{
				debuglog("MBP Model Property fail; got: " + model);
				return false;
			}
			debuglog("Model property pass; got: " + model);
			
			// check ThunderBolt EPROM version
			var ThunderEPROM = system.ioregistry.fromPath("IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/PEG1@1,1/IOPCI2PCIBridge/UPSB@0/IOPCI2PCIBridge/DSB0@0/IOPCI2PCIBridge/NHI0@0/AppleThunderboltHAL/AppleThunderboltNHI/IOThunderboltController/IOThunderboltPort@6/IOThunderboltSwitch");
			if (!ThunderEPROM) 
			{
				debuglog("Can't find IOThunderboltSwitch; assuming machine does not needs update.");
				return false;
			}
			var ROMVersion = ThunderEPROM["ROM Version"];
			
			// check PortMicro version
			var PortMicro = system.ioregistry.fromPath("IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/PEG1@1,1/IOPCI2PCIBridge/UPSB@0/IOPCI2PCIBridge/DSB0@0/IOPCI2PCIBridge/NHI0@0/AppleThunderboltHAL/AppleThunderboltNHI/IOThunderboltController/IOThunderboltPort@6/IOThunderboltSwitch/IOThunderboltPort@1");
			if (!PortMicro)
			{
				debuglog("Can't find IOThunderboltPort; assuming machine does not needs update.");
				return false;
			}
			var MicroVersion = PortMicro["Micro Version"];
			if ((ROMVersion >= 0x22) &amp;&amp; (MicroVersion >= 0x20007)) 
			{
				debuglog("ThunderBolt EPROM version is eligible for update, got: " + ROMVersion);
				debuglog("ThunderBolt Micro Version is eligible for update, got: " + MicroVersion);
				return true;
			}
			
			// Nope, we don't need the update
			debuglog("MBP Neither EPROM Version nor Micro Version are eligible for update. Returning false");
			return false;
		}
		
		function iMacNeedsUpdate()
		{
			// check model
			var model = system.sysctl("hw.model");
			if (!model) return false;
			if ((model != "iMac12,1") &amp;&amp; (model != "iMac12,2")) 
			{
				debuglog("MBP Model Property fail; got: " + model);
				return false;
			}
			debuglog("Model property pass; got: " + model);

			var Bluetooth = system.ioregistry.fromPath("IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/EHC2@1A,7/AppleUSBEHCI/Bluetooth USB Host Controller@fa111000");
			if (!Bluetooth) 
			{
				debuglog("Bluetooth Setting for K60E");
				return false;
			}

			var IR = system.ioregistry.fromPath("IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/EHC1@1D,7/AppleUSBEHCI/IR Receiver@fd120000");
			if (!IR)
			{
				debuglog("IR Setting for K60E");
				return false;
			}
			
			// check ThunderBolt EPROM version
			var ThunderEPROM = system.ioregistry.fromPath("IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/RP05@1C,4/IOPCI2PCIBridge/UPSB@0/IOPCI2PCIBridge/DSB0@0/IOPCI2PCIBridge/NHI0@0/AppleThunderboltHAL/AppleThunderboltNHI/IOThunderboltController/IOThunderboltPort@6/IOThunderboltSwitch");
			if (!ThunderEPROM) 
			{
				debuglog("Can't find IOThunderboltSwitch; assuming machine does not need update.");
				return false;
			}
			var ROMVersion = ThunderEPROM["ROM Version"];
			
			// check PortMicro version
			var PortMicro = system.ioregistry.fromPath("IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/RP05@1C,4/IOPCI2PCIBridge/UPSB@0/IOPCI2PCIBridge/DSB0@0/IOPCI2PCIBridge/NHI0@0/AppleThunderboltHAL/AppleThunderboltNHI/IOThunderboltController/IOThunderboltPort@6/IOThunderboltSwitch/IOThunderboltPort@1");
			if (!PortMicro)
			{
				debuglog("Can't find IOThunderboltPort; assuming machine does not need update.");
				return false;
			}
			var MicroVersion = PortMicro["Micro Version"];
                        if ((ROMVersion >= 0x22) &amp;&amp; (MicroVersion >= 0x20007))
                        {
                                debuglog("ThunderBolt EPROM version is eligible for update, got: " + ROMVersion);
                                debuglog("ThunderBolt Micro Version is eligible for update, got: " + MicroVersion);
                                return true;
                        }
			
			// Nope, we don't need the update
			debuglog("MBP Neither EPROM Version nor Micro Version are eligible for update. Returning false");
			return false;
		}
		
		function debuglog(message)
		{
			// yes, this is secure
			if (system.files.fileExistsAtPath("/tmp/com.apple.pkg.testing")) system.log("********** " + updateName + ": " + message);
		}
	</script>
    <script>
function InstallationCheck(prefix) {
	var models = ['MacBookPro8,1','MacBookPro8,2','MacBookPro8,3','iMac12,1','iMac12,2',];
	var model = system.sysctl('hw.model');
	if (models.indexOf(model) == -1) {
		my.result.message = system.localizedString('ERROR_1');
		my.result.type = 'Fatal';
		return false;
	}
	if (system.compareVersions(system.version.ProductVersion, '10.6.8') &lt; 0) {
		my.result.message = system.localizedStringWithFormat('ERROR_0', '10.6.8');
		my.result.type = 'Fatal';
		return false;
	}
	my.result.message = system.localizedString('ERROR_1');
	if (!LogicalOr0("/")) {
		my.result.type = 'Fatal';
		return false;
	}
	return true;
}
function LogicalOr0(prefix) {
	if (typeof(my.result) != 'undefined') my.result.message = system.localizedString('ERROR_2');
	if (LogicalAnd1(prefix) || LogicalAnd6(prefix)) {
		return true;
	}
	return false;
}
function LogicalAnd1(prefix) {
	if (Script2(prefix) &amp;&amp; LogicalAnd3(prefix)) {
		return true;
	}
	return false;
}
function Script2(prefix) {
	if (!iMacNeedsUpdate()) {
		return false;
	}
	return true;
}
function LogicalAnd3(prefix) {
	if (PlistCheck4(prefix) &amp;&amp; BundleCheck5(prefix)) {
		return true;
	}
	return false;
}
function PlistCheck4(prefix) {
	var plist = system.files.plistAtPath(prefix + '/System/Library/CoreServices/SystemVersion.plist');
	if (!plist) {
		return false;
	}
	var plistKeyValue = plist['ProductVersion'];
	if (!plistKeyValue) {
		return false;
	}
	if (system.compareVersions(plistKeyValue, '10.7') >= 0) {
		return false;
	}
	return true;
}
function BundleCheck5(prefix) {
	var bundle = system.files.bundleAtPath(prefix + '/System/Library/Extensions/IOThunderboltFamily.kext');
	if (!bundle) {
		return false;
	}
	var bundleKeyValue = bundle['CFBundleShortVersionString'];
	if (!bundleKeyValue) {
		return false;
	}
	if (system.compareVersions(bundleKeyValue, '1.6.3') > 0) {
		return false;
	}
	return true;
}
function LogicalAnd6(prefix) {
	if (Script7(prefix) &amp;&amp; LogicalAnd3(prefix)) {
		return true;
	}
	return false;
}
function Script7(prefix) {
	if (!MacBookProNeedsUpdate()) {
		return false;
	}
	return true;
}
function BundleCheck8(prefix) {
	var bundle = system.files.bundleAtPath(prefix + '/System/Library/Extensions/IOThunderboltFamily.kext');
	if (!bundle) {
		return false;
	}
	var bundleKeyValue = bundle['CFBundleShortVersionString'];
	if (!bundleKeyValue) {
		return false;
	}
	if (system.compareVersions(bundleKeyValue, '1.6.3') >= 0) {
		return false;
	}
	return true;
}
</script>
    <platforms>
        <client arch="i386"/>
        <server arch="i386"/>
    </platforms>
    <choices-outline ui="SoftwareUpdate">
        <line choice="su"/>
    </choices-outline>
    <choices-outline>
        <line choice="su"/>
    </choices-outline>
    <choice id="su" title="SU_TITLE" versStr="SU_VERS" description="SU_DESCRIPTION" description-mime-type="text/html" secondaryDescription="SU_SERVERCOMMENT" suDisabledGroupID="ThunderboltSoftwareUpdate1.0" visible="BundleCheck8('/')">
        <pkg-ref id="AppleDisplay" auth="Root" packageIdentifier="com.apple.pkg.ThunderboltSoftwareUpdate" onConclusion="RequireRestart">ThunderboltSoftwareUpdate.pkg</pkg-ref>
    </choice>
    <localization>
        <strings language="pl"><![CDATA["SU_TITLE" = "Uaktualnienie oprogramowania Thunderbolt";
"SU_VERS" = "1.0";
"SU_SERVERCOMMENT" = "Dla komputerów klienckich i serwerów";
"SU_DESCRIPTION" = '<HTML><!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <meta http-equiv="Content-Style-Type" content="text/css">
  <title></title>
  <style type="text/css">
	p {margin: 0.0px 0.0px 0.0px 0.0px; font: 11px Lucida Grande;}
  </style>
</head>
<body>
<p>To uaktualnienie zapewnia obsługę Apple Thunderbolt Display i zawiera poprawki zgodności z urządzeniami używającymi interfejsu Thunderbolt.</p>
</body>
</html>
';
]]></strings>
    </localization>

	<pkg-ref id='AppleDisplay' installKBytes='156032' version='1.0.0.0.1.1238328574'/>
</installer-gui-script>