#!/bin/bash
#
# Name: system_info.sh
# Copyright: (C)2004 Hewlett-Packard Company
#
# Description: gathers system information and bundles it together
#              into a tarball
# 
# CD	03/01/04 Initial Development
# CD    06/11/04 Changes for SLES 9 (2.6 kernel)

write_file () {
 echo $1 >> $SYSINFOFILE
}

SYSINFODIR="/tmp"
SYSINFOFILE="/tmp/system_info.txt"
TARBALL="/tmp/system_info.tar"
PROCSCSI="/tmp/proc_scsi.txt"
PROCQLA="/tmp/proc_qla.txt"
FILELIST="system_info.txt proc_scsi.txt proc_qla.txt messages"
LSSD="/opt/hp/hp_fibreutils/lssd"

# init files

rm -f $TARBALL.gz
rm -f $SYSINFOFILE
rm -f $PROCSCSI
rm -f $PROCQLA
echo -n "" > $SYSINFOFILE
echo -n "" > $PROCQLA

# write out system information file

echo "Capturing System Information..."
write_file "   System Information"
write_file "------------------------"
write_file ""
write_file "Date: `date`"
write_file ""
cat /etc/issue >> $SYSINFOFILE
write_file "Hostname: `hostname`"
write_file "Kernel: `uname -r`"

# print whether system is running a uniprocessor or
# an SMP kernel

if [ "`cat /proc/version | grep SMP`" = "" ]
then
 write_file "Kernel is uniprocessor"
else
 write_file "Kernel is SMP"
fi

write_file "Architecture: `uname -m`"
write_file "LVM version: `rpm -q lvm`"
write_file ""
write_file "CPU Info:"
write_file ""
cat /proc/cpuinfo >> $SYSINFOFILE
write_file ""
write_file "Memory Info:"
write_file ""
cat /proc/meminfo >> $SYSINFOFILE
write_file ""
write_file "Process Info:"
write_file ""
ps -eaf >> $SYSINFOFILE
write_file ""
write_file "PCI Bus Info:"
write_file ""
lspci >> $SYSINFOFILE
write_file ""
write_file "Module Info"
write_file ""
lsmod >> $SYSINFOFILE
write_file ""
write_file "Disk Info:"
write_file ""
$LSSD >> $SYSINFOFILE
write_file ""
write_file "Filesystem Info:"
write_file ""
df -Tk >> $SYSINFOFILE
write_file ""

# determine if we need to look at EFI directories

if [ "`uname -m`" = "ia64" ]
then
 if [ -d /boot/efi/efi/redhat ]
 then
	EFIDIR="/boot/efi/efi/redhat"
 else
	EFIDIR="/boot/efi/suse"
 fi

 write_file "Contents of $EFIDIR:"
 ls -l $EFIDIR >> $SYSINFOFILE
 write_file ""
fi

write_file "qla2x00 RPM installed: `rpm -q qla2x00`"
write_file "hp_qla2x00 RPM installed: `rpm -q hp_qla2x00`"
write_file "hp_qla2x00src RPM installed: `rpm -q hp_qla2x00src`"
write_file "fibreutils RPM installed: `rpm -q fibreutils`"

# capture /proc/scsi/scsi

echo "Capturing /proc/scsi/scsi..."
cat /proc/scsi/scsi >> $PROCSCSI

# capture /proc/scsi/qla2200

if [ -d /proc/scsi/qla2200 ]
then
 echo "Capturing /proc/scsi/qla2200..."
 more /proc/scsi/qla2200/* >> $PROCQLA
fi

# capture /proc/scsi/qla2300

if [ -d /proc/scsi/qla2300 ]
then
 echo "Capturing /proc/scsi/qla2300 directory"
 more /proc/scsi/qla2300/* >> $PROCQLA
fi

# capture /proc/scsi/qla2xxx

if test -d /proc/scsi/qla2xxx
then
 echo "Capturing /proc/scsi/qla2xxx directory"
 more /proc/scsi/qla2xxx/* >> $PROCQLA
fi

# make tar file

cp /var/log/messages /tmp
cd $SYSINFODIR
echo "Making system information archive $TARBALL.gz"
tar cvf $TARBALL $FILELIST 1>/dev/null
gzip $TARBALL

# clean up

rm -f $SYSINFOFILE
rm -f $PROCSCSI
rm -f $PROCQLA
rm -f /tmp/messages

