<?xml version="1.0"?>

<installer-gui-script minSpecVersion='1'>

	<options hostArchitectures='i386' allow-external-scripts='true'/>
	<domains enable_anywhere="true"/>

	<welcome file='Welcome.html'/>
	<!-- license file="License.rtf" sla="EA0401" -->
	<readme file='Description.html'/>
	<conclusion file="Conclusion.html"/>
	<background file='background.tiff' alignment='topleft' scaling='proportional'/>
  <background-darkAqua file="background.tiff" alignment='topleft' scaling="proportional"/>
  
	<title>Clover r5126 EFI bootloader</title>

	<script>
    
	function installCheckScript()
	{
		var obj = system.ioregistry.matchingClass("AppleSMC");
		if (obj) {
			system.log('installCheckScript: Found AppleSMC');
			my.result.message = system.localizedStringWithFormat('Intel_Mac_message');
			my.result.type = 'Fatal';
			return false;
		}
		system.log('installCheckScript: Passed.');
		return false;
	}

	function volCheckScript()
	{
		system.log('volCheckScript: Passed.');
		return true;
	}
  
	function upgrade_allowed(){
		var upgradable = true;
		var upgradeAction = my.choice.packageUpgradeAction;

		if((upgradeAction == "downgrade") || (upgradeAction == "mixed")){
			my.choice.tooltip = system.localizedString('Newer_Package_Installed_message');
			upgradable = false;
		}

		return upgradable;
	}

	function systemHasGPT(){
		var obj = system.ioregistry.matchingName("EFI System Partition");
		if (obj)
			return true;
		return false;
	}

	function checkFileExists(file){
		if (my.target) {
			return system.files.fileExistsAtPath(my.target.mountpoint + file)
		}
		return false;
	}
  
  function cloverPackageFirstRun(){
    var installer_plist = '/Library/Preferences/com.projectosx.clover.installer.plist';
    if (checkFileExists(my.target.mountpoint + installer_plist)) {
      return false;
    }
		return true;
	}

	function choicePreviouslySelected(option) {
		var installer_plist = '/Library/Preferences/com.projectosx.clover.installer.plist';
		if (checkFileExists(installer_plist)) {
			dict = system.files.plistAtPath(my.target.mountpoint + installer_plist);
			return dict[option] == undefined ? false : dict[option];
		}
		return false;
	}

	function checkBootFromUEFI() {
		var classObjects = system.ioregistry.matchingName('efi','IODeviceTree');
		if (classObjects) {
			for(var i = 0; i &lt; classObjects.length; i++) {
				var obj = classObjects[i];
				if ( obj.hasOwnProperty("firmware-vendor") != true)
					continue;
				if (obj["firmware-vendor"].toString() == 'C,L,O,V,E,R') {
					return false;
				}
			}
		}
		return true;
	}
  
  function checkFileSystemIsWritable()
	{
    var writable = true;
    var cmd = '[[ yes == $(diskutil info / | grep -i \'read-only volume:\' | awk \'{print $NF}\' | tr \'[:upper:]\' \'[:lower:]\') ]]'
    r = system.run('/bin/bash', '-c', cmd);
    system.log('checkFileSystemIsWritable diskutil result = ' + r);

    writable = (r != 0);
    
    if (writable) {
      system.log('checkFileSystemIsWritable: file system is writable: Passed');
    } else {
      system.log('checkFileSystemIsWritable: root file system is read only, try to make it RW...');
      var cmd2 = '/usr/bin/osascript -e\''
      cmd2 += 'do shell script "mount -uw /'
      cmd2 += '" with prompt '
      cmd2 += '"' + system.localizedString('MakingRootRW') + '"'
      cmd2 += ' with administrator privileges\''
      
      try
      {
        r2 = system.run('/bin/bash', '-c', cmd2);
        writable = (r2 == 0);
        if (writable) {
          system.log('mount -uw / succeded.');
        }
      } catch (e) {
        system.log('mount -uw / returned with error: ' + e);
        writable = false;
      }
    
      if (writable == false) {
        my.result.message = system.localizedString('GoToFailRootRW');
        my.result.type = 'Fatal';
      }
    }

		return writable;
	}

	</script>
  <installation-check script="checkFileSystemIsWritable()"/>

	<choices-outline>
		<line choice="Pre"/>
		<line choice="UEFI.only"/>
		<line choice="Target.ESP"/>
		<line choice="BiosBoot"/>
		<line choice="Utils"/>
		<line choice="EFIFolder"/>
		<line choice="off"/>
		<line choice="Bootloader">
			<line choice="bootNo"/>
			<line choice="boot0af"/>
			<line choice="boot0ss"/>
		</line>
		<line choice="AltBoot"/>
		<line choice="CloverEFI"/>
		<line choice="rc.scripts.on.target"/>
		<line choice="rc.scripts.on.all.volumes"/>
		<line choice="rc.scripts.core"/>
		<line choice="OptionalRCScripts">
			<line choice="disable_sleep_proxy_client"/>
		</line>
		<line choice="Themes">
			<line choice="Purple_Swirl"/>
			<line choice="Clovy"/>
			<line choice="BGM"/>
			<line choice="cesium"/>
		</line>
		<line choice="CloverPrefpane"/>
		<line choice="Post"/>
	</choices-outline>

	<choice
		id="Pre"
		title="Pre"
		description="Pre"
		start_visible="false" start_selected="true">
		<pkg-ref id="org.clover.pre"/>
	</choice>

	<choice
		id="UEFI.only"
		title="UEFI.only_title"
		description="UEFI.only_description"
		start_visible="true" start_selected="choicePreviouslySelected('org.clover.uefi.only')">
		<pkg-ref id="org.clover.uefi.only"/>
	</choice>

	<choice
		id="Target.ESP"
		title="Target.ESP_title"
		description="Target.ESP_description"
		start_visible="true" start_selected="choicePreviouslySelected('org.clover.target.esp')"
		selected="choices['UEFI.only'].selected || choices['Target.ESP'].selected">
		<pkg-ref id="org.clover.target.esp"/>
	</choice>

	<choice
		id="BiosBoot"
		title="BiosBoot"
		description="BiosBoot"
		start_visible="false" start_selected="false">
		<pkg-ref id="org.clover.biosboot"/>
	</choice>

	<choice
		id="Utils"
		title="Utils"
		description="Utils"
		start_visible="false" start_selected="true">
		<pkg-ref id="org.clover.utils"/>
	</choice>

	<choice
		id="EFIFolder"
		title="EFIFolder"
		description="EFIFolder"
		start_visible="false" start_selected="true">
		<pkg-ref id="org.clover.efifolder"/>
	</choice>

	<choice
		id="off"
		title="off_title"
		description="off_description"
		start_visible="true" start_selected="choicePreviouslySelected('org.clover.off')">
		<pkg-ref id="org.clover.off"/>
	</choice>

	<choice
		id="Bootloader"
		title="Bootloader_title"
		description="Bootloader_description"
		enabled="!choices['UEFI.only'].selected" visible="!choices['UEFI.only'].selected">
	</choice>

	<choice
		id="AltBoot"
		title="AltBoot_title"
		description="AltBoot_description"
		start_selected="choicePreviouslySelected('org.clover.bootloader.altboot')" visible="choices['boot0af'].selected || choices['boot0ss'].selected"
		selected="!choices['UEFI.only'].selected &amp;&amp; choices['AltBoot'].selected">
		<pkg-ref id="org.clover.biosboot"/>
		<pkg-ref id="org.clover.utils"/>
		<pkg-ref id="org.clover.bootloader.altboot"/>
	</choice>

	<choice
		id="bootNo"
		title="bootNo_title"
		description="bootNo_description"
		enabled="!choices['UEFI.only'].selected" start_selected="choicePreviouslySelected('org.clover.bootloader.bootno') || checkBootFromUEFI()"
		selected="(choices['UEFI.only'].selected) || !(choices['boot0af'].selected || choices['boot0ss'].selected)">
		<pkg-ref id="org.clover.bootloader.bootno"/>
	</choice>

	<choice
		id="boot0af"
		title="boot0af_title"
		description="boot0af_description"
		enabled="!choices['UEFI.only'].selected" start_selected="choicePreviouslySelected('org.clover.bootloader.boot0af')"
		selected="!(choices['bootNo'].selected || choices['boot0ss'].selected)">
		<pkg-ref id="org.clover.biosboot"/>
		<pkg-ref id="org.clover.utils"/>
		<pkg-ref id="org.clover.bootloader.boot0af"/>
	</choice>

	<choice
		id="boot0ss"
		title="boot0ss_title"
		description="boot0ss_description"
		enabled="!choices['UEFI.only'].selected" start_selected="choicePreviouslySelected('org.clover.bootloader.boot0ss')"
		selected="!(choices['bootNo'].selected || choices['boot0af'].selected)">
		<pkg-ref id="org.clover.biosboot"/>
		<pkg-ref id="org.clover.utils"/>
		<pkg-ref id="org.clover.bootloader.boot0ss"/>
	</choice>

	<choice
		id="CloverEFI"
		title="CloverEFI_title"
		description="CloverEFI_description"
		enabled="!choices['UEFI.only'].selected" visible="!choices['UEFI.only'].selected"
		selected="!choices['UEFI.only'].selected">
	</choice>

	<choice
		id="rc.scripts.on.target"
		title="rc.scripts.on.target_title"
		description="rc.scripts.on.target_description"
		start_visible="true" start_selected="checkFileExists('/System/Library/CoreServices/boot.efi') &amp;&amp; choicePreviouslySelected('org.clover.rc.scripts.on.target')" start_enabled="checkFileExists('/System/Library/CoreServices/boot.efi')">
		<pkg-ref id="org.clover.rc.scripts.on.target"/>
	</choice>

	<choice
		id="rc.scripts.on.all.volumes"
		title="rc.scripts.on.all.volumes_title"
		description="rc.scripts.on.all.volumes_description"
		start_visible="true" start_selected="choicePreviouslySelected('org.clover.rc.scripts.on.all.volumes')">
		<pkg-ref id="org.clover.rc.scripts.on.all.volumes"/>
	</choice>

	<choice
		id="rc.scripts.core"
		title="rc.scripts.core"
		description="rc.scripts.core"
		start_visible="false"
		selected="choices['rc.scripts.on.target'].selected || choices['rc.scripts.on.all.volumes'].selected">
		<pkg-ref id="org.clover.rc.scripts.core"/>
	</choice>

	<choice
		id="OptionalRCScripts"
		title="OptionalRCScripts"
		description="OptionalRCScripts"
		enabled="choices['rc.scripts.core'].selected">
	</choice>

	<choice
		id="disable_sleep_proxy_client"
		title="disable_sleep_proxy_client_title"
		description="disable_sleep_proxy_client_description"
		start_selected="choicePreviouslySelected('org.clover.optional.rc.scripts.disable.sleep.proxy.client')" enabled="choices['OptionalRCScripts'].enabled">
		<pkg-ref id="org.clover.optional.rc.scripts.disable.sleep.proxy.client"/>
	</choice>

	<choice
		id="Themes"
		title="Themes_title"
		description="Themes_description">
	</choice>

	<choice
		id="Purple_Swirl"
		title="Purple_Swirl"
		description="Purple_Swirl"
		start_selected="choicePreviouslySelected('org.clover.themes.purple.swirl')">
		<pkg-ref id="org.clover.themes.purple.swirl"/>
	</choice>

	<choice
		id="Clovy"
		title="Clovy"
		description="Clovy"
		start_selected="choicePreviouslySelected('org.clover.themes.clovy')">
		<pkg-ref id="org.clover.themes.clovy"/>
	</choice>

	<choice
		id="BGM"
		title="BGM_title"
		description="BGM_description"
		start_selected="choicePreviouslySelected('org.clover.themes.bgm')">
		<pkg-ref id="org.clover.themes.bgm"/>
	</choice>

	<choice
		id="cesium"
		title="cesium_title"
		description="cesium_description"
		start_selected="choicePreviouslySelected('org.clover.themes.cesium')">
		<pkg-ref id="org.clover.themes.cesium"/>
	</choice>

	<choice
		id="CloverPrefpane"
		title="CloverPrefpane_title"
		description="CloverPrefpane_description"
		start_selected="checkFileExists('/bin/launchctl') &amp;&amp; choicePreviouslySelected('org.clover.cloverprefpane')" start_enabled="checkFileExists('/bin/launchctl')">
		<pkg-ref id="org.clover.cloverprefpane"/>
	</choice>

	<choice
		id="Post"
		title="Post"
		description="Post"
		start_visible="false" start_selected="true">
		<pkg-ref id="org.clover.post"/>
	</choice>

	<pkg-ref id="org.clover.pre" installKBytes='0' version='5126.0.0.1603332867'>#Pre.pkg</pkg-ref>
	<pkg-ref id="org.clover.uefi.only" installKBytes='4' version='5126.0.0.1603332867'>#UEFI.only.pkg</pkg-ref>
	<pkg-ref id="org.clover.target.esp" installKBytes='0' version='5126.0.0.1603332867'>#Target.ESP.pkg</pkg-ref>
	<pkg-ref id="org.clover.biosboot" installKBytes='40' version='5126.0.0.1603332867'>#BiosBoot.pkg</pkg-ref>
	<pkg-ref id="org.clover.utils" installKBytes='132' version='5126.0.0.1603332867'>#Utils.pkg</pkg-ref>
	<pkg-ref id="org.clover.efifolder" installKBytes='2056' version='5126.0.0.1603332867'>#EFIFolder.pkg</pkg-ref>
	<pkg-ref id="org.clover.off" installKBytes='0' version='5126.0.0.1603332867'>#off.pkg</pkg-ref>
	<pkg-ref id="org.clover.bootloader.altboot" installKBytes='0' version='5126.0.0.1603332867'>#AltBoot.pkg</pkg-ref>
	<pkg-ref id="org.clover.bootloader.bootno" installKBytes='0' version='5126.0.0.1603332867'>#bootNo.pkg</pkg-ref>
	<pkg-ref id="org.clover.bootloader.boot0af" installKBytes='0' version='5126.0.0.1603332867'>#boot0af.pkg</pkg-ref>
	<pkg-ref id="org.clover.bootloader.boot0ss" installKBytes='0' version='5126.0.0.1603332867'>#boot0ss.pkg</pkg-ref>
	<pkg-ref id="org.clover.rc.scripts.on.target" installKBytes='0' version='5126.0.0.1603332867'>#rc.scripts.on.target.pkg</pkg-ref>
	<pkg-ref id="org.clover.rc.scripts.on.all.volumes" installKBytes='0' version='5126.0.0.1603332867'>#rc.scripts.on.all.volumes.pkg</pkg-ref>
	<pkg-ref id="org.clover.rc.scripts.core" installKBytes='48' version='5126.0.0.1603332867'>#rc.scripts.core.pkg</pkg-ref>
	<pkg-ref id="org.clover.optional.rc.scripts.disable.sleep.proxy.client" installKBytes='0' version='5126.0.0.1603332867'>#disable_sleep_proxy_client.pkg</pkg-ref>
	<pkg-ref id="org.clover.themes.purple.swirl" installKBytes='608' version='5126.0.0.1603332867'>#Purple_Swirl.pkg</pkg-ref>
	<pkg-ref id="org.clover.themes.clovy" installKBytes='1004' version='5126.0.0.1603332867'>#Clovy.pkg</pkg-ref>
	<pkg-ref id="org.clover.themes.bgm" installKBytes='2736' version='5126.0.0.1603332867'>#BGM.pkg</pkg-ref>
	<pkg-ref id="org.clover.themes.cesium" installKBytes='712' version='5126.0.0.1603332867'>#cesium.pkg</pkg-ref>
	<pkg-ref id="org.clover.cloverprefpane" installKBytes='2140' version='5126.0.0.1603332867'>#CloverPrefpane.pkg</pkg-ref>
	<pkg-ref id="org.clover.post" installKBytes='0' version='5126.0.0.1603332867'>#Post.pkg</pkg-ref>

</installer-gui-script>
