Aiden
Ramirez

Using pre/post app installation scripts

Aiden Ramirez

May 8, 2023

12 min read

“An error occurred while installing the application.”

“The application can’t be opened.”

These words are one of the worst nightmares of all IT admins. Enough to drive someone into a state of confusion, thinking about what they missed. In addition, every app will have its own set of requirements to run correctly. Making sure all these prerequisites are satisfied fulfilled in all devices can be a daunting task. Being an IT admin is not easy😪. ‘Pat pat’ to you folks.

Alright, let’s say you managed to install the application. Is the job done? I’m afraid not. You might have to ensure all the necessary features are turned on before launching the app. Seems like too much work? Getting an application to work correctly shouldn’t be this hard, right? So, what is the solution?

(Read in Al Pacino’s voice) Say hello to my little friend- pre and post app install scripts.

Scripting made simple

Since my “catchy” intro is over, let’s look at what precisely are these pre and post app installation scripts and why we might need them.

A script is a series of commands written in a scripting language that details the operations you want to perform on your computer devices and automatically executes it on the devices without any manual intervention. IT admins will have to manually administrate these tasks one by one on each device. Hence, IT admins majorly turn to scripts to execute specific routines and time-consuming operations.

Pre/post app installation scripts is a new feature for macOS devices, available now in the Hexnode portal. This feature allows you to customize your enterprise app installation process. For example, you can add custom-made scripts as pre-install scripts and post-install scripts while pushing an application management policy into the devices. Pre-install scripts run before the app installation, and post-install scripts run once the installation process is complete.

Knowing more about pre/post app install scripts

Pre-install scripts

Pre-install scripts perform an action before installation occurs. For example, IT admins can use it to set up all the necessary prerequisites before executing the dmg/pkg file that installs the application. If the pre-install script fails to execute, it will cease the installation process and send an error message to the server.

Before installing your applications, you might have to perform cleanup tasks such as clearing all the cached data. Let’s see how you can automate this process by executing a bash script for cleaning cache data as a pre-install script.

When added as the pre-install script, this bash script clears the system cache, browser cache, user cache, download history, and terminal history before app installation.

You can also use pre-install scripts to do other cleanup tasks, such as removing licensing and clearing database files. Apart from this, you can use pre-install scripts to run configuration files to configure applications automatically during installation. When installation occurs, the installer finds the configuration files already placed to facilitate this process.

Post-install scripts

The Post-install script runs after the execution of the dmg/pkg/mpkg file. You can use it for applying configurations after the software completes the installation. Tasks that would typically be prompted for the user to resolve before running the app can be automated by using these scripts.

Consider the situation where the user has to launch the app you just installed every time they turn on their devices. Having these apps automatically opened as soon as the user logs in will be convenient. Again, you can deploy a script for this as the post-install script to your device fleet.

Replace app_name in the script with the name of the application you require to launch automatically and specify the full path of the executable file for the application under the key. This script will create a launch agent for the specified app in /Library/LaunchAgents and run for every user account upon logging in.

You can also set up custom app configurations, Wi-Fi settings, VPN settings, and so on by post-install scripting.

Audit scripts

An audit script checks the installation status of the enterprise app. The script can check for required files, settings, apps and more to find all possible errors. The audit script would check for the presence of an app at the specified location. If it is not present, the script will prompt Hexnode to reinstall it.

Configuring pre/post app installation scripts

Configuring pre-install, post-install and audit scripts using Hexnode won’t take much time if you have your apps and scripts in hand. Feel free to check out Hexnode’s sample script repository if you need help creating your scripts.

Pre-requisites

  • Works on macOS 10.11+.
  • Supported file formats include Perl (.pl), Bash (.sh), Shell (.sh), C Shell (.csh), Zsh (.zsh), Korn Shell (.ksh), Hypertext Preprocessor (.php), Ruby (.rb), and Python (.py).
  • The binary required to run the script must be installed on the Mac.
  • The latest version of the Hexnode MDM app should be installed on the device.

To configure your app installation,

  1. Login to your Hexnode portal and navigate to Policies-> New policy-> New blank policy.
  2. In the macOS tab, go to Mandatory Apps under the App Management section.
  3. Click on Configure and add your respective enterprise app.
  4. Click on the Configure button next to the enterprise app name.
  5. In the pop-up window that appears, upload the pre-install, post-install and audit scripts according to your requirement.

Binary path

It will depend on the shell you are using. Some common shells and their binary paths are;

  • Bash: /bin/bash
  • Perl: /usr/bin/perl
  • Shell: /bin/sh
  • C Shell: /bin/csh
  • Zsh: /bin/zsh
  • Korn Shell: /bin/ksh
  • Python: /usr/bin/python
  • Hypertext Preprocessor: /usr/bin/php
  • Ruby: /usr/bin/ruby

Argument

An argument is a value we may pass to our script when it executes. Arguments let a user dynamically change the actions a script takes or the results it produces. You may use any number of arguments for executing the scripts by separating each with a space.

Once you upload the files and enter the necessary details, click Save and add the policy to your target devices. This action will initiate the execution of the pre-install script, followed by app installation. You can check the installation status from the Action history of your device under the Manage section.

Implementation

The implementation of the app install happens in 4 stages after configuring all the scripts and arguments from the portal. One stage starts after the completion of the ongoing stage. If any stages fail, the action stops and acknowledges the server with error codes and output, if available.
Let’s see the steps involved in this process:

  1. Execute the pre-install script. Once the execution is a success, it triggers the app installation.
  2. Actual installation of the app happens in this stage.
  3. Once the installation is completed, the post-install script is executed.
  4. Audit script runs to check if all stages are completed and acknowledges the server.
Featured resource

Hexnode Mac management solution

Get started with Hexnode’s Mac Management solution to save your time and the associated IT operational costs of managing your Mac devices.

DOWNLOAD DATASHEET

Conclusion

Enterprise applications play a significant role in improving workflows and increasing employee productivity across almost all organizations. However, it’s crucial to ensure that you cover all app requirement checkboxes to ensure its proper functioning. Scripts can be a powerful weapon in your arsenal if you want to automate mundane tasks. In addition, pre/post app install scripts further simplify the process as it is incorporated within the app installation process.

With Hexnode, you get much more than being able to customize enterprise app installation. Hexnode lets you have greater control over your enterprise applications through policies such as blacklisting, whitelisting and having customized app catalogs. It also offers a wide range of device management features that gives you complete control over your organization’s fleet of devices. Rather than me explaining all of this, it’s better that you realize it yourself. So go ahead and sign up for the free trial to experience Hexnode’s capabilities.


Disclaimer

The Sample Scripts provided here are adapted from third-party Open-Source sites. We recommend you to manually validate the script execution on a system before executing the action in bulk.

Share
Aiden Ramirez

Product Evangelist @ Hexnode. Hey Ferb, I know what we're gonna do today!

Share your thoughts