<?xml version="1.0" encoding="UTF-8"?>
<installer-gui-script authoringTool="Packages" authoringToolVersion="1.2.10" authoringToolBuild="732" minSpecVersion="1.0">
    <options allow-external-scripts="true" hostArchitectures="x86_64"/>
    <installation-check script="installation_check()"/>
    <!--+==========================+
        |       Presentation       |
        +==========================+-->
    <title>DISTRIBUTION_TITLE</title>
    <background file="background" uti="public.png" scaling="proportional" alignment="topleft"/>
    <background-darkAqua file="background" uti="public.png" scaling="proportional" alignment="topleft"/>
    <welcome file="welcome.rtfd"/>
    <readme file="readme.rtf"/>
    <license file="license.rtf"/>
    <!--+==========================+
        |         Installer        |
        +==========================+-->
    <choices-outline>
        <line choice="installer_choice_1"/>
    </choices-outline>
    <choice id="installer_choice_1" title="AssinadorSerpro" description="">
        <pkg-ref id="br.gov.serpro.desktop.assinador"/>
    </choice>
    <!--+==========================+
        |    Package References    |
        +==========================+-->
    <pkg-ref id="br.gov.serpro.desktop.assinador" version="4.3.0" auth="Root" installKBytes="157769">file:./Contents/Packages/AssinadorSerpro.pkg</pkg-ref>
    <!--+==========================+
        |    JavaScript Scripts    |
        +==========================+-->
    <script>

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

	const IC_CPU_ARCHITECTURE_APPLESILICON=16777228;
	const IC_CPU_ARCHITECTURE_TYPE_ANY=0;
	const IC_CPU_ARCHITECTURE_TYPE_32=1;
	const IC_CPU_ARCHITECTURE_TYPE_64=2;
	const IC_CPU_ARCHITECTURE_INTEL=7;
	const IC_CPU_ARCHITECTURE_ANY=0;
	const IC_CPU_ARCHITECTURE_POWERPC=18;

	function IC_CheckOS(inDiskType,inMustBeInstalled,inMinimumVersion,inMaximumVersion,inDistributionType)
	{
		var tOSVersion=undefined;
		
		/* Check Version Constraints */
		
		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);
			}
			
			if (inMustBeInstalled==false)
			{
				return false;
			}
		}
		else
		{
			tOSVersion=system.version.ProductVersion;
		}
		
		if (system.compareVersions(tOSVersion,inMinimumVersion)==-1)
			return false;
			
		if (inMaximumVersion!=undefined &amp;&amp;
			system.compareVersions(tOSVersion,inMaximumVersion)==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 IC_CheckCPU(inMinimumCoresCount,inSupportedArchitecture,inSupportedPowerPCArchitectureType,inSupportedIntelArchitectureType,inMinimumFrequency)
	{
		/* Check Minimum Core Count */
		
		if (system.sysctl('hw.ncpu')&gt;=inMinimumCoresCount)
		{
			var tArchitecture;
			var t64BitSupport;
			var tTranslated;

			tArchitecture=system.sysctl('hw.cputype');

			tTranslated=system.sysctl('sysctl.proc_translated');

			if (tTranslated!=null)
			{
				if (tTranslated==1)
				{
					tArchitecture=IC_CPU_ARCHITECTURE_APPLESILICON;
				}
			}
			
			/* 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 (hw.cpufrequency_max does not exist on Apple Silicon) */
			
			var tFrequencyMax;
			
			tFrequencyMax=system.sysctl('hw.cpufrequency_max');
			
			if (tFrequencyMax==null || system.sysctl('hw.cpufrequency_max')&gt;=inMinimumFrequency)
			{
				return true;
			}
		}
		
		return false;
	}

	function installation_check()
	{
		var tResult;

		tResult=IC_CheckOS(IC_DISK_TYPE_STARTUP_DISK,true,'10.5',undefined,IC_OS_DISTRIBUTION_TYPE_ANY);

		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_ANY,IC_CPU_ARCHITECTURE_TYPE_ANY,IC_CPU_ARCHITECTURE_TYPE_ANY,866666);

			if (tResult==false)
			{
				my.result.title = system.localizedString('REQUIREMENT_FAILED_MESSAGE_INSTALLATION_CHECK_1');
				my.result.message = system.localizedString('REQUIREMENT_FAILED_DESCRIPTION_INSTALLATION_CHECK_1');
				my.result.type = 'Fatal';
			}
		}

		return tResult;
	}

    </script>
</installer-gui-script>