Moka5
Moka5


Run host scripts on Mac or Windows host computers   « Go Back

Summary

Host scripts add flexibility for IT administrators to collect important host attributes and to perform critical checks and actions at Player start time. Results can be reported back to the Management Server. This article provides an overview of host script bundles and examples of how to implement them.

This feature is intended for Moka5 administrators with advanced scripting knowledge.

Applies to

  • Moka5 3.17 and later
  • Mac or Windows host computers

Table of Contents

Overview
Components of a host script bundle
Understanding the host script environment
How to deploy a host script bundle
How to retrieve information (reported by a host script) from the Management Server
Example #1: Collect host information: free disk space on Mac (simple version)
Example #2: Collect host information: free disk space on Mac (advanced version)

Overview

What can administrators do with host scripts?

Run a task or check for a condition that is specific to the company’s environment
  • Examples:
    • Make sure the host computer is connected to a specific SSID for guest wi-fi before allowing Moka5 to run
    • Present a custom EULA to the end user before starting Moka5 Player; track EULA acceptance from the Management Server
    • If company requires BYO users to have specific version of antivirus software on the host, check for that before allowing Moka5 to run
Deploy a workaround for a bug or implement a new feature not yet available in the current Moka5 release
  • Example: Disable a conflicting process or driver before a Moka5 patch is available
Collect data on endpoints and return it to the Moka5 Management Server
  • Examples:
    • Check OS version running on host computers
    • Check free disk space, memory, and CPU on host computers

How it works

The administrator creates a host script bundle (ZIP file) and uploads it to the Moka5 Management Server. The administrator then uses Player Policies to target the host script bundle to specific user groups. Moka5 delivers the host script bundle to the targeted users on their host computers as part of the Moka5 Player update process. On initial Player launch, the default set of host scripts is executed.

The next time the end user double-clicks the Moka5 Player icon:
  • Moka5 checks for the existence of a host script bundle
  • If found, the host script bundle will execute before the user sees the Moka5 Player authentication screen.

Components of a host script bundle

A host script bundle is a compressed zip file that contains the following components.

Component Description Notes
tasks.xml
This is the task configuration file for the host script bundle.
REQUIRED for all host script bundles
Host scripts
The most common types of scripts include bash, bat, Powershell,* and Python scripts. These require a script interpreter to be present on the host OS.

OPTIONAL
Examples:
  • Bash scripts work on Mac hosts by default
  • Bat scripts work on Windows hosts by default
Executables This can be a compiled program that performs the desired functions.

OPTIONAL
Data files This can include data or image files referenced by the host scripts or executables.

OPTIONAL

Note: Please note that administrators will need to create two separate host script bundles: one for Mac hosts and another for Windows hosts. tasks.xml may contain different file paths for Mac versus Windows. Also, host scripts and executables may need to be platform-specific.

*Running Powershell scripts

Powershell scripts will run on Windows hosts, but must be enabled first. Use the following commands to enable Powershell scripts:

On 64-bit hosts:
%SystemRoot%\syswow64\Windowspowershell\v1.0\powershell.exe Set-ExecutionPolicy Unrestricted -Force

On 32-bit hosts:
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe Set-ExecutionPolicy Unrestricted -Force

Understanding the host script environment

Tasks

  • Tasks are the individual actions that you want to run on the host computer. These can be specified within tasks.xml by:
    • Using a command (contained within the tasks.xml entry)
    • Calling a host script (file contained within the host script bundle)
    • Calling an executable (file contained within the host script bundle)
  • You can specify multiple tasks in the same tasks.xml file.

Tags

Tag Comments
Tasks Task container
Task (Attributes: name_id: This is unique to each task, and version: This is the task version, and is uploaded as part of data collection.)

This tag declares tasks to execute.
Enable The task is executed if the "enable" value is set to "true." If this tag is missing, the task will not execute.
command Commands the executable or script to run.

This tag is case-sensitive on Macs.
context The only supported context is "user."
launch The only supported context is "on Player start." Host scripts run on Player start, before a user logs in.
run_player Controls the execution of Player launch (see the description below).
Output This tag declares information that is output from a host script.
file The host script outputs to a file.
name The file name.
format The output type ("kvp" or "raw." For more information, see the description below).
stdout The host script outputs to stdout.


Environment Variables

Moka5 provides some environment variables for use in host scripts.
Variable Name Description
M5_BIN Returns the Moka5 bin directory on Windows hosts, or the app bundle on Mac hosts (for example: C:\Program Files\MokaFive\bin).
M5_VERSION Returns the Moka5 Player version (for example, 4.1.0.69772).


Output

Tasks can output in one of two formats:

Raw

Declare this format with the "raw" keyword in the tasks.xml file.
  • Example: list of all files in a directory
  • Example of the tasks.xml file syntax with "raw" output:
<task version=”12_09_2013” name_id=”disk_free_mac2”>
<enable>true</enable>
<command>./disk_check.sh</command>
<context>user</context>
<launch>on player start</launch>
<output>
<stdout>
<format>raw</format>
</stdout>
</output>
</task>

Key-value pairs

  • Key-value pairs are sets of data items: a unique identifier for some data, or a “Key,” and the state or content of the data itself, or “Value.” They are denoted by two items connected with an “=” sign: Key=Value.
  • Key-value pairs are written to the local property stack and sent to the Management Server
    • The first time key-value pairs are sent, it can take a few minutes after authentication for the send to complete. After that, whenever value changes and you restart your Moka5 Player, the key-value pairs are re-sent.
    • The key-value pair format is declared by the “kvp” keyword in the tasks.xml file.
<task version=”12_09_2013” name_id=”disk_free_mac2”><enable>true</enable>
<command>eula-app.exe</command>
<context>user</context>
<launch>on player start</launch>
<output>
<stdout>
<format>kvp</format>
</stdout>
</output>
</task>

Tasks can consider the result of a previous run of the host script bundle

Since a host script bundle will attempt to run every time the end user launches Moka5 Player, the administrator may want a task to consider the result of the previous run before taking new action. This can be done by using previously outputted key-value pairs as input in the next run of the host script bundle. This can be declared in the tasks.xml file by using an “env=true” format tag.

<?xml version="1.0" encoding="UTF-8"?>
<tasks>
<task name_id="hello" version="05_21_2014">
<enable>true</enable>
<command>win_run.bat</command>
<context>user</context>
<launch>on player start</launch>
<run_player>true</run_player>

<output>
<file>
<name>win_comp_check.out</name>
<format env=”true”>kvp</format>
</file>
</output>
</task>
</tasks>


Note: To specify key-value pairs as the output format, you must include the content in the <output> tags.

Workflow

On first run:
  • There are no previously outputted key-value pairs to consider, so the task will execute without this input.
  • The host script bundle generates a key-value pair, stored in the local property stack and sent to the server.
On following runs:
  • The previously outputted key-value pair is provided as an environment variable and input to the host script bundle. The script can use environment variable M5HS_Key and make appropriate decision.
<?xml version="1.0" encoding="UTF-8"?>
<tasks>
<task name_id="hello" version="05_21_2014">
<enable>true</enable>
<command>win_run.bat</command>
<context>user</context>
<launch>on player start</launch>
<run_player>true</run_player>
<output>
<file>
<name>win_comp_check.out</name>
<format env=”true”>kvp</format>
</file>
</output>
</task>
</tasks>
  • The host script bundle generates a key-value pair, stored in the local property stack and sent to the server.
Further script examples can be found in the attachment to this KB (scroll to the bottom of this page).

Control over Moka5 Player

An administrator may want to prevent Moka5 Player from launching if certain host conditions are not met, e.g. sufficient free disk space, required antivirus software installed on host, etc.
WARNING – Be very, very careful when using this feature. Please test extensively before deploying to end users since this can prevent users from launching Moka5.
You can control launching of Moka5 Player, by including the following line in tasks.xml:

<?xml version="1.0" encoding="UTF-8"?>
<tasks>
<task name_id="hello" version="05_21_2014">
<!-- This task checks for Windows Version, Firewall status, Patch Status and AntiVirus status -->
<enable>true</enable>
<command>win_run.bat</command>
<context>user</context>
<launch>on player start</launch>
<run_player>true</run_player>
<output>
<file>
<name>win_comp_check.out</name>
<format>kvp</format>
</file>
</output>
</task>
</tasks>
The tasks.xml file can contain multiple tasks. If a task includes “<run_player>false</run_player>,” it will not execute any tasks in the file after that entry. Data will be collected on all tasks in the file, even those which are not run.
  • If this tag is present, then output is checked for presence of the [RUN_PLAYER=True] key-value pair.
  • If this is not present, then Moka5 Player is not launched.

How to deploy a host script bundle

Log in to the Moka5 Management Console with an account that has Desktop Administrator role permissions.

Upload the host script bundles. Do this for both Windows and Mac zip files.
  • Go to Settings > Customizations > Host Scripts tab.
  • Click the Upload button.
  • For bundle name, enter <script name_platform> (Example: EULA_Win)
  • Browse to your newly created zip file and Click Upload.
Target the host script bundles to a pilot user group
  • Go to Policies > Player Policies > Custom tab
  • Select the pilot user group you wish to target.
  • For the policy “Custom host script for Windows” select <script name_Win> from the pull-down menu.
  • For the policy “Custom host script for Mac” select <script name_Mac> from the pull-down menu.
  • Click Save.
On each of the target computers in your pilot group:
  • Shut down the LivePC.
  • Go to the Player menu > Check for updates.
  • You will see a message in the yellow notification bar, “MokaFive Player update available.”
  • Click Update Now, and then click Yes.
  • Launch Moka5 Player.
  • The host script will now run.
  • Note: If you are delivering an update to existing host scripts after installation, you must enable the "Player auto-update" policy for your pilot user group. Restart the player to ensure that the policy update takes effect.

How to retrieve information (reported by a host script) from the Management Server

Obtain the Device Properties Report

  • Log in to the Management Console with an account that has Desktop Administrator or Report Viewer role permissions.
  • Go to Reports > Devices.
  • Click the Export Properties to CSV button.
  • Download and save the file mokafive_deviceproperties<date>.csv.

How to interpret the MokaFive_Device_Properties csv report

When you open the CSV file in Excel, you will see a report with various columns. The following are descriptions of the main fields.
  • deviceid – This is a unique identifier for a host computer. This report contains key/value pairs that correspond to a deviceid.
  • namespace – This corresponds to the name_id you specified in tasks.xml.
  • key – You specified this to output in your host script bundle.
  • value – You specified this to output in your host script bundle.

Example #1 - Collect host information: free disk space on Mac (simple version)

Download the full host script bundle for Example #1
  • The host script bundle is a zip file named disk_details_mac.zip.
  • Applies to Mac hosts (not Windows hosts).
  • This example collects free disk space on Mac hosts and reports the information to the Moka5 Management Server.
    • The task gets all the details like total disk size, disk used, disk free for the disk on which current working directory is present.
  • The zip file contains:
    • tasks.xml
  • The task is executed using a command in tasks.xml.
  • The output is raw format.


Example #2 - Collect host information: free disk space on Mac (advanced version)

Download the full host script bundle for Example #2
  • The host script bundle is a zip file named disk_free_mac.zip.
  • Applies to Mac hosts (not Windows hosts).
  • This example collects free disk space on Mac hosts and reports the information to the Moka5 Management Server.
    • The improvement over the simple version is that the disk_check.sh script parses out extraneous information and reports the data as key-value pairs, making the data easier to read and consume.
  • The zip file contains:
    • tasks.xml
    • disk_check.sh
  • The task is executed using the host script file, disk_check.sh
  • The output is key-value pair format.