1. Home
  2. SureMDM
  3. Linux Management
  4. How to update SureMDM agent on Linux devices.

How to update SureMDM agent on Linux devices.

KB ID: 42G2012868
Views: 790
Updated: August 2021

Updated versions of products have new features and improvised performance and it is always preferred to have the latest version of the product installed on the device. Better if this could be done remotely. SureMDM provides this feature on Linux devices. 
Please follow the below-mentioned steps to update the SureMDM agent on Linux devices. 

Steps:

1. Log into SureMDM Console.

2. Click on Jobs and Navigate to New Job.

3. Select the OS as Linux.

4. Click on Run Script jobs

5. Enter the Job name and below script in the script section.

#!/bin/bash

NIX_DEFAULT_LOCATION="https://suremdm.42gears.com/nix/nix.tar.gz"

if [ "$EUID" -ne 0 ]
  then echo "Permission denied. Please run as root."
  exit 126
fi

if [ ! -f "/usr/share/java/nix/nix.jar" ]; then
    echo "Cannot find existing nix @ /usr/share/java/nix/nix.jar"
    echo "Nothing to upgrade. Exiting..."
    exit 1
fi

rm nix.tar.gz
rm -rf ./nix

if [ -z "$1" ]; then
    wget $NIX_DEFAULT_LOCATION
else
    wget $1
fi

if [ ! -f "nix.tar.gz" ]; then
    echo "Cannot Download Nix package. Please check your Internet connection or download URL."
    echo "Exiting"
    exit 1
fi

tar -xvzf nix.tar.gz

# Backup Existing Nix Installation in-case something goes wrong - 
BACKUP_FILE=$HOME"/nix_backup_date_"$(date '+%d%b%Y_%H%M%S')".tar.gz"
echo "Backing up to $BACKUP_FILE"
tar -zcvf $BACKUP_FILE /usr/share/java/nix/

if [ -f "$BACKUP_FILE" ]; then
	echo "Nix backup location: $BACKUP_FILE"
else
    echo "Could not create backup file $BACKUP_FILE. Exiting..."
    exit 1
fi

if [ ! -d "/usr/share/java/nix/lib" ]; then
    mkdir /usr/share/java/nix/lib
    chmod -R 0750 /usr/share/java/nix/lib
    chown root:root /usr/share/java/nix/lib
fi

cp nix/app/*.jar /usr/share/java/nix/
cp nix/app/lib/*.jar /usr/share/java/nix/lib/

sleep 5 && service nix restart && service nixr restart &

echo "Upgrade Complete"

Note: Ensure the script has the proper downloadable link of the latest version of SureMDM Agent for Linux.

6. Save the job and apply it to the device in the device grid.

This will upgrade the SureMDM Agent for Linux to the latest version on the device. 

Note:  If an admin is using advanced settings in the Run-script screen, below are the values to be entered for the requested parameters. 

  • File Name: tar -xvzf nix.tar.gz
  • Default path: Admin can enter the path where the older version of the SureMDM agent is copied on the device. This is optional. 
  • Permission: Admin can enter 777 to grant permissions to the SureMDM agent all the necessary permissions. This is optional.

For more details on SureMDM Linux, click here.
For more details on our products, click here
If you need further assistance, please submit a ticket here   

Related Articles