1. Home
  2. Knowledge Base
  3. SureMDM
  4. Linux Management
  5. How to update the SureMDM Agent on Linux devices

How to update the SureMDM Agent on Linux devices

Product updates include new features and better performance. It is always preferable to have the most recent version of the product installed on the device, preferably remotely. SureMDM offers this feature on Linux devices.

Purpose

The purpose of this knowledge article is to provide a guide on how to update the SureMDM Agent on Linux devices.

Prerequisites

NA

Steps

1. Log into the SureMDM Console.

2. Click on Jobs and navigate to New Job.

3. Select the OS as Linux.

4. Click on Run Script Job.

5. Enter the job name and the below script in the run 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

DPKG=$(type -p dpkg)

installDPKGs() {
    #For Package integrity check
    REQUIRED_PKG_DEBSUMS="debsums"
    DEBSUMS_PKG_OK=$(dpkg-query -W --showformat='${Status}\n' $REQUIRED_PKG_DEBSUMS|grep "install ok installed")
    if [ "" = "$DEBSUMS_PKG_OK" ]; then
	apt-get --yes install $REQUIRED_PKG_DEBSUMS
    fi
}

if [ ! -z  $DPKG ]; then
  installDPKGs
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

SCRIPT_PATH="nix/upgradenixdynamic.sh"

source $SCRIPT_PATH

echo "Upgrade Complete"

Note: Ensure the script has the proper downloadable link to 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 for all the necessary permissions. This is optional.

Need help? CONTACT US 

Was this helpful?
YesNo
Updated on November 2023