<?xml version="1.0" encoding="utf-8"?>
<installer-gui-script minSpecVersion="1">
    <installation-check script="installationCheck()"/>
    <script>
function installationCheck() {
  createInstallerInfoFile();

	if(isEndpointSecurityInstalled() == true) {
    my.result.title = 'Check Point Endpoint Security VPN can not be installed on this computer';
    my.result.message = 'Check Point Endpoint Security is installed on this computer. Please install the VPN blade as part of Endpoint Security.';
    my.result.type = 'Fatal';
		return false;
	}
	
	if(isDowngrade() == true) {
    my.result.title = 'Check Point Endpoint Security VPN'
    my.result.message = 'Endpoint Security VPN downgrade to version build 986203002 is not allowed.';
    my.result.type = 'Fatal';
		return false;
	}
	
	if(isVersionAlreadyInstalled() == true) {
	}
	
	if(isUpgrade() == true) {
    my.result.title = 'Check Point Endpoint Security VPN'
    my.result.message = 'A previous instance of Endpoint Security VPN was detected and will be upgraded to build 986203002.';
    my.result.type = 'Warn';
	}
	return true;
}

function createInstallerInfoFile() {
  system.run('CreateInstallerInfo.sh', 986203002);
}

function isDowngrade() {
  if(system.run('CheckIfDowngrade.sh', 986203002) == true) {
    return true;
  }
  
  return false;
}

function isUpgrade() {
  if(system.run('CheckIfUpgrade.sh', 986203002) == false) {
    return true;
  }
  
  return false;
}

function isVersionAlreadyInstalled() {
  if(system.run('CheckIfAlreadyInstalled.sh', 986203002) == false) {
   if(isFwModuleInstalled() == false || isCePackageInstalled() == false) {
      my.result.title = 'Check Point Endpoint Security VPN'
      my.result.message = 'Endpoint Security VPN build 986203002 is already installed on this computer. Only additional modules that not installed will be available for installation.';
      my.result.type = 'Warn';
    } else {
      my.result.title = 'Check Point Endpoint Security VPN'
      my.result.message = 'Endpoint Security VPN build 986203002 is already installed on this computer.';
      my.result.type = 'Fatal';
    }
    return true;
  }
  
  return false;
}

function isEndpointSecurityInstalled() {
  if(system.run('CheckEndpointSecurity.sh') == true) {
    return true;
  }

  return false;
}

function isFwModuleInstalled() {
  if(system.run('CheckIfFwModuleInstalled.sh') == false) {
    return true;
  }
  
  return false;
}

function isFwPackageInstalled() {
  if(system.run('CheckIfFwPackageInstalled.sh') == false) {
    return true;
  }
  
  return false;
}

function isCePackageInstalled() {
  if(system.run('CheckIfCePackageInstalled.sh') == false) {
    return true;
  }
  return false;
}
  
function isInstallVpnSelected() {
  return choices['com.checkpoint.pkg.epc'].packageUpgradeAction != 'installed';
}

function isInstallFwEnabled() {
  return choices['com.checkpoint.pkg.epc.fw'].packageUpgradeAction == 'clean';
}

function isInstallFwSelected() {
  if (choices['com.checkpoint.pkg.epc.fw'].packageUpgradeAction == 'clean') {
    throw "Don't update the choices";
  }
  return choices['com.checkpoint.pkg.epc.fw'].packageUpgradeAction == 'upgrade';
}

function isInstallFwVisible() {
  return choices['com.checkpoint.pkg.epc.fw'].packageUpgradeAction != 'installed';
}

function isInstallCeEnabled() {
  if (choices['com.checkpoint.pkg.epc.ce'].packageUpgradeAction == 'clean') {
    return true
  }
  else {
    choices['com.checkpoint.pkg.epc.ce'].selected = true;
    return false;
  }
}

function isInstallCeSelected() {
  if (choices['com.checkpoint.pkg.epc.ce'].packageUpgradeAction == 'clean') {
    throw "Don't update the choices";
  }
  return choices['com.checkpoint.pkg.epc.ce'].packageUpgradeAction == 'upgrade';
}

function isInstallCeVisible() {
  return choices['com.checkpoint.pkg.epc.ce'].packageUpgradeAction != 'installed';
}
    </script>
    <title>Endpoint Security VPN</title>
    <background file="background.png"/>
    <license file="EULA.rtf"/>
    <pkg-ref id="com.checkpoint.pkg.epc">
        <bundle-version>
            <bundle CFBundleShortVersionString="986203002" CFBundleVersion="1" id="com.checkpoint.eps_vpn.ui" path="Applications/Endpoint Security VPN.app"/>
        </bundle-version>
    </pkg-ref>
    <pkg-ref id="com.checkpoint.pkg.epc.fw">
        <bundle-version>
            <bundle CFBundleShortVersionString="872016503" CFBundleVersion="6" id="com.checkpoint.fw.filter" path="Library/Application Support/Checkpoint/Endpoint Connect/Check Point Firewall.app/Contents/Library/SystemExtensions/com.checkpoint.fw.filter.systemextension"/>
            <bundle CFBundleShortVersionString="872016503" CFBundleVersion="1" id="com.checkpoint.fw.app" path="Library/Application Support/Checkpoint/Endpoint Connect/Check Point Firewall.app"/>
            <bundle CFBundleShortVersionString="872016503" CFBundleVersion="1" id="com.checkpoint.fw" path="Library/Application Support/Checkpoint/Endpoint Connect/Check Point Firewall.app/Contents/Library/SystemExtensions/com.checkpoint.fw.filter.systemextension/Contents/PlugIns/fw.bundle"/>
        </bundle-version>
    </pkg-ref>
    <options customize="always" require-scripts="false" allow-external-scripts="yes" hostArchitectures="x86_64,arm64" rootVolumeOnly="true"/>
    <choices-outline>
        <line choice="com.checkpoint.pkg.epc"/>
        <line choice="com.checkpoint.pkg.epc.fw"/>
        <line choice="com.checkpoint.pkg.epc.ce"/>
    </choices-outline>
    <choice id="default"/>
    <choice id="com.checkpoint.pkg.epc" title="Remote Access VPN" description="Installs the module that enables VPN capabilities." start_selected="false" enabled="false" selected="isInstallVpnSelected()">
        <pkg-ref id="com.checkpoint.pkg.epc"/>
    </choice>
    <choice id="com.checkpoint.pkg.epc.fw" title="Firewall" description="Installs the Check Point Firewall module." start_selected="false" enabled="isInstallFwEnabled()" selected="isInstallFwSelected()">
        <pkg-ref id="com.checkpoint.pkg.epc.fw"/>
    </choice>
    <choice id="com.checkpoint.pkg.epc.ce" title="Compliance Engine" description="Installs the Check Point Compliance Engine module." start_selected="false" enabled="isInstallCeEnabled()" selected="isInstallCeSelected()">
        <pkg-ref id="com.checkpoint.pkg.epc.ce"/>
    </choice>
    <pkg-ref id="com.checkpoint.pkg.epc" version="986203002" onConclusion="none" installKBytes="114936">#EPS_VPN.pkg</pkg-ref>
    <pkg-ref id="com.checkpoint.pkg.epc.fw" version="986203002" onConclusion="none" installKBytes="4247">#EPS_FW.pkg</pkg-ref>
    <pkg-ref id="com.checkpoint.pkg.epc.ce" version="986203002" onConclusion="none" installKBytes="34820">#EPS_CE.pkg</pkg-ref>
    <pkg-ref id="com.checkpoint.pkg.epc.ce">
        <bundle-version/>
    </pkg-ref>
    <product version="986203002"/>
</installer-gui-script>