Skip to content

Instantly share code, notes, and snippets.

@patgmac
Created March 23, 2018 19:48
Show Gist options
  • Save patgmac/2d6455f0872563daf4aa2efde324e791 to your computer and use it in GitHub Desktop.
Save patgmac/2d6455f0872563daf4aa2efde324e791 to your computer and use it in GitHub Desktop.
#!/bin/bash
###
#
# Name: mcafee_dat_updater.sh
# Description: Downloads latest McAfee AV DAT and installs
# Manual update instructions https://kb.mcafee.com/corporate/index?page=content&id=KB70253
# Author: Patrick Gallagher for The Home Depot
# Created: 03-23-2018
#
###
tmp_dir="/tmp/dat-update/"
datIni="${tmp_dir}avvdat.ini"
datDir="/usr/local/McAfee/AntiMalware/dats/"
if [[ ! -d $tmp_dir ]]; then
mkdir -p $tmp_dir
fi
if [[ -f "$datIni" ]]; then
rm "$datIni"
fi
# Download avvdat.ini to obtain the latest version number
curl -o $datIni http://update.nai.com/products/commonupdater/current/vscandat1000/dat/0000/avvdat.ini > /dev/null 2>&1
if [[ ! "$datIni" ]]; then
echo "Problem downloading avvdat.ini"
exit 1
fi
# For some reason, this adds a carriage return, so removing it with tr
DATVersion=$(cat $datIni | grep DATVersion | sed -n 1p | cut -c 12-)
DATVersion=$(echo $DATVersion | tr -d '\r')
echo "Latest DAT version is $DATVersion"
if [[ "$DATVersion" == "" ]]; then
echo "Error getitng DAT version"
exit 2
else
# Construct file name as it should appear on server
DAT="avvdat-${DATVersion}.zip"
echo "Filename will be $DAT"
fi
# Compare with already installed DAT version
currentDAT=$(/usr/bin/defaults read /Library/Preferences/com.mcafee.ssm.antimalware.plist Update_DATVersion | cut -b 1-4)
echo "Currently installed DAT is $currentDAT"
if [[ $currentDAT -ge $DATVersion ]]; then
echo "No update needed, exiting..."
rm -rf "$tmp_dir"
exit 0
fi
curl -o "${tmp_dir}${DAT}" http://update.nai.com/products/commonupdater/current/vscandat1000/dat/0000/${DAT} > /dev/null 2>&1
if [[ ! -f "${tmp_dir}${DAT}" ]]; then
echo "Problem downloading DAT"
exit 3
fi
/usr/local/McAfee/fmp/bin/fmp stop
launchctl unload /Library/LaunchDaemons/com.mcafee.ssm.ScanManager.plist
launchctl unload /Library/LaunchDaemons/com.mcafee.ssm.ScanFactory.plist
sleep 10
mkdir -p ${datDir}${DATVersion}
chmod 755 ${datDir}${DATVersion}
unzip -o "${tmp_dir}${DAT}" -d ${datDir}${DATVersion} > /dev/null 2>&1
if [[ ! -f ${datDir}${DATVersion}/avvnames.dat ]]; then
echo "Problem extacting files to DAT directory"
exit 4
fi
chmod 644 ${datDir}${DATVersion}/*.dat
chown root:Virex ${datDir}${DATVersion}/avv*
defaults write /Library/Preferences/com.mcafee.ssm.antimalware.plist Update_DATVersion -string $DATVersion.0000
/usr/local/McAfee/fmp/bin/fmp start
sleep 10
launchctl load /Library/LaunchDaemons/com.mcafee.ssm.ScanManager.plist
launchctl load /Library/LaunchDaemons/com.mcafee.ssm.ScanFactory.plist
# Cleanup
rm -rf ${tmp_dir}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment