#!/usr/bin/perl
 
use Sys::Syslog;
 
$PackageDir = shift || "/opt/SYMCScan";
 
$LockFile = "/tmp/SymScanEngineBusy.lock";
 
$LOCK_SH = 1;
$LOCK_EX = 2;
$LOCK_NB = 4;
$LOCK_UN = 8;
 
Sys::Syslog::openlog("SymScanEngine-autoupdate", 'pid, nowait', 'mail');
 
BailOut("Installation dir \"$PackageDir\" does not exist!")
  unless $PackageDir ne "" && -d $PackageDir;
 
&LockSymantec();
 
# Need to add code to dymanically locate the java binary
# SuSE has some info in /etc/java, is this a standard location for info?
$JavaDir="/usr/lib/j2sdk1.4.2_03/jre/bin/";
 
$ENV{'PATH'} .= ":$JavaDir";
system("$PackageDir/bin/liveupdate.sh -VIRUSDEFS -URLUPDATES");
&UnlockSymantec();
Sys::Syslog::syslog('info', "SymScanEngine updated in $PackageDir");
Sys::Syslog::closelog();
exit 0;
 
sub BailOut {
	Sys::Syslog::syslog('err', @_);
	Sys::Syslog::closelog();
	warn "@_, $!";
	exit 1;
}
 
sub LockSymantec {
	open(LOCK, ">$LockFile") or return;
	flock(LOCK, $LOCK_EX);
	print LOCK "Locked for updating SymScanEngine patterns by $$\n";
}
 
sub UnlockSymantec {
	print LOCK "Unlocked after updating SymScanEngine patterns by $$\n";
	unlink $LockFile;
	flock(LOCK, $LOCK_UN);
	close LOCK;
}

