#!/bin/bash


if [[ -e "/Applications/ESET Endpoint Antivirus.app" ]]; then
   APP="ESET Endpoint Antivirus.app"
fi


if [[ -e "/Applications/ESET Endpoint Security.app" ]]; then
   APP="ESET Endpoint Security.app"
fi


if [[ -z "$APP" ]]; then
   echo "No ESET Endpoint protection"
else
   if [[ "$APP" == "ESET Endpoint Antivirus.app" ]]; then ESET="EEA"; fi
   if [[ "$APP" == "ESET Endpoint Security.app" ]]; then ESET="EES"; fi
   if [[ -e "/Applications/ESET Endpoint Antivirus.app/Contents/MacOS/odscan" ]]; then
       AVSigsVer=$(/Applications/ESET\ Endpoint\ Antivirus.app/Contents/MacOS/upd --list-module | grep "Detection engine" | sed -r 's/^EM.*\ (.*\ \(.*\)).*Detection\ engine$/\1/')
       ClientVer=$(/Applications/ESET\ Endpoint\ Antivirus.app/Contents/MacOS/odscan --version | sed -r 's/^\/Applications\/ESET\ Endpoint\ Antivirus\.app\/Contents\/MacOS\/odscan\ \(eea_mac\)\ (.*)$/\1/')
       Activation=$(/Applications/ESET\ Endpoint\ Antivirus.app/Contents/MacOS/lic --status | grep "Status" )
       echo "$ESET $ClientVer $AVSigsVer $Activation"
   else
       Status="$(mktemp -q /tmp/ESETstatus.XXXXX)"
       /Applications/"$APP"/Contents/MacOS/esets_daemon --status > $Status
       AVSigsVer=$(grep AVSigsVer $Status | sed 's/AVSigsVer=//g')
       ClientVer=$(grep ClientVer $Status | sed 's/ClientVer=//g')
       Activation=$(grep Activation $Status | sed 's/Activation=//g')
       echo "$ESET $ClientVer $AVSigsVer $Activation"
       rm -f $Status
   fi
fi