#!/usr/bin/perl

sub checkHardware;
sub checkVersion;
sub installationCheck;


sub checkHardware
{
	my $hw = `system_profiler SPHardwareDataType | grep Intel`;
	if (!$hw) {
		#print "This is not an Intel Mac\n";
		return 1;
	}	
}

sub checkVersion
{
    my $version         = $_[0];
    my $operator        = $_[1];
	my $plist = "/System/Library/CoreServices/SystemVersion.plist";
	my $key = "ProductVersion";

	if (!$version) {
		return 0;
	}

    if ( -f $plist && (open my $fd, "$plist") )
    {
		my $plistData = "";
		{
			local $/;
			$plistData = <$fd>;
		}
		close $fd;

		if (!$operator) {
			$operator = ">=";
		}

 	   if ( $plistData =~ /^.*?<key>${key}<\/key>.*?<string>(.*?)<\/string>.*$/s )
 	   {
			@systemVersion = split /\./, $1;
			@incommingVersion = split /\./, $version;

			my $actualVersion;
		
			for ($i = 0; $i < 3; $i++)
			{
				if(!$systemVersion[$i])
				{
					$systemVersion[$i] = 0;
				}
				if (($incommingVersion[$i] != $systemVersion[$i]) || ($i == 2))
				{
					$actualVersion = $systemVersion[$i];
					$version = $incommingVersion[$i];
					last;
				}
			}

			return 0 if( eval ("$actualVersion " . $operator . " $version") );
 	   }
    }

	return 1;
}


sub installationCheck
{
	if ( checkHardware )
	{
		return ((1 << 6) + (1 << 5) + 16);
		
	} elsif ( checkVersion("10.9.0") )	{
	
		return ((1 << 6) + (1 << 5) + 17);
		
	} else {	

	return 0;
	}
}

exit installationCheck(@ARGV);
