--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.perltidyrc Wed May 26 00:10:07 2010 +0200
@@ -0,0 +1,2 @@
+--paren-tightness=2
+--square-bracket-tightness=2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/check Wed May 26 00:10:07 2010 +0200
@@ -0,0 +1,170 @@
+#! /usr/bin/perl
+# © Heiko Schlittermann <hs@schlittermann.de>
+# Sources: https://keller.schlittermann.de/hg/exim-checks
+use strict;
+use warnings;
+
+use Perl6::Slurp;
+use File::Temp;
+use File::Basename;
+use Getopt::Long;
+use Pod::Usage;
+use FindBin qw($Bin);
+
+my $ME = basename $0;
+
+my $opt_init = 0;
+my $opt_refresh = 0;
+my $opt_dir = \'dirname($opt_config) . "/lib"';
+
+my $opt_config = undef;
+my $opt_exim = undef;
+
+MAIN: {
+
+ GetOptions(
+ "i|init" => \$opt_init,
+ "r|refresh" => \$opt_refresh,
+ "d|dir=s" => \$opt_dir,
+ "c|config=s" => \$opt_config,
+ "exim|binary=s" => \$opt_exim,
+ "h|help" => sub { pod2usage(-exitval => 0, -verbose => 1) },
+ "m|man" => sub { pod2usage(-exitval => 0, -verbose => 3) },
+ ) or pod2usage();
+
+ defined $opt_exim
+ or $opt_exim = (
+ grep { -x }
+ map { ("$_/exim", "$_/exim4") }
+ qw(
+ /usr/local/sbin /usr/local/bin /usr/sbin /usr/bin)
+ )[0]
+ or die "$ME: Can't find the exim(4) binary\n";
+
+ defined $opt_config
+ or $opt_config = (
+ map { /.*\s(\S+)$/ && $1 } grep /Configuration file is\s+/,
+ qx/$opt_exim -v -bV/
+ )[0]
+ or die "$ME: Can't find exim config\n";
+
+ $opt_dir = eval $$opt_dir if ref $opt_dir;
+
+ print "% using $opt_config and dir $opt_dir\n";
+
+ if ($opt_init or $opt_refresh) {
+ foreach my $address (@ARGV) {
+ if ($opt_init) {
+ mkdir $_ = "$opt_dir/$address", 0777
+ or die "Can't mkdir $_: $!\n";
+ }
+ else {
+ -d ($_ = "$opt_dir/$address") or die "Can't find die $_: $!\n";
+ }
+ foreach my $opt ("v", "t") {
+ my $file = "$opt_dir/$address/$opt";
+ system("exim4 -C $opt_config -v -b$opt '$address' >$file");
+ }
+ }
+ exit;
+ }
+
+ foreach my $dir (
+ @ARGV
+ ? map { /\// ? $_ : "$opt_dir/$_" } @ARGV
+ : glob("$opt_dir/*")
+ )
+ {
+ my $address = basename $dir;
+ print "checking $address:";
+
+ for my $opt ("v", "t") {
+
+ print $opt eq "v" ? " verify:" : " test:";
+
+ my $checkfile = "$dir/$opt";
+ my $expect = slurp $checkfile;
+ my $result = qx/exim4 -C $opt_config -v -b$opt '$address'/;
+
+ foreach ($expect, $result) {
+ s/^\s+host\s.*//m;
+ s/^\s+host\s.*//m;
+ }
+
+ print "ok" and next if $result eq $expect;
+
+ my $tmp_expect = new File::Temp;
+ my $tmp_result = new File::Temp;
+
+ $tmp_expect->print($expect);
+ $tmp_result->print($result);
+
+ print "* DIFFERS *\n";
+
+ $_ = join " ", "diff", "-u",
+ "--label=got",
+ "--label=expected",
+ $tmp_result->filename,
+ $tmp_expect->filename;
+ chomp;
+
+ $_ = qx/$_/;
+ s/^/\t/mg;
+ print;
+ }
+
+ print "\n";
+ }
+}
+
+__END__
+
+=head1 NAME
+
+check - checks exim routing agains pre-defined values
+
+=head1 SYNOPSIS
+
+ check [options] -i|--init <address>...
+ check [options] [<address>...]
+ check [options] -r|--refresh <address>...
+ check {-h|-m}|{--help|--man}
+
+=head1 DESCRIPTION
+
+This tools calls exim4 and checks the output of C<exim4 -v -bv <address>>
+and C<exim4 -v -bt <address>> against some pre-defined values.
+
+=head1 OPTIONS
+
+=over 4
+
+=item B<-c>|B<--config> I<config_file>
+
+The location of the exim config to use. (default: autodetected by C<exim
+-bV>)
+
+=item B<-d>|B<--dir> I<directory>
+
+The directory containing the checks (default: C<dirname($config)/lib>)
+
+=item B<-i>|B<--init>
+
+Initialize the tests (run them for the first time and remember
+the results. (default: not used)
+
+=item B<-r>|B<--refresh>
+
+Refresh the results (should be used after a verified change).
+(default: not used)
+
+=item B<--exim> I<binary_file>
+
+The exim binary to use. This option should be rarely used. (default:
+autodetected in some standard locations).
+
+=back
+
+=cut
+
+# vim:sts=4 sw=4 aw ai sm: