#!/bin/sh
#####################################################
#####################################################
#
# This is a helper script for updating NOD32. It simplifies
# the update process to merely running this script.
#
# Make sure to configure username and password prior to
# using this script.
#
# It is also a good idea to put the script into crontab
# so that you always had the latest virus signature files.
#

###
### Enter the name of the file where your username and password
### to download NOD32 update are stored.
###
### Please edit the file, enter username and password information
### and make it UNREADABLE to the public.
###
### The file should include two lines like this:
### username=your_nod32_username
### password=your_nod32_password
###

authfile=/usr/local/nod32/nod32.auth

###
### If you want to download updates from other than the default
### server (www.nod32.com), uncomment and edit the following
### line.
###

server=www.nod32.com

###
### If NOD32 is installed in other than default directory
### (/usr/local/nod32), uncomment and edit the following line.
### Use absolute path here with trailing slash, please.
###

nod32dir=/usr/local/nod32/

###
### If you want mirrors to be created in other than default
### directory (/usr/local/nod32/mirror), uncomment and edit the
### following line. Use absolute path here, please.
###

mirrordir=/usr/local/nod32/mirror

###
### Configuration of the update script is finished.
###
#####################################################
#####################################################

#####################################################
#####################################################
###
### There is nothing to configure beyond this point
###


if [ "a$nod32dir" = "a" ]
then
  nod32dir="/usr/local/nod32"
fi

if [ "a$mirrordir" = "a" ]
then
  mirrordir="$nod32dir/mirror"
fi

if [ "a$server" = "a" ]
then
  server="www.nod32.com"
fi

if [ ! -d $nod32dir ]
then
  echo NOD32 home directory \'$nod32dir\' does not exist
  exit 1
fi

if [ ! -d $mirrordir ]
then
  echo NOD32 update mirror directory \'$mirrordir\' does not exist
  exit 1
fi

if [ "$1" = "--create_control_file" ]
then
  printf "creating control file in \'$nod32dir\'... "
  control_file="$nod32dir/nod32.ver"

  echo "# This file is neccesary for correct functionality of automatic update of NOD32" > $control_file
  echo "# Please DO NOT alter this file" >> $control_file
  echo "[info]" >> $control_file
  echo "language=english" >> $control_file
  echo "platform=linux" >> $control_file
  echo "version=<none>" >> $control_file
  echo "build=1000" >> $control_file
  echo "mod_build=1000" >> $control_file
  echo "app_build=1000" >> $control_file

  if [ ! -f "$nod32dir/nod32.ver" ]
  then
    echo "failed!"
  else
    echo "ok"
  fi
  exit 1
fi

if [ ! -f "$nod32dir/nod32.ver" ]
then
  echo Fatal error ocurred!
  echo
  echo NOD32 directory \'$nod32dir\' does not contain update control file
  echo nod32.ver, which is important for correct functionality of automatic
  echo update. If you want to create an empty file, run this script with
  echo the following argument:
  echo
  echo "    update --create_control_file"
  echo
  exit 1
fi

olddir=`pwd`
cd $nod32dir
./nod32umc -s $server -a $authfile $mirrordir
./nod32upd $mirrordir -update
cd $olddir
