#!/bin/sh
#
#ident	"@(#)system_info.sh	1.18	04/12/15 SMI"
#
# Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
DIR=bin

bus_type() {
        echo "\n\tYour system has at least the following bus types"
#comment by carson for resolving dead loop when getting ISA infomation 2004/08/04 
# ls -l /devices | awk '{print $9}' > /tmp/bus.$$ 2>&1
        ls -l /devices | awk '{print $9}' > /tmp/bustype.$$ 2>&1
#        cat /tmp/bus.$$ | while read bus_type
        cat /tmp/bustype.$$ | while read bus_type
        do
                case $bus_type in
                eisa)
                        echo "\t\tEISA" ;;
                isa)
                        echo "\t\tISA" ;;
                #pci*)
		#	echo "\t\tPCI" ;;  using the following way to probe
                mc)
                        echo "\t\tMCA" ;;
                pcmcia)
                        echo "\t\tPCMCIA" ;;
                esac
        done

#	$DIR/kvars -e
#	if [ $? -eq 0 ]
#	then
#		echo "\t\tPCI\t(`$DIR/kvars -p`)"
#	fi
	$DIR/all_devices -p

#	rm -rf /tmp/bus.$$	
	rm -rf /tmp/bustype.$$	
}

eval `id | sed 's/([^)]*)//g'`
[ "$uid" != "0" ] && echo "You must be root to run this program" && exit 0

echo "\nSystem Configuration\n"
hostname=`uname -n`
line_num=`cat /etc/hosts | awk '{ print $2 }' | grep -n "^$hostname$" | cut -f1 -d:`
echo "\tHostname: $hostname, IP Address: `cat /etc/hosts | sed -n "${line_num}p" | awk '{print $1}'`"
echo "\n\t`cat /etc/release | head -1 | sed -e 's/.*Sol/Sol/g'`"

isainfo -v > /tmp/isainfo_tmp
while read isainfo_var
do
        isainfo_var_head=`echo $isainfo_var | awk '{print $1}'`
        case $isainfo_var_head in
        32-bit)
                echo "\t$isainfo_var" ;;
        64-bit)
                echo "\t$isainfo_var" ;;
        *)
                echo "\t\t$isainfo_var" ;;
        esac
done < /tmp/isainfo_tmp
echo "\n"
rm -f /tmp/isainfo_tmp
#echo "\t\t`isainfo -v` \n"

#$DIR/kvars | sed -e 's/,.*MHZ//g'
#$DIR/all_devices
if [ -f /tmp/all_dev_tmp ]
then
	rm -f /tmp/all_dev_tmp
fi
$DIR/all_devices -m 

$DIR/all_devices -u > /tmp/all_dev_tmp
vir_cpu_no=`cat /tmp/all_dev_tmp | grep "Number of CPUs:" |awk '{print $4}'`
phy_cpu_no=`psrinfo -p` 
if [ $vir_cpu_no = $phy_cpu_no ]
then
	cat /tmp/all_dev_tmp
else	
	while read all_dev_var
	do
       		all_dev_var_head=`echo $all_dev_var | awk '{print $1}'`
        	case $all_dev_var_head in
        	CPU)
               		if [ `echo $all_dev_var | awk '{print $2}'` = "Info" ]
                	then
                       		echo "\t$all_dev_var"
                	else
                       		echo "\t\t$all_dev_var"
                	fi ;;
        	Number)
			if [ `echo $all_dev_var | awk '{print $3}'` = "CPUs:" ]
               		then
                        	echo "\t\t$all_dev_var" | sed "s/$vir_cpu_no/$phy_cpu_no/"
                	elif [ $vir_cpu_no -gt $phy_cpu_no ]
                	then
                       		echo "\t\t$all_dev_var (Hyperthread option is set in BIOS)"
                	else
                       		echo "\t\t$all_dev_var"
                	fi ;;

        	esac

	done < /tmp/all_dev_tmp
fi
rm -f /tmp/all_dev_tmp

#echo "\t\tCPU speed: `psrinfo -v | grep MHz | head -1 | awk '{ print $6 }'` MHz"
bus_type
rm -rf /tmp/tmp_data

sh ./disk_info.sh
sh ./drivers_info.sh

echo
echo "		Network configuration:"
echo
               echo
               echo "Host Name: "`uname -n`
               echo "NIS Domain Name: "`domainname`
               sh ./net_info.sh
               echo
#<Begin> Modified by Martin Mei for bug 4995428, there is "<" which is looked as mark flag by html protocol, and the origional information cannot be output if not replace the "<"
               ifconfig -a | sed 's/</(/g' | sed 's/>/)/g'  
#<End> Modification
echo
echo "......................................................................"
echo
echo "		System Software Configuration:				    "
echo
echo
./mode_info.sh
echo
sh ./whatami 2>/dev/null
             if [ $? -ne 0 ]
             then echo "Cannot reach ./whatami to get information."
                  echo "Make sure ./whatami is accessible."
             fi       
echo "......................................................................"
