Mac – JavaScript – Citrix Workspace Client

email me

I took this JS from the Distribution file in the latest Citrix Workspace Mac install, v24.05.0. Maybe you’ll find the internal workings interesting. I do.

Located: Citrix.dmg\Citrix Workspace\Install Citrix Workspace.pkg\Distribution

I ended up packaging the DMG into a PKG, signing the PKG, and publishing to Macs from Intune.

 

Code.js

 

# MrNetTek  
# eddiejackson.net  
# 7/31/2024

function compatibleOSVersionCheck() {
    system.log('Starting compatibleOSVersionCheck');
    system.log('System Product Version: ' + system.version.ProductVersion);
    if (system.compareVersions(system.version.ProductVersion, "12.0") < 0) {
        system.log('Product version Test failed');
        my.result.title = system.localizedString("InstallCheckFailedTitle");
        my.result.message = system.localizedString("InstallCheckFailedMessage");
        my.result.type = "Fatal";
        return false;
      }
     return true;
  }

function canUpgradeWorkspace() {
    var bundleWorkspace = system.files.bundleAtPath('/Applications/Citrix Workspace.app');
    if (bundleWorkspace) {
        var installedWorkspaceVersion = bundleWorkspace['CitrixVersionString'];
        system.log('Installed workspace version : ' + installedWorkspaceVersion);
        if (installedWorkspaceVersion && system.compareVersions(installedWorkspaceVersion, '24.05.0.89') > 0) {
            my.result.title = system.localizedString("PreventDowngradeTitle");
            my.result.message = system.localizedString("PreventDowngradeMessage");
            my.result.type = "Fatal";
            return false;
           }
      }
            return true;
  }

function canInstallWorkspaceOnExistingEnterpriseBrowser() {
    var bundleHelper = system.files.bundleAtPath('/usr/local/libexec/Citrix Workspace Helper.app');
    if (bundleHelper) {
        var minWorkspaceAppVersionSupported = '24.05.0.0';
        var plistPath = '/Library/Preferences/com.citrix.apps.configuration.plist';
        var plistfileExist = system.files.fileExistsAtPath(plistPath);
        if (plistfileExist) {
            var plistContent = system.files.plistAtPath(plistPath);
                if (plistContent) {
                    minWorkspaceAppVersionSupported = plistContent['minWorkspaceAppVersionSupported'];
                        if (minWorkspaceAppVersionSupported && system.compareVersions(minWorkspaceAppVersionSupported, '24.05.0.89') > 0) {
                            my.result.title = system.localizedString("PreventWorkspaceInstallationTitle");
                            my.result.message = system.localizedString("PreventWorkspaceInstallationMessage");
                            my.result.type = "Fatal";
                            return false;
                        }
                    }               
               }    
        }
            return true;
  }

function canUpgradeEnterpriseBrowser() {
    var bundleHelper = system.files.bundleAtPath('/usr/local/libexec/Citrix Workspace Helper.app');
    if (bundleHelper) {
        var installedEnterpriseBrowserVersion = bundleHelper['CitrixVersionString'];
        system.log('Installed enterprise browser version : ' + installedEnterpriseBrowserVersion);
        if (installedEnterpriseBrowserVersion && system.compareVersions(installedEnterpriseBrowserVersion, '24.05.0.89') > 0) {
            my.result.title = system.localizedString("PreventDowngradeTitle");
            my.result.message = system.localizedString("PreventDowngradeMessage");
            my.result.type = "Fatal";
            return false;
           }
      }
         return true;
  }

function canInstallEnterpriseBrowserOnExistingWorkspace() {
    var bundleWorkspace = system.files.bundleAtPath('/Applications/Citrix Workspace.app');
    if (bundleWorkspace) {
        var installedWorkspaceVersion = bundleWorkspace['CitrixVersionString'];
        system.log('Installed workspace version : ' + installedWorkspaceVersion);
        if (installedWorkspaceVersion) {
            if (system.compareVersions(installedWorkspaceVersion, '24.05.0.89') > 0 || system.compareVersions(installedWorkspaceVersion, '24.05.0.0') < 0) {
                my.result.title = system.localizedString("PreventBrowserInstallationTitle");
                my.result.message = system.localizedString("PreventBrowserInstallationMessage");
                my.result.type = "Fatal";
                return false;
                 }
            }
       }
            return true;
  }

function preventDowngrade() {               
    if ('cwa' == "ceb") {
        system.log('Package enterprise browser version : ' + '24.05.0.89');
        var canInstallEnterpriseBrowserOnExistingWorkspace_ = canInstallEnterpriseBrowserOnExistingWorkspace();
        var canUpgradeEnterpriseBrowser_ = canUpgradeEnterpriseBrowser();
        return canInstallEnterpriseBrowserOnExistingWorkspace_ && canUpgradeEnterpriseBrowser_;         
        }
    else {        
        system.log('Package Workspace version : ' + '24.05.0.89');
        var canUpgradeWorkspace_ = canUpgradeWorkspace();
        var canInstallWorkspaceOnExistingEnterpriseBrowser_ = canInstallWorkspaceOnExistingEnterpriseBrowser();  
        return canUpgradeWorkspace_ && canInstallWorkspaceOnExistingEnterpriseBrowser_; 
            }           
        return true;
   }

function compatibleOSVersionCheckAndPreventDowngrade() {
    // Check if CWA can be installed on the machine OS.
    system.log('Checking compatible macOS versions');
    var didSucceed = compatibleOSVersionCheck();
    system.log('Result of compatible macOS version check ' + didSucceed);

    // Check if the installed CWA is higher version than the one in this package.
    if (didSucceed) {
    system.log('Checking if higher version of CWA is already installed');
    didSucceed = preventDowngrade();
    system.log('Result of Downgrade Prevention check ' + didSucceed);
    }
    return didSucceed;
  }


 
 
 

Script Breakdown

 

# 1 compatibleOSVersionCheck()
This function checks if the operating system version is compatible with the required version (12.0 or higher).

– Logs the start of the check.
– Logs the current system version.
– Compares the current system version with “12.0”. If it’s lower, it logs a failure message, sets the result to fatal, and returns `false`.
– Returns `true` if the version is compatible.

 

# 2 canUpgradeWorkspace()
This function checks if the installed Citrix Workspace version can be upgraded.

– Gets the bundle information for Citrix Workspace.
– Logs the installed version.
– Compares the installed version with “24.05.0.89”. If the installed version is higher, it logs a message, sets the result to fatal, and returns `false`.
– Returns `true` if the upgrade is possible.

 

# 3 canInstallWorkspaceOnExistingEnterpriseBrowser()
This function checks if Citrix Workspace can be installed on an existing Enterprise Browser.

– Gets the bundle information for Citrix Workspace Helper.
– Checks for a configuration file and reads the minimum supported version.
– Compares the minimum supported version with “24.05.0.89”. If the minimum version is higher, it logs a message, sets the result to fatal, and returns `false`.
– Returns `true` if the installation is possible.

 

# 4 canUpgradeEnterpriseBrowser()
This function checks if the installed Enterprise Browser version can be upgraded.

– Gets the bundle information for Citrix Workspace Helper.
– Logs the installed version.
– Compares the installed version with “24.05.0.89”. If the installed version is higher, it logs a message, sets the result to fatal, and returns `false`.
– Returns `true` if the upgrade is possible.

 

# 5 canInstallEnterpriseBrowserOnExistingWorkspace()
This function checks if the Enterprise Browser can be installed on an existing Citrix Workspace.

– Gets the bundle information for Citrix Workspace.
– Logs the installed version.
– Compares the installed version with “24.05.0.89” and “24.05.0.0”. If the version is outside this range, it logs a message, sets the result to fatal, and returns `false`.
– Returns `true` if the installation is possible.

 

# 6 preventDowngrade()
This function prevents downgrading of the software.

– Checks if the package is for the enterprise browser.
– Calls the appropriate functions to check if the installation or upgrade is possible.
– Returns `true` if both checks pass.

 

# 7 compatibleOSVersionCheckAndPreventDowngrade()
This function combines the OS version check and downgrade prevention.

– Logs the start of the OS version check.
– Calls compatibleOSVersionCheck() and logs the result.
– If the OS version check passes, it calls `preventDowngrade()` and logs the result.
– Returns the final result of the checks.

 

 

How I Package for Deployment

 

The Packages App > Add Citrix.dmg to Payload – Applications folder > Add Code.sh to Scripts – Post-installation > Build PKG > Sign PKG > Upload to Intune > Test in Company Portal

 

Code.sh
 

#!/bin/bash

cd /Applications

hdiutil attach -nobrowse '/Applications/Citrix.dmg'
ditto '/Volumes/Citrix Workspace/Uninstall Citrix Workspace.app' '/Applications/Uninstall Citrix Workspace.app'
installer -pkg '/Volumes/Citrix Workspace/Install Citrix Workspace.pkg' -target /
hdiutil detach '/Volumes/Citrix Workspace'
rm /Applications/Citrix.dmg