#!/usr/bin/perl

die "Must have euid = 0 to install this stuff!\n" if $>;
print "This will install the appropriate headers (if required),\n";
print "install libpcap, Net::RawIP, Term::ANSIColor, URI,\n";
print "and install pdump itself.  Do you want to continue? (y/n)\n";
chomp ($ans = <STDIN>);
unless ($ans =~ /^y/i) {
 die "Exiting...\n";
}
else {
 print "Locating required headers...\n";
 unless (-e '/usr/include/net/bpf.h') {
  system("cp -f headers/bpf.h /usr/include/net/bpf.h >> install.log");
  print "Adding bpf.h...\n";
 }
 unless (-e '/usr/include/pcap.h') {
  system("cp -f headers/pcap.h /usr/include/pcap.h >> install.log");
  print "Adding pcap.h...";
 }
 chdir('zips');
 print "Decompressing and extracting files...\n";
 system('tar -zxvf ANSIColor-1.03.tar.gz >> ../install.log');
 system('tar -zxvf Net-RawIP-0.09.tar.gz >> ../install.log');
 system('tar -zxvf URI-1.09.tar.gz >> ../install.log');
 system('tar -zxvf libpcap.tar.Z >> ../install.log');
 chdir('libpcap-0.4');
 print "Configuring libpcap...\n";
 system('./configure >> ../../install.log');
 print "Making libpcap...\n";
 system('make >> ../../install.log');
 print "Installing libpcap...\n";
 system('make install >> ../../install.log');
 chdir('../Net-RawIP-0.09');
 print "Configuring Net::RawIP...\n";
 system('perl Makefile.PL >> ../../install.log');
 print "Making Net::RawIP...\n";
 system('make >> ../../install.log');
 print "Installing Net::RawIP...\n";
 system('make install >> ../../install.log');
 chdir('../URI-1.09');
 print "Configuring URI...\n";
 system('perl Makefile.PL >> ../../install.log');
 print "Making URI...\n";
 system('make >> ../../install.log');
 print "Installing URI...\n";
 system('make install >> ../../install.log');
 chdir('../ANSIColor-1.03');
 print "Configuring Term::ANSIColor...\n";
 system('perl Makefile.PL >> ../../install.log');
 print "Making Term::ANSIColor...\n";
 system('make >> ../../install.log');
 print "Installing Term::ANSIColor...\n";
 system('make install >> ../../install.log');
 chdir('../../');
 print "Locating documentation...\n";
 if (-e '/usr/man/man1/perl.1.bz2') {
  print "Adding documentation...\n";
  system('cp -f zips/pdump.not-current.1.bz2 /usr/man/man1/pdump.1.bz2');
 }
 if (-e '/usr/man/man1/perl.1.gz') {
  print "Adding documentation...\n";
  system('cp -f zips/pdump.not-current.1.gz /usr/man/man1/pdump.1.gz');
 }
 if (-e '/usr/share/man/man1/perl.1.bz2') {
  print "Adding documentation...\n";
  system('cp -f zips/pdump.not-current.1.bz2 /usr/share/man/man1/pdump.1.bz2');
 }
 if (-e '/usr/share/man/man1/perl.1.gz') {
  print "Adding documentation...\n";
  system('cp -f zips/pdump.not-current.1.gz /usr/share/man/man1/pdump.1.gz');
 }
 print "Installing pdump...\n";
 system('cp -f pdump.pl /usr/bin/pdump');
 system('ln -sf /usr/bin/pdump /usr/bin/pdump.pl');
 print "Installing pdump's plugings...\n";
#mkdir('/usr/local/pdump', 755) unless (-e '/usr/local/pdump');
#system('cp -r lib /usr/local/pdump/lib');
#system('cp -r docs /usr/local/pdump/docs');
 print "Installation complete.\n";
 print "Read the 'README' file in the current directory for the man page in text format.\n";
 print "Unfortunately the current pod and man pages are innacurate and old.\n";
 print "The README.html in the docs directory is just as current as the README, too.\n";
 print "You can find a detailed explanation including examples and\n";
 print "other various information on pdump in the README(.html).\n";
 print "\nRun `pdump` to run pdum in standard mode. I suggest you skim the options\n";
 print "in the README before you try anything or you will be completely stuck.\n";
 print "Pdump also requires you to be in a directory which includes the lib directory\n";
 print "such as the directory you are in right now since the libs dir is a requireed dir.\n";
 print "Good luck,\nSamy Kamkar [CommPort5\@LucidX.com]\n";
}
