tar.gz upgrade question

Mike Kercher mike at CAMAROSS.NET
Tue Jul 15 01:24:38 IST 2003


You may need to adjust paths because I use the rpm distro.

[root at genesis rules]# cat /usr/sbin/upgrade_MailScanner_conf
#!/usr/bin/perl

#
#   MailScanner - SMTP E-Mail Virus Scanner
#   Copyright (C) 2002  Julian Field
#
#   $Id: upgrade_MailScanner_conf,v 1.1.2.5 2003/03/10 19:42:37 jkf Exp $
#
#   This program is free software; you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation; either version 2 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
USA
#
#   The author, Julian Field, can be contacted by email at
#      Jules at JulianField.net
#   or by paper mail at
#      Julian Field
#      Dept of Electronics & Computer Science
#      University of Southampton
#      Southampton
#      SO17 1BJ
#      United Kingdom
#

#
# This script will output the contents of a new MailScanner.conf file based
# on an old MailScanner.conf file and a default copy of the new file.
# It is designed for upgrading MailScanner.conf files from one release of
# version 4 to another release of version 4. It will not help with the
upgrade
# from version 3 or earlier to version 4, you still have to do that by hand.
#

use FileHandle;
use strict;

sub Usage {
  print STDERR <<EOU;
Usage:

If you are using the RPM distributions then try this:

cd /etc/MailScanner
upgrade_MailScanner_conf MailScanner.conf MailScanner.conf.rpmnew >
MailScanner.new
mv MailScanner.conf MailScanner.old
mv MailScanner.new  MailScanner.conf

If you are using the tar distribution so that the old version is in
/opt/MailScanner and the new one is in /opt/MailScanner.new then:

cd /opt/MailScanner.new/etc
../bin/upgrade_MailScanner_conf /opt/MailScanner/etc/MailScanner.conf
/opt/MailScanner.new/etc/MailScanner.conf > MailScanner.new
mv MailScanner.conf MailScanner.old
mv MailScanner.new  MailScanner.conf

EOU
  exit 1;
}

sub Afterwards {
  print STDERR "\nOnce you have checked that MailScanner.new contains
what\n";
  print STDERR "you want, you can then save your old one and move the
new\n";
  print STDERR "one into place, using commands like these:\n";
  print STDERR "  mv -f MailScanner.conf MailScanner.old\n";
  print STDERR "  mv -f MailScanner.new  MailScanner.conf\n";
}

my $oldfname = shift;
my $newfname = shift;

Usage() unless $oldfname && $newfname && -f $oldfname && -f $newfname;

# Read in the old file to get all their current settings
my $oldfh = new FileHandle;
$oldfh->open($oldfname)
  or die "Cannot read old MailScanner.conf file $oldfname, $!";
my($key, $value, $origkey, $origline, %oldsettings, $ReadOldValue,
%oldkeys);
my(%oldcomments, $comments);
$ReadOldValue = 0;
$comments = "";
while(<$oldfh>) {
  chomp;
  $origline = $_;
  s/#.*$//;
  s/^\s+//;
  s/\s+$//;
  ($comments .= "$origline\n"),next if /^$/;

  undef $origkey;
  undef $key;
  undef $value;
  /^(.*?)\s*=/; # \s*(.*)$/;
  $origkey = $1;
  $origline =~ /=\s*(.*)$/;
  $value = $1;

  $key = lc($origkey);
  $key =~ s/[^a-z0-9]//g; # Leave numbers and letters only

  $oldsettings{$key} = $value;
  $oldkeys{$key} = $origkey;
  $oldcomments{$key} = $comments;
  $comments = "";
  $ReadOldValue++;
}
$oldfh->close();

# Read in the new file to get all the default settings and new key names
my $newfh = new FileHandle;
$newfh->open($newfname)
  or die "Cannot read new default MailScanner.conf file $newfname, $!";
my($defaultvalue, $UsedOldValue, $UsedDefaultValue);
$UsedOldValue = 0;
$UsedDefaultValue = 0;
$comments = "";
while(<$newfh>) {
  chomp;
  $origline = $_;
  s/#.*$//;
  s/^\s+//;
  s/\s+$//;
  ($comments .= "$origline\n"),next if /^$/;

  undef $origkey;
  undef $key;
  undef $defaultvalue;
  /^(.*?)\s*=/; # \s*(.*)$/;
  $origkey = $1;
  /=\s*(.*)$/;
  $defaultvalue = $1;

  $key = lc($origkey);
  $key =~ s/[^a-z0-9]//g; # Leave numbers and letters only

  if (exists $oldsettings{$key}) {
    # They previously had a setting for this parameter
    print $oldcomments{$key};
    print "$origkey = $oldsettings{$key}\n";
    delete $oldsettings{$key};
    $comments = "";
    $UsedOldValue++;
  } else {
    # they are using the new default value for this parameter
    print $comments;
    print "$origline\n";
    print STDERR "Added new: $origline\n";
    sleep(2);
    $comments = "";
    $UsedDefaultValue++;
  }
}
$newfh->close();
while (($key, $value) = each %oldsettings) {
  print STDERR "Removed old: $oldkeys{$key} = $value\n";
  sleep(2);
}

print STDERR <<EOL;

Summary
-------
Read $ReadOldValue settings from old $oldfname
Used $UsedOldValue settings from old $oldfname
Used $UsedDefaultValue default settings from new $newfname

Notes
-----
I would advise you to check on any parameters which are different between
the default new conf file and the conf file you just created, so that you
find any parameters whose default values have changed.
If you ran this with a command like this
  upgrade_MailScanner_conf MailScanner.conf MailScanner.conf.rpmnew >
MailScanner.conf.new
then you should do
  diff MailScanner.conf.rpmnew MailScanner.conf.new
and check for any differences in values you have not changed yourself.

EOL
sleep(5);
Afterwards();
exit 0;



-----Original Message-----
From: MailScanner mailing list [mailto:MAILSCANNER at JISCMAIL.AC.UK] On Behalf
Of penguin
Sent: Monday, July 14, 2003 4:49 PM
To: MAILSCANNER at JISCMAIL.AC.UK
Subject: tar.gz upgrade question


Hiya,

Has anyone seen an upgrade script for the tar.gz installation of
MailScanner? I have Gentoo and I don't use the RPM of MailScanner, so I was
wondering if someone had developed or considered developing a nice .sh
script that would perform the updates required in an RPM-like fashion. If
not, I'm willing to give it a go and/or work with someone in making a script
that does that.

A. Eijkhoudt



--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the MailScanner mailing list