Ad-Aware SE Pro (or personal) file definition update

For those who are still using Ad-Aware SE Pro or personal but as all of us discoverred that the Integrated WebUpdates Tools of the definitions is no longer working through the auto-update, here is a script which will help you installing the new definitions as they are provided.

Ad-Aware SE Main windowAd-Aware SE Integrated WebUpdate Tools window

Hope it will help Ad-Aware SE users ...

 

#!/usr/local/bin/perl

#
# (c) J. Lauret July 2008, GPL
#
# This script contacts the LavaSoft update center, checks if updates
# are available for the Ad-Aware SE definition files, downloads and
# install the update if needed. It is a replacement for the automated
# updates for Ad-Aware SE (product support for definitions continues
# but the update center mechanism was broken).
#
# This script is meant to run under cygwin on Windows.
#
# Variables used (and you will need to change) are:
#   $ARCH   An archive directory for the downloaded packages specified as
#           cygwin-path syntax.
#           *** YOU HAVE TO DEFINE THIS ONE FOR SURE ***
#
#   $TRGTD  Target directory where your Ad-Aware SE product is installed
#           There should be no need to change this unless you have it
#           installed on another drive than the C: drive
#
#   $ENAM   Lavasoft package name for the definitions (assumed to be
#           $ENAM.zip)
#   $BNAM   The base name of the definition files to be downloaded and
#           archived on your disk (no need to change unless you really
#           do not like the name I picked). If not defined, will default
#           to $ENAM
#
# In case
#   $SRC    Source and base URL where the defs.zip can be found.
#
#

use URI;
use File::Copy;
use lib "/home/jlauret/lib";
use CygWin;

$URL  = "http://www.lavasoft.com/support/securitycenter/blog/";
$FLNM = "/tmp/ad-aware.securitycenter.html";
$CURL = "/usr/bin/curl";
$WGET = "/usr/bin/wget";
$UNZIP= "/usr/bin/unzip";
$SRC  = "http://download.lavasoft.com/public";


# Expected name of download - extension always expected as .zip
$ENAM = "defs";

# Archive director for all downloads (copy)
$ARCH = "/cygdrive/f/Documents and Settings/jlauret/My Documents/Packages/Ad-Aware/";

# Target directory where it should go
$TRGTD= "/cygdrive/c/Program Files/Lavasoft/Ad-Aware SE Professional/";

# Base name for archive file anme - if empty, will be the same
# name than ENAM with version appended
$BNAM = "Ad-Aware-defs";


# --- No modifs needed below ----

#extract base URL for information
$uri = URI->new($URL);
$BASE  = $uri->host;
print "Looking at $BASE for updates\n";

# check variables
$BNAM = ENAM if ($BNAM eq "");



system("$CURL $URL >&$FLNM");

$ref = $ver = "";

if ( -e $FLNM ){
  open(FI,$FLNM);
  $fetch =0;
  while ( defined($line = <FI>) ){
    if ($line =~ m/filename-se/){
      $fetch = 1;
      $next;
    }
    if ( $fetch ){
      if ( $line =~ m/(<a href=)(.*)(>SE)(.*)( <.*)/){
        $fetch = 0;
        $ref   = $2;
        $ver   = "SE".$4;
        last;
      }
    }
  }
  close(FI);
}
unlink($FLNM);

if ($ver eq "" && $ref eq ""){
  die "Could not parse version and fetch URL\n";
} elsif ( $ver eq ""){
  die "Found fetcher URL $ref with no version info. Skipping.\n";
} else{
  # all is OK
  if ( ! -e "$ARCH/$BNAM-$ver.zip"){
    print " Found $ver . We do not have $BNAM-$ver.zip\n";
    print " Fetching from $SRC/$ENAM.zip\n";
    system("$WGET $SRC/$ENAM.zip");
    if ( ! -e "$ENAM.zip"){
      die "Failed to download $ENAM.zip\n";
    } else {
      $BASE = "/tmp/$$";                         # re-usde of variable
                                                 # now a working directory
      mkdir($BASE);
      $FLNM = "/tmp/ad-aware-se-install.csh";    # temp csh script now

      open(FO,">$FLNM");
      print FO 
        "#!/bin/csh\n",
        "/bin/cp $ENAM.zip $BASE/\n",
        "cd $BASE\n",
        "$UNZIP $ENAM.zip\n";
      close(FO);
      chmod( oct('0755'), $FLNM);
      print " Unziping $ENAM.zip ($ver)\n";
      system($FLNM);
      if ( !-e "$BASE/$ENAM.ref"){
        print 
          "Failed to find $ENAM.ref in downloaded package.".
          "Please, review content\n";
        system("/bin/ls -al $BASE/");
        die "\n";
      } else {
        # rename old defs
        if ( -e "$TRGTD/$ENAM.ref.old"){
          print " Deleting previous old definition\n";
          unlink("$TRGTD/$ENAM.ref.old");
        }
        if ( -e "$TRGTD/$ENAM.ref"){
          print " Moving current definition to .old\n";
          rename("$TRGTD/$ENAM.ref","$TRGTD/$ENAM.ref.old");
        }

        # install new files
        print " Copying new definition\n";
        if ( ! copy("$BASE/$ENAM.ref","$TRGTD/$ENAM.ref")){
          print " Warning: Did not succeed in installing new definitions\n";
          if ( -e "$TRGTD/$ENAM.ref.old" && ! -e "$TRGTD/$ENAM.ref"){
            print " Re-installing previous definitions\n";
            rename("$TRGTD/$ENAM.ref.old","$TRGTD/$ENAM.ref");
          }
        } else {
          # was a success, proceed
          print " Saving archive copy\n";
          if ( copy("$BASE/$ENAM.zip","$ARCH/$BNAM-$ver.zip") ){
            print " Archive copy is made as $BNAM-$ver.zip\n";
          } else {
            print " Warning: Failed to copy into archive directory\n";
          }
        }
        # cleanup
        system("/bin/rm -fr $BASE") if ( -e $BASE);
        unlink("$ENAM.zip")         if ( -e "$ENAM.zip");
        unlink($FLNM)               if ( -e $FLNM);
      }
    }
  } else {
    print "You have the latest definition version $ver\n";
  }
}