#!/bin/perl
# config-test,v 1.3 1996/01/28 19:16:29 cwilson Exp
# configuration test for majordomo
# provided with majordomo, modifications by darren stalder <torin@daft.com>
# more mods by Vince Skahan <vince@atc.boeing.com>
#
# execute this by cd to your majordomo dir, then 'wrapper config-test'
#

@requires = ( "ctime.pl",
	     "majordomo_version.pl",
	     "majordomo.pl",
	     "shlock.pl",
	     "config_parse.pl",
	      );


&header("Obvious things:");

&header("environment variables");
foreach $e (sort keys %ENV) {
        print "   $e=$ENV{$e}\n";
}

&header("euid/egid checks");

$euid_name=getpwuid($>);
push(@egid_group_numbers,(split(' ',$) )));   # it switches groups...
foreach $groupnum (@egid_group_numbers) {
	$name = getgrgid($groupnum);
	push(@egid_names,$name);
}
print "   effective user  = $euid_name (uid $>)\n";
print "   effective group = @egid_names (gid $) )\n";

&header("uid/gid checks");

$uid_name=getpwuid($<);
push(@gid_group_numbers,(split(' ',$( )));   # it switches groups...
foreach $groupnum (@gid_group_numbers) {
	$name = getgrgid($groupnum);
	push(@gid_names,$name);
}
print "   real      user  = $uid_name (uid $<)\n";
print "   real      group = @gid_names (gid $( )\n";

&header('');
print "\n\tNon obvious things that cause headaches:\n\n";
&header('');

foreach (@requires) {
    if (require $_) {
	&good("found $_ okay.");
    } else {
	&bad("failed to find $_ in \@INC");
    }
}

print "\n";

$cf = $ENV{'MAJORDOMO_CF'};

if (require $cf) { 
    &good("\"require\"d $cf okay.");    
} else {
    &bad("unable to open $cf: $!");
}

print "\n--==> Majordomo home directory is $homedir.\n";

unshift(@INC, $homedir);

&header("Include directories");
foreach (@INC) {
    print "\t$_\n";
}

&header("Home");

if (chdir($homedir)) {
    &good("changedir to $homedir succeeded.");
} else {
    &bad("changedir to $homedir failed, $!");
}

&header("list directory");

if (-d $listdir) {
    if (-r $listdir && -w $listdir && -x $listdir) {
	&good("list directory $listdir has good permissions.");
    } else {
	&bad("list directory $listdir has bad permissions");
    }
} else {
    &bad("list directory $listdir doesn't exist or isn't a directory.");
}

&header("log");

if ( ! -e $log ) {
    print "Logfile $log didn't exist, trying to create...";
    if (open(A, ">$log")) {
	print "okay.\n";
	chmod (A, 664) || &bad( "but chown on $log failed, $!");
    } else {
	print "nope!\n";
    }
}

if ( -r $log && -w $log) {
    &good("logfile $log exists and is writeable.");
} else {
    &bad("logfile $log exists, but is not writeable.");
}

&header ("Mailers");
if ( -x $sendmail_command) {
    &good("The mailer $sendmail_command is executable");
} else {
    &bad("The mailer $sendmail_command isn't executable or isn't valid.");
}

if ($mailer) {
    print "HOWEVER, the mailer command is not default ($mailer)\n";
    print "Attempting to verify that this is a valid mailer...";
    ($x) = $mailer =~ /^(\S+)/;
    if ( -x $x ) {
	print "looks okay.\n";
    } else {
	print "looks bad..maybe.\n";
    }
}






&header( "end of tests");

print "\n\n";

if ($BAD) {
    print "$BAD bad ", $BAD == 1 ? "thing was " : "things were", " found.\n";
    print "Please fix before attempting to run Majordomo.\n";
} else {
    print <<"ZOT";
Nothing bad found!  Majordomo _should_ work correctly.

If it doesn't, check your configuration file 
	($cf) 

closely, and if it still looks okay, consider asking the
majordomo-users mailing list at "majordomo-users\@greatcircle.com" for
assistance Be sure and fully specify what your problems are, and what
type of machine (and operating system) you are using.

Enjoy!

ZOT
}    


######################################################################
sub good { print "Good: $_[0]\n"; }

sub bad { print "BAD:  $_[0]\n"; $BAD++;}

sub header {
    print '-' x ( ( 60 - (length($_[0]) + 2) ) / 2),
    " $_[0] ", '-' x ( ( 60 - (length($_[0]) + 2) ) / 2), "\n";
}

#
# that's all folks

