#!/usr/bin/perl

# ------------------  Needs more work.  This is VERY Linux centric code!  -----------

# inspect  (c) Copyright 1998 Mark Black 

# NOTE:  If you modify this code, you MUST change the version to
#        something over 100 to prevent it being replaced by future
#        versions of this script. 
$version = 1 ;

$input = "" ;
foreach $i (0 .. $#ARGV) {
   $input .= "@ARGV[$i] " ;
}
chop($input) ;

# Output the version if requested
if($input eq "-v") {
    print "$version\n" ;
    exit(0) ;
}

$debug = 0 ;      # Set to 1 to turn debug mode ;
# OS global variables
$dnsBindFile = "/etc/resolv.conf" ;

# Discover OS type and set variables for OS type
chop($os = `uname -s`) ;

if($os eq "Linux") {
    $ps_arg = "-auxww" ;
    $ypbindName = "ypbind" ;
    $dnsServerName = "named" ;
    $nisServerName = "ypserv" ;
    $lpdconf = "/etc/printcap" ;
    $lpdeamon = "lpd" ;
    $fstab = "/etc/fstab" ;

}else{
    $ps_arg = "-elf" ;
}

#  Run system commands all at once
@psout = `ps $ps_arg` ;
chop($domainName = `domainname`) ;

# Is NIS running?
if(grep(!/none/, $domainName)) {
    print "___ Domainname =  $domainName \n" unless $debug == 0 ;
    print "___ YPBind name = $ypbindName \n" unless $debug == 0 ;
    print grep(/$ypbindName/, @psout) ;
    if(grep(/$ypbindName/, @psout)) {
	print "NISclient: up\n" ;
	$NIS = 1 ;
    } else {
	print "NISclient: down\n" ;
	$NIS = 0 ;
    }
} else {
    print "NISclient: down\n" ;
    $NIS = 0 ;
}

# Is NIS Server running
if(grep(/$nisServerName/, @psout)) {
    print "NISServer: up\n" ;
} else {
    print "NISServer: down\n" ;
}


# Is DNS Client setup
if( -e $dnsBindFile ) {
    @dnsResolvConf = `cat $dnsBindFile` ;
    @dnsdomainLine = grep(/domain/, @dnsResolvConf) ;
    ($junk, $dnsDomain) = split(' ', @dnsdomainLine[0]) ;
    print "___ DNS domainname =  $dnsDomain \n" unless $debug == 0 ;
    if( $NIS == 1 ) {
	if( $dnsDomain eq $domainName) {
	    print "DNSclient: up\n" ;
	    $DNS = 1 ;
	} else {
	    print "DNSclient: NIS-DNS_domain_conflict \n" ;
	    $DNS = 1 ;
	}
    } else {
	print "DNSclient: up\n" ;
	$DNS = 1 ;
    }
} else {
    print "DNSclient: down\n" ;
    $DNS = 0 ;
}

# Is DNS Server Setup and running
if(grep(/$dnsServerName/, @psout)) {
    print "DNSServer: up\n" ;
} else {
    print "DNSServer: down\n" ;
}

# Is Printing running
if( -f $lpdconf ) {
    if(grep(/$lpdeamon/, @psout)) {
	print "LPD: up\n" ;
	$LPD = 1 ;
    } else {
	print "LPD: down\n" ;
	$LPD = 0 ;
    }
} else {
    print "LPD: unconfigured\n" ;
    $LPD = 0 ;
}

# Is there a printer
#
if($LPD == 1 ) {
    open(PRINTCAP, $lpdconf) ;
    @tmppcap = <PRINTCAP> ;
    close PRINTCAP ;
    @printcap = grep(!/^\s*\#/, @tmppcap) ;
    $cnt = 0 ;
    foreach $line (@printcap) {
	if( $line =~ /^\w/ ) {
	    # This is a new printer
	    $cnt++ ;
	    chop(@printer[$cnt] = $line) ;
	} else {
	    chop(@printer[$cnt] .= $line) ;
	}
    }
    print @printer unless $debug == 0 ;
    # Scan the printers for local devices
    @localprinters = grep(/\:lp=\//, @printer) ;
    # Note this will only find one local printer.  It's a workaround for aps
    
    if(@localprinters) {
	print "LOCALprinter: yes\n" ;
    } else {
	print "LOCALprinter: no\n" ;
    }
} else {
    print "LOCALprinter: unconfigured\n" ;
}

# Check UFS filestsystems









