File: kaspersky-autoupdate

package info (click to toggle)
mailscanner 4.79.11-2.2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 5,820 kB
  • ctags: 1,309
  • sloc: perl: 25,655; sh: 2,666; xml: 624; makefile: 242
file content (93 lines) | stat: -rwxr-xr-x 2,592 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/perl

use Sys::Syslog;

# Note that there are shell bugs in the kavupdater.sh where they have used
# == instead of = for comparing numbers.
$PackageDir = shift || "/opt/AVP";
$KavUpdateBinary  = "$PackageDir/kavupdater.sh";
$KavUpdateCommand = "cat $KavUpdateBinary | sed -e 's/==/=/g' | sh";

$LockFile = shift || "/var/spool/MailScanner/incoming/Locks/kasperskyBusy.lock";

$LOCK_SH = 1;
$LOCK_EX = 2;
$LOCK_NB = 4;
$LOCK_UN = 8;

Sys::Syslog::openlog("kaspersky-autoupdate", 'pid, nowait', 'mail');

# Code for Kasperky KAV4FS 5.5 first
if (-x "$PackageDir/kav4fs/bin/kav4fs-keepup2date") {
  &Lock();
  system("$PackageDir/kav4fs/bin/kav4fs-keepup2date");
  &Unlock();
  Sys::Syslog::syslog('info', "Kaspersky-5.5 kav4fs updated");
  Sys::Syslog::closelog();
  exit 0;
}


# Code for Kasperkey 5.5 first
if (-x "$PackageDir/kav4unix/bin/keepup2date") {
  &Lock();
  system("$PackageDir/kav4unix/bin/keepup2date");
  &Unlock();
  Sys::Syslog::syslog('info', "Kaspersky-5.5 updated");
  Sys::Syslog::closelog();
  exit 0;
}

# Code for Kasperkey 5.0 first
if (-x "$PackageDir/bin/keepup2date") {
  &Lock();
  system("$PackageDir/bin/keepup2date");
  &Unlock();
  Sys::Syslog::syslog('info', "Kaspersky-5.0 updated");
  Sys::Syslog::closelog();
  exit 0;
}

# Code for Kaspersky 4.5 first, it's much simpler
if (-x "$PackageDir/bin/kavupdater") {
  &Lock();
  system("$PackageDir/bin/kavupdater");
  &Unlock();
  Sys::Syslog::syslog('info', "Kaspersky-4.5 updated");
  Sys::Syslog::closelog();
  exit 0;
}

# Now the code for older versions.
if (-x $KavUpdateBinary) {
  &Lock();
  $Command = "$KavUpdateCommand";
  #$Command .= " --http-proxy $HTTPproxy" if $HTTPproxy;
  $result = system($Command);
  &Unlock();
  if ($result) {
    Sys::Syslog::syslog('err', "Kaspersky update failed. You may need to add 'UpdatePath=http://www.kaspersky-labs.com/updates/' to your /opt/AVP/AvpUnix.ini");
    print STDERR "Kaspersky update failed. You may need to add\nUpdatePath=http://www.kaspersky-labs.com/updates/\nto your /opt/AVP/AvpUnix.ini\n";
  } else {
    Sys::Syslog::syslog('info', "Kaspersky updated");
  }
} else {
  Sys::Syslog::syslog('err', "Kaspersky updater $KavUpdateCommand could not be run");
  print STDERR "Kaspersky updater $KavUpdateCommand could not be run";
}

Sys::Syslog::closelog();
exit $result;

sub Lock {
	open(LOCK, ">$LockFile") or return;
	flock(LOCK, $LOCK_EX);
	print LOCK "Locked for updating Kaspersky definitions by $$\n";
}

sub Unlock {
	print LOCK "Unlocked after updating Kaspersky definitions by $$\n";
	flock(LOCK, $LOCK_UN);
	close LOCK;
}