#!/usr/bin/perl -w
# --
# $Id: otrs.checkModules,v 1.4 2003/03/10 21:29:16 martin Exp $
# --
# This programm is based on pminst from Tom Christiansen.
# This is free software.  You may modify it and distribute it 
# under Perl's Artistic Licence.  Modified versions must be
# clearly indicated.
# --

# use ../ as lib location
use File::Basename;
use FindBin qw($RealBin);
use lib dirname($RealBin);
use lib dirname($RealBin)."/Kernel/cpan-lib";

use File::Find;

if (@ARGV == 0) {
    @ARGV = ('.');
} 

my @NeededModules = (qw(
    CGI 
    Date::Pcalc 
    DBI DBD::mysql 
    Digest::MD5 
    Email::Valid
    IO::Scalar IO::Wrap 
    MIME::Base64 MIME::Tools Mail::Internet
    Net::DNS Net::POP3 Net::LDAP Net::SMTP
    Authen::SASL
    GD GD::Text GD::Graph GD::Graph::lines GD::Text::Align
));

my %InstalledModules = ();

no lib '.';

for $startdir (@INC) { 
    find(\&wanted, $startdir);
}

sub wanted {
    if (-d && /^[a-z]/) { 
        # this is so we don't go down site_perl etc too early
        $File::Find::prune = 1;
        return;
    }
    return unless /\.pm$/;
    local $_ = $File::Find::name;
    $tmpname = $_; 
    $tmpname =~ s{^\Q$startdir/}{};
    s{^\Q$startdir/}{};  
    s/\.pm$//;
    s{/}{::}g;
    $InstalledModules{lc($_)} = 1;
}

foreach (@NeededModules) {
    if ($InstalledModules{lc($_)}) {
        print sprintf(" %20s %s\n", $_, '... ok');
    }
    else {
        if ($_ =~ /^GD/) {
            print sprintf(" %20s %s\n", $_, '... not installed! (for stats - not required)');
        }
        elsif ($_ =~ /^Net::SMTP$/ || $_ =~ /^Authen::SASL$/) {
            print sprintf(" %20s %s\n", $_, '... not installed! (for SMTP backend - not required)');
        }
	    elsif ($_ =~ /^Net::LDAP/) {
            print sprintf(" %20s %s\n", $_, '... not installed! (for directory authentication - not required)');
        }
        else {
            print sprintf(" %20s %s\n", $_, '... not installed! (required - use "perl -MCPAN -e shell;")');
        }
    }
}

