#
#  execute a pile of commands to suck in host information
#
#  Each command should do a date_stamp() & sign_it() to date stamp
# and md5 the results.
#

require "conf/coroner.cf";
require "conf/paths.pl";

sub suck_hostinfo {

print "Running all sorts of commands on host (in &suck_hostinfo())\n" if $verbose;

if (-x $UNAME) {
	&date_stamp("$COMM_OUT/uname");
	&redirect_command("$UNAME", "-a", ">>$COMM_OUT/uname") 
	&sign_it("$COMM_OUT/uname");
	}

if (-x $DMESG) {
	&date_stamp("$COMM_OUT/dmesg");
	&redirect_command($DMESG, ">>$COMM_OUT/dmesg");
	&sign_it("$COMM_OUT/dmesg");
	}

if (-x $DF) {
	&date_stamp("$COMM_OUT/df");
	&redirect_command($DF, ">>$COMM_OUT/df");
	&sign_it("$COMM_OUT/df");
	}

#
# suns...
#
if (($OS eq "SUNOS4") || ($OS eq "SUNOS5")) {
	if (-x $SHOWREV) {
		&date_stamp("$COMM_OUT/showrev");
		&redirect_command($SHOWREV, "-p", ">>$COMM_OUT/showrev");
		&sign_it("$COMM_OUT/showrev");
		}
	if (-x $EEPROM) {
		&date_stamp("$COMM_OUT/eeprom");
		&redirect_command($EEPROM, ">>$COMM_OUT/eeprom");
		&sign_it("$COMM_OUT/eeprom");
		}
	if (-x $FORMAT) {
		&date_stamp("$COMM_OUT/format");
		# this should be safe... cross fingers ;-)
		&redirect_command("$FORMAT", ">>$COMM_OUT/format");
		&sign_it("$COMM_OUT/format");
		}
	}

# sunos
if ($OS eq "SUNOS4") {
	if (-x $IPCS) {
		&date_stamp("$COMM_OUT/ipcs");
		&redirect_command($IPCS, "-a", ">>$COMM_OUT/ipcs");
		&sign_it("$COMM_OUT/ipcs");
		}
	if (-x $DEVINFO) {
		&date_stamp("$COMM_OUT/devinfo");
		&redirect_command($DEVINFO, "-vp", ">>$COMM_OUT/devinfo");
		&sign_it("$COMM_OUT/devinfo");
		}
	}

# solaris
if ($OS eq "SUNOS5") {
	#
	# looks the same as sunos, different arg
	#
	if (-x $IPCS) {
		&date_stamp("$COMM_OUT/ipcs");
		&redirect_command("$IPCS", "-A", ">>$COMM_OUT/ipcs");
		&sign_it("$COMM_OUT/ipcs");
		}
	if (-x $SWAP) {
		&date_stamp("$COMM_OUT/swap");
		&redirect_command($SWAP, "-l", ">>$COMM_OUT/swap");
		&sign_it("$COMM_OUT/swap");
		}
	if (-x $PKGINFO) {
		&date_stamp("$COMM_OUT/pkginfo");
		&redirect_command($PKGINFO, ">>$COMM_OUT/pkginfo");
		&sign_it("$COMM_OUT/pkginfo");
		}
	# the useful df...
	if (-x $DF) {
		&date_stamp("$COMM_OUT/df2");
		&redirect_command($DF, "-k", ">>$COMM_OUT/df2");
		&sign_it("$COMM_OUT/df2");
		}
	}

# linux/redhat
if ($OS eq "LINUX2") {
	if (-x $RPM) {
		&date_stamp("$COMM_OUT/rpm");
		&redirect_command($RPM, "-a", "-q", ">>$COMM_OUT/rpm");
		&sign_it("$COMM_OUT/rpm");
		}
	}

# Kernel modules.

if (-x $LSMOD) {
	&date_stamp("$COMM_OUT/lsmod");
	&redirect_command($LSMOD, ">>$COMM_OUT/lsmod");
	&sign_it("$COMM_OUT/lsmod");
	}

if (-x $MODINFO) {
	&date_stamp("$COMM_OUT/modinfo");
	&redirect_command($MODINFO, ">>$COMM_OUT/modinfo");
	&sign_it("$COMM_OUT/modinfo");
	}

if (-x $MODSTAT) {
	&date_stamp("$COMM_OUT/modstat");
	&redirect_command($MODSTAT, ">>$COMM_OUT/modstat");
	&sign_it("$COMM_OUT/modstat");
	}

print "Running lastcomm - this could take awhile (in &suck_hostinfo())\n" if $verbose;

if (-x $LASTCOMM) {
	&date_stamp("$COMM_OUT/lastcomm");
	&redirect_command($LASTCOMM, ">>$COMM_OUT/lastcomm");
	&sign_it("$COMM_OUT/lastcomm");
	}

}

if (!$running_under_grave_robber) {
	$verbose = $debug = 1;
	require "lib/ostype.pl";
	require "lib/command.pl";
	require "lib/dig-sig.pl";
	&determine_os();

	&suck_hostinfo();
	}

1;

