<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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";
        
//        The logic:
//        1. If this is iMac12,1.
//        2. If no Bluetooth nor IR.
//        3. return false
//        
//        So effectively, Model is iMac12,1 AND (Bluetooth nor IR, don't offer.)
		
	function iMac21NeedsUpdate()
				{
					// check model
					var model = system.sysctl("hw.model");
					if (!model) return false;
					if (model != "iMac12,1") 
					{
						debuglog("iMac21 Model Property fail; got: " + model);
						return true;
					}
					debuglog("Model property pass; got: " + model);


					// check for Bluetooth
					var Bluetooth = 
		system.ioregistry.fromPath("IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/EHC2@1A,7/AppleUSBEHCI/Bluetooth USB Host Controller@fa111000");
					
					// check for IR
					var IR = 
		system.ioregistry.fromPath("IOService:/AppleACPIPlatformExpert/PCI0@0/AppleACPIPCI/EHC1@1D,7/AppleUSBEHCI/IR Receiver@fd120000");
					
					if ( (IR || Bluetooth) )
					{
						debuglog("Found IR Receiver or Bluetooth; continue.");
						return true;
					}
					debuglog("Didn't find Bluetooth controller nor IR Receiver. 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 = ['MacBookAir4,1','MacBookAir4,2',];
	var model = system.sysctl('hw.model');
	if (models.indexOf(model) == -1) {
		my.result.message = system.localizedString('ERROR_3');
		my.result.type = 'Fatal';
		return false;
	}
	if (system.compareVersions(system.version.ProductVersion, '10.7.4') &lt; 0) {
		my.result.message = system.localizedStringWithFormat('ERROR_0', '10.7.4');
		my.result.type = 'Fatal';
		return false;
	}
	if (system.compareVersions(system.version.ProductVersion, '10.7.4') > 0) {
		my.result.message = system.localizedStringWithFormat('ERROR_0', '10.7.4');
		my.result.type = 'Fatal';
		return false;
	}
	my.result.message = system.localizedString('ERROR_3');
	if (!BundleCheck0("/") || !Script1("/")) {
		my.result.type = 'Fatal';
		return false;
	}
	return true;
}
function BundleCheck0(prefix) {
	var bundle = system.files.bundleAtPath(prefix + '/System/Library/Extensions/IONetworkingFamily.kext/Contents/PlugIns/AppleBCM5701Ethernet.kext');
	if (!bundle) {
		return false;
	}
	var bundleKeyValue = bundle['CFBundleShortVersionString'];
	if (!bundleKeyValue) {
		return false;
	}
	if (system.compareVersions(bundleKeyValue, '3.2.4') > 0) {
		return false;
	}
	return true;
}
function Script1(prefix) {
	if (!iMac21NeedsUpdate()) {
		return false;
	}
	return true;
}
function BundleCheck2(prefix) {
	var bundle = system.files.bundleAtPath(prefix + '/System/Library/Extensions/IONetworkingFamily.kext/Contents/PlugIns/AppleBCM5701Ethernet.kext');
	if (!bundle) {
		return false;
	}
	var bundleKeyValue = bundle['CFBundleShortVersionString'];
	if (!bundleKeyValue) {
		return false;
	}
	if (system.compareVersions(bundleKeyValue, '3.2.4') >= 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.2.1" start_selected="true" visible="BundleCheck2('/')">
        <pkg-ref id="ThunderboltSoftwareUpdate" auth="Root" packageIdentifier="com.apple.ThunderboltSoftwareUpdate1.2.1" onConclusion="RequireRestart">ThunderboltSoftwareUpdate.pkg</pkg-ref>
    </choice>
    <localization>
        <strings language="pl"><![CDATA["SU_TITLE" = "Uaktualnienie oprogramowania Thunderbolt";
"SU_VERS" = "1.2";
"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">
	body {font: 11px "Lucida Grande";}
  </style>
</head>
<body>
<p>Dodaje obsługę interfejsu Apple Thunderbolt do adaptera Gigabit Ethernet.</p>
</body>
</html>
';
]]></strings>
    </localization>

	<pkg-ref id='ThunderboltSoftwareUpdate' installKBytes='458' version='1.2.1.0.1.1293150744'/>
</installer-gui-script>