HEX
Server: LiteSpeed
System: Linux s3604.bom1.stableserver.net 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: dmstechonline (1480)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //lib64/nagios/plugins/check_a2_softy_version.sh.shared.mvps.mdedi
#!/bin/bash
#
# Compare installed and latest version of Softaculous

# Fetch latest version
_latest_version=$(curl --silent "https://api.softaculous.com/updates.php?version=latest&panel=cpanel&in=json" | jq -r '.version' 2>/dev/null)
# Fetch installed version
_installed_version=$(/usr/local/cpanel/3rdparty/bin/php /usr/local/cpanel/whostmgr/docroot/cgi/softaculous/cli.php --version 2>/dev/null)

_main(){
  # Check if Softy is installed
  if [[ ! -d "/usr/local/cpanel/whostmgr/docroot/cgi/softaculous" ]]; then
    echo "Softaculous is not installed!"
    exit 2
  fi

  # Compare versions using awk to handle decimal numbers
  if awk -v latest="${_latest_version}" -v installed="${_installed_version}" 'BEGIN{if (installed < latest) exit 0; exit 1}'; then
    echo "Softaculous version is outdated: ${_installed_version} (latest version is: ${_latest_version})"
    exit 2
  else
    echo "Softaculous version is updated: ${_installed_version}"
    exit 0
  fi

  # Save installed version and timestamp to the separate version cache
  echo "${_installed_version} $(date +%s)" > "${_version_cache}"
}

_main