[Mimedefang] Perl Script to Update/Check perl prereq for MD and SA

James Ebright jebright at esisnet.com
Thu Jun 2 15:01:12 EDT 2005


I thought I would share something I did recently to clean up my older personal
howto and checklist for updating/installing MD and SA, this greatly simplifies
keeping the CPAN side of things updated.

Note, it will not let you know if you are missing a pre requisite module, it
will just skip it if you do not already have one installed. It will ask you if
you want to update if it finds a newer module on CPAN and do the update for
you (note, you really should preconfigure CPAN before doing this, but it
should work either way).

As always, use it entirely at your own risk.

Comments or suggestions are welcome, I will add it to the wiki somewhere as well.

Jim

--
EsisNet.com Webmail Client

-------------- next part --------------
#!/usr/bin/perl
#
# Perl script to check for prereq updates on cpan for MD and SA
# by James R. Ebright, ESISNET, LLC 6/1/2005
# Provided with no warranty of any kind, use at your own risk
# COPYRIGHT ESISNET, LLC, 2005, ALL RIGHTS RESERVED
#
# TODO: Cleaner way to update/check MailTools package
#       print CPAN::Shell->expand("Module","Mail::Header")->cpan_file;
#       can use the above to detect the file to install potentially
#       Check for proper version of CPAN, CPAN installation and config, 
#       and update CPAN Bundle if need be.
#       Subroutine the loops so there is not as much duplication of code
#
# 2005060101: Initial Version - JRE
# 2005060200: Added code to check for proper MailTools - JRE
#             Added install update to loops - JRE
##########################################################################
use CPAN;
# get CPAN version before check, not currently used, 
# but this makes output below more readable
$cver = CPAN::Shell->expand("Module","CPAN")->cpan_version;

##Module prereqs for MIMEdefang
print "\nPerl Modules required for MIMEdefang.\n";
print "____________________________________________\n";
for $mod (CPAN::Shell->expand("Module","/MIME::Tools|MIME::Base64|Mail::Audit|Mail::Address|Mail::Cap|Mail::Field|Mail::Filter|Mail::Header|Mail::Internet|Mail::Mailer|Mail::Send|Mail::Util|IO::Stringy|Digest::SHA1|Time::HiRes|Unix::Syslog|Archive::Zip|Sendmail::AccessDB/")){
  next unless $mod->inst_file;
  if ($mod->uptodate) {
    printf "Module %s installed as %s and is up to date\n", $mod->id, $mod->inst_version;
    next;
  }
  printf "Module %s is installed as %s, could be updated to %s from CPAN\n",
  $mod->id, $mod->inst_version, $mod->cpan_version;
  print "Do you wish to update this module now? Y [N]: ";
  $answer = lc(<STDIN>);
  if ($answer =~ /y/) {
    $mod->install;
  }
}

##Additional modules (for Spamassassin)
print "\nAdditional modules (for Spamassassin)\n";
print "____________________________________________\n";
for $mod (CPAN::Shell->expand("Module","/HTML::Parser|DB_File|Net::DNS|Net::Ident|Mail::SpamAssassin/")){
  next unless $mod->inst_file;
  # I dont want to know about all the subpackages on these two
  if (($mod->id =~ /Mail::SpamAssassin::/) || ($mod->id =~ /Net::DNS::/)) {
    next;
  }
  if ($mod->uptodate) {
    printf "Module %s installed as %s is and up to date\n", $mod->id, $mod->inst_version;
    next;
  }
  printf "Module %s is installed as %s, could be updated to %s from CPAN\n",
  $mod->id, $mod->inst_version, $mod->cpan_version;
  print "Do you wish to update this module now? Y [N]: ";
  $answer = lc(<STDIN>);
  if ($answer =~ /y/) {
    $mod->install;
  }
}


More information about the MIMEDefang mailing list