#!/usr/bin/perl -w # mvs-update-notify.pl use strict; my $DEBUG = 0; my $update_dir = "/var/ftp/pub/av/vs/updates"; my $update_dir_new = "$update_dir/Current/VSCANDAT1000/DAT/0000"; my $holding_dir = "/var/ftp/pub/av/vs/holding"; my $holding_dir_new = "$holding_dir/new"; my $link_filename = "sdat.exe"; my $link_file = "$update_dir/$link_filename"; # Verify update directory if ( ! -d $update_dir ) { die "Update directory $update_dir does not exist, exiting.\n"; } # Set link for current McAfee SDAT file opendir(UPDIR, $update_dir) or die "Cannot open directory $update_dir, exiting.\n"; my @dentries = sort readdir(UPDIR); closedir(UPDIR); dprint("All Directory Entries: ", @dentries); my @datfiles = sort grep(m/^dat\-\d{4}\.zip$/, @dentries); dprint("All DAT Files: ", @datfiles); my $current_dat = pop @datfiles; dprint("Old DAT Files: ", @datfiles); dprint("Current DAT File: ", $current_dat); my @sdatfiles = sort grep(m/^sdat\d{4}\.exe$/, @dentries); dprint("All SDAT Files: ", @sdatfiles); my $current_sdat = pop @sdatfiles; dprint("Old SDAT Files: ", @sdatfiles); dprint("Current SDAT File: ", $current_sdat); my $link_target = readlink $link_file || ""; dprint("Current SDAT Link Target: ", $link_target); # Make new link and notify if ( ! ($current_sdat eq $link_target) ) { print "A new current SDAT has arrived!\n"; print "$current_sdat is in the $update_dir directory.\n"; if ( -f $link_file ) { print "Removing old symbolic link to $link_target.\n"; unlink $link_file; } print "Creating symbolic link from $link_filename to $current_sdat.\n"; symlink $current_sdat, $link_file; } # Move old dat and sdat files to holding location, awaiting deletion # Check if holding directory exists if ( ! -d $holding_dir ) { die "Holding directory $holding_dir does not exist...exiting.\n"; } # Check for the presence of any old files if ( scalar @datfiles || scalar @sdatfiles ) { print "Moving old DAT and SDAT files to $holding_dir.\n"; foreach my $file (@datfiles, @sdatfiles) { my $oldfile = "$update_dir/$file"; my $newfile = "$holding_dir/$file"; print " Moving $oldfile\n"; rename $oldfile, $newfile; } } # Clean up deeper directory structure for newer McAfee clients opendir(UPDIRNEW, $update_dir_new) or die "Cannot open directory $update_dir_new, exiting.\n"; my @dentriesnew = sort readdir(UPDIRNEW); closedir(UPDIRNEW); dprint("All New Directory Entries: ", @dentriesnew); my @datfilesnew = sort grep(m/^dat\-\d{4}\.zip$/, @dentriesnew); dprint("All New DAT Files: ", @datfilesnew); my $current_dat_new = pop @datfilesnew; dprint("Old DAT Files: ", @datfilesnew); dprint("Current DAT File: ", $current_dat_new); # Move old dat files to holding location, awaiting deletion # Check if holding directory exists if ( ! -d $holding_dir_new ) { die "Holding directory $holding_dir_new does not exist...exiting.\n"; } # Check for the presence of any old files if ( scalar @datfilesnew ) { print "Moving old DAT files to $holding_dir_new.\n"; foreach my $file (@datfilesnew) { my $oldfile = "$update_dir_new/$file"; my $newfile = "$holding_dir_new/$file"; print " Moving $oldfile\n"; rename $oldfile, $newfile; } } exit; # print debug info if DEBUG is on sub dprint { if (not $DEBUG) { return; } print join('', map { $_ || 'undef' } @_), "\n"; } __END__