#!/usr/bin/perl -w

open(TMP, ">/tmp/eminfo.dat");

@pci = qx { lspci -vv };
@em = qx { cat /proc/em8300/* };
@modulesc = qx { cat /etc/modules.conf };

print "Please type/paste your em8300/adv717x module options below\nWhen done please enter . on a new line\n";
$i = 0 ;
$modules[$i++] = <STDIN>;
while (!($modules[$i-1] =~ /^\./)) {
        $modules[$i++] = <STDIN>;
}


@dmesg = qx { dmesg };

print TMP "::: EM8300 MODULES INFO (user) :::\n";
print TMP @modules;

print TMP "::: EM8300 MODULES INFO :::\n";
for $line (@modulesc) {
        if (($line =~ /em8300/) || ($line =~ /adv717x/) || ($line =~ /bt865/)) {
                print TMP $line;
        }
}

print TMP "::: PCI INFO :::\n";
$start = 0;
for $line (@pci) {
        if (($start) && ($line =~ /^[0-9]/)) {
                $start=0;
        }
        if($start) { 
                print TMP $line ; 
        }
        if ($line =~ /Multimedia controller/) {
                $start=1;
                print TMP $line;
        }
}


print TMP "::: /proc/em8300/* info :::\n";
print TMP @em;


print TMP "::: DMESG INFO :::\n";
for $line (@dmesg) {
        if ($line =~ /detected/) {
                print TMP $line;
        }
}

print TMP "::: ADDITIONAL INFO :::\n";
print "Does overlay work? (yes/no/don't know)?";
$reply = <STDIN>;
print TMP "Overlay: ";
print TMP $reply;
print "Does tv-out work? (yes/no/don't know)?";
$reply = <STDIN>;
print TMP "TV-Out: ";
print TMP $reply;

print TMP "::: USER INFO :::\n";
print "If you have any comments or something else you want us to know enter that here.\nWhen done enter . on a single line\n";
$i = 0 ;
$comment[$i++] = <STDIN>;
while (!($comment[$i-1] =~ /^\./)) {
        $comment[$i++] = <STDIN>;
}
print TMP @comment;
print "Please enter your e-mail address (not required): ";
$reply = <STDIN>;
print TMP "E-Mail: ";
print TMP $reply;

@out  = qx { cat /tmp/eminfo.dat };
print @out;
print "\nCan I send this information to the dxr3 developers to assist in the quest for automatic module option setting?";
$reply = <STDIN>;
if ($reply =~ /[Yy]/ ) {
        @out = qx { mail -s "em8300.dat" david\@realityrift.com </tmp/eminfo.dat };
        print @out;
	print "If mail seems to have failed somehow please manually mail /tmp/eminfo.dat to david\@realityrift.com with subject em8300.dat\n";
} else {
        print "Please reconsider running this again and answering Y, or edit /tmp/eminfo.dat and remove any details you don't want sent, before mailing the output to david\@realityrift.com\n";
}



