<?xml version="1.0" encoding="UTF-8"?>
<installer-script authoringTool="Packages" authoringToolVersion="1.1.3" authoringToolBuild="2B112" minSpecVersion="1.0">
    <options rootVolumeOnly="true" customize="always"/>
    <installation-check script="installation_check()"/>
    <volume-check script="volume_check()"/>
    <!--+==========================+
        |       Presentation       |
        +==========================+-->
    <title>DISTRIBUTION_TITLE</title>
    <background file="background" scaling="tofit" alignment="center"/>
    <welcome file="welcome.rtf"/>
    <license file="license.rtf"/>
    <!--+==========================+
        |         Installer        |
        +==========================+-->
    <choices-outline>
        <line choice="installer_choice_1"/>
        <line choice="installer_choice_2">
            <line choice="installer_choice_2_1"/>
            <line choice="installer_choice_2_2"/>
            <line choice="installer_choice_2_3"/>
        </line>
    </choices-outline>
    <choice id="installer_choice_1" title="OnTheAir Video" description="">
        <pkg-ref id="com.softronmedia.pkg.OnTheAirVideo"/>
    </choice>
    <choice id="installer_choice_2_1" title="OnTheAir Tools" description="INSTALLER_CHOICE_2_1_DESCRIPTION">
        <pkg-ref id="com.softronmedia.pkg.otav.OnTheAirTools"/>
    </choice>
    <choice id="installer_choice_2_2" title="Actions Folder" description="INSTALLER_CHOICE_2_2_DESCRIPTION">
        <pkg-ref id="com.softronmedia.pkg.otav.ActionsFolder"/>
    </choice>
    <choice id="installer_choice_2_3" start_selected="false" title="AppleScript Examples" description="INSTALLER_CHOICE_2_3_DESCRIPTION">
        <pkg-ref id="com.softronmedia.pkg.otav.AppleScripts"/>
    </choice>
    <choice id="installer_choice_2" title="INSTALLER_CHOICE_2_TITLE" description="INSTALLER_CHOICE_2_DESCRIPTION"/>
    <!--+==========================+
        |    Package References    |
        +==========================+-->
    <pkg-ref id="com.softronmedia.pkg.otav.ActionsFolder" version="3.0" installKBytes="28">#Actions_Folder.pkg</pkg-ref>
    <pkg-ref id="com.softronmedia.pkg.otav.AppleScripts" version="3.0" installKBytes="45">#AppleScript_Examples.pkg</pkg-ref>
    <pkg-ref id="com.softronmedia.pkg.OnTheAirVideo" version="3.5.2b2" installKBytes="23492">#OnTheAir_Video.pkg</pkg-ref>
    <pkg-ref id="com.softronmedia.pkg.otav.OnTheAirTools" version="1.31" installKBytes="2732">#OnTheAir_Tools.pkg</pkg-ref>
    <!--+==========================+
        |    JavaScript Scripts    |
        +==========================+-->
    <script>

	const __IC_FLAT_DISTRIBUTION__=true;
	const IC_CPU_ARCHITECTURE_ANY=0;
	const IC_CPU_ARCHITECTURE_POWERPC=18;
	const IC_CPU_ARCHITECTURE_INTEL=7;
	const IC_CPU_ARCHITECTURE_TYPE_ANY=0;
	const IC_CPU_ARCHITECTURE_TYPE_32=1;
	const IC_CPU_ARCHITECTURE_TYPE_64=2;

	const IC_DISK_TYPE_DESTINATION=0;
	const IC_DISK_TYPE_STARTUP_DISK=1;
	const IC_OS_DISTRIBUTION_TYPE_ANY=0;
	const IC_OS_DISTRIBUTION_TYPE_CLIENT=1;
	const IC_OS_DISTRIBUTION_TYPE_SERVER=2;

	function IC_CheckMinimumRAMSize(inMinimumSize)
	{
		return (system.sysctl('hw.memsize')&gt;=inMinimumSize);
	}

	function IC_CheckCPU(inMinimumCoresCount,inSupportedArchitecture,inSupportedPowerPCArchitectureType,inSupportedIntelArchitectureType,inMinimumFrequency)
	{
		/* Check Minimum Core Count */
		
		if (system.sysctl('hw.ncpu')&gt;=inMinimumCoresCount)
		{
			var tArchitecture;
			var t64BitSupport;
			
			tArchitecture=system.sysctl('hw.cputype');
			
			/* Check Architecture */
			
			if (inSupportedArchitecture!=IC_CPU_ARCHITECTURE_ANY)
			{
				if (inSupportedArchitecture!=tArchitecture)
				{
					return false;
				}
			}
			
			/* Check Architecture Type */
			
			t64BitSupport=system.sysctl('hw.cpu64bit_capable');
			
			if (tArchitecture==IC_CPU_ARCHITECTURE_POWERPC)
			{
				if ((inSupportedPowerPCArchitectureType==IC_CPU_ARCHITECTURE_TYPE_32 &amp;&amp; t64BitSupport==1) ||
					(inSupportedPowerPCArchitectureType==IC_CPU_ARCHITECTURE_TYPE_64 &amp;&amp; t64BitSupport==0))
				{
					return false;
				}
			}
			else if (tArchitecture==IC_CPU_ARCHITECTURE_INTEL)
			{
				if ((inSupportedIntelArchitectureType==IC_CPU_ARCHITECTURE_TYPE_32 &amp;&amp; t64BitSupport==1) ||
					(inSupportedIntelArchitectureType==IC_CPU_ARCHITECTURE_TYPE_64 &amp;&amp; t64BitSupport==0))
				{
					return false;
				}
			}
			
			/* Check Minimum CPU Frequency */
			
			if (system.sysctl('hw.cpufrequency_max')&gt;=inMinimumFrequency)
			{
				return true;
			}
		}
		
		return false;
	}

	function IC_CheckOS(inDiskType,inMustBeInstalled,inMinimumVersion,inDistributionType)
	{
		var tOSVersion=undefined;
		
		/* Check Minimum Version */
		
		if (inDiskType==IC_DISK_TYPE_DESTINATION)
		{
			if (my.target.systemVersion!=undefined)
			{
				tOSVersion=my.target.systemVersion.ProductVersion;
			}
			
			/* Check if no OS is installed on the potential target */
			
			if (tOSVersion==undefined)
			{
				return (inMustBeInstalled==false);
			}
		}
		else
		{
			tOSVersion=system.version.ProductVersion;
		}
		
		if (system.compareVersions(tOSVersion,inMinimumVersion)==-1)
		{
			return false;
		}
		
		/* Check Distribution Type */
		
		if (inDistributionType!=IC_OS_DISTRIBUTION_TYPE_ANY)
		{
			var tIsServer;
			
			if (system.compareVersions(tOSVersion,'10.8.0')==-1)
			{
				if (inDiskType==IC_DISK_TYPE_DESTINATION)
				{
					tIsServer=system.files.fileExistsAtPath(my.target.mountpoint+'/System/Library/CoreServices/ServerVersion.plist');
				}
				else
				{
					tIsServer=system.files.fileExistsAtPath('/System/Library/CoreServices/ServerVersion.plist');
				}
			}
			else
			{
				if (inDiskType==IC_DISK_TYPE_DESTINATION)
				{
					tIsServer=system.files.fileExistsAtPath(my.target.mountpoint+'/Applications/Server.app');
				}
				else
				{
					tIsServer=system.files.fileExistsAtPath('/Applications/Server.app');
				}
			}
			
			if (inDistributionType==IC_OS_DISTRIBUTION_TYPE_CLIENT &amp;&amp; tIsServer==true)
			{
				return false;
			}
			
			if (inDistributionType==IC_OS_DISTRIBUTION_TYPE_SERVER &amp;&amp; tIsServer==false)
			{
				return false;
			}
		}
		
		return true;
	}

	function installation_check()
	{
		var tResult;

		tResult=IC_CheckMinimumRAMSize(2147483648);

		if (tResult==false)
		{
			my.result.title = system.localizedStandardStringWithFormat('InstallationCheckError', system.localizedString('DISTRIBUTION_TITLE'));
			my.result.message = ' ';
			my.result.type = 'Fatal';
		}

		if (tResult==true)
		{
			tResult=IC_CheckCPU(1,IC_CPU_ARCHITECTURE_INTEL,IC_CPU_ARCHITECTURE_TYPE_ANY,IC_CPU_ARCHITECTURE_TYPE_64,0);

			if (tResult==false)
			{
				my.result.title = system.localizedStandardStringWithFormat('InstallationCheckError', system.localizedString('DISTRIBUTION_TITLE'));
				my.result.message = ' ';
				my.result.type = 'Fatal';
			}
		}

		return tResult;
	}

	function volume_check()
	{
		var tResult;

		tResult=IC_CheckOS(IC_DISK_TYPE_DESTINATION,true,'10.9',IC_OS_DISTRIBUTION_TYPE_ANY);

		if (tResult==false)
		{
			my.result.type = 'Fatal';
		}

		return tResult;
	}

    </script>
</installer-script>