<?xml version="1.0" encoding="utf-8"?>
<installer-gui-script minSpecVersion="2">
    <product id="com.sagexrt.unisignmacos" version="1.0"/>
    <title>Sage eID Sign</title>
    <domains enable_localSystem="true"/>
    <options allow-external-scripts="yes" customize="never" require-scripts="true" rootVolumeOnly="true" hostArchitectures="x86_64"/>
    <choices-outline>
        <line choice="default">
            <line choice="com.sagexrt.unisignmacos"/>
        </line>
    </choices-outline>
    <choice id="default" title="Sage.Eb.UniSign.Macos" versStr="1.0"/>
    <choice id="com.sagexrt.unisignmacos" title="Sage.Eb.UniSign.Macos" visible="false" customLocation="/Applications">
        <pkg-ref id="com.sagexrt.unisignmacos"/>
    </choice>
    <pkg-ref id="com.sagexrt.unisignmacos" version="2.0.0" onConclusion="none" installKBytes="51891">#com.sagexrt.unisignmacos.pkg</pkg-ref>
    <pkg-ref id="com.sagexrt.unisignmacos">
        <bundle-version>
            <bundle CFBundleShortVersionString="2.0" CFBundleVersion="2.0" id="com.sagexrt.unisignmacos" path="Sage.Eb.UniSign.Macos.app"/>
        </bundle-version>
    </pkg-ref>
    <installation-check script="installation_check()"/>
    <volume-check script="volume_check()">
        <allowed-os-versions>
            <os-version min="10.10"/>
        </allowed-os-versions>
    </volume-check>
    <script><![CDATA[

		function installation_check() 
		{
			if (system.files.fileExistsAtPath('/Library/LaunchAgents/Sage.Eb.UniSign.Macos.plist') == true)
		    {
		    	// On arrête l'ancien service
		    	system.run('/bin/sh', '-c','echo "Unload Agent..." >> /tmp/Sage.Eb.UniSign.Macos.install.log; exit 0');
		
		    	exit_code = system.run('/bin/sh', '-c','launchctl unload "/Library/LaunchAgents/Sage.Eb.UniSign.Macos.plist"; exit 0');
	    		if (exit_code != 0) 
	    		{
	        		// need to set error type
	        		my.result.type = "Fatal";
	        		my.result.message = "Unable to stop agent Sage.Eb.UniSign.Macos process - rc = " + exit_code;
	        		return false;
	    		}
    		}
		    return true;
		}

		function volume_check() 
		{
			return true;
		}

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