#!/bin/bash
#
#  System Report, by Wil Harris <wil@redhat.com> and Peter Jones <pjones@redhat.com>.
#
umask 0077
ROOT=/tmp/sysreport.$$
UTILDIR=/usr/share/sysreport
VER=`/bin/uname -r`
if [ -f $UTILDIR/functions ]; then
  . $UTILDIR/functions
else 
  echo "Sysreport is not properly installed"
  exit 1
fi
if [ $UID != 0 ]; then
  echo "You must be root to use this utility"
  exit 1
fi
rm -rf $ROOT
mkdir $ROOT
PATH=""

echo "This utility will go through and collect some detailed information "
echo "about the hardware and setup of your Red Hat Linux system."
echo "This information will be used to diagnose problems with your system,"
echo "and will be considered confidential information.  Red Hat will use"
echo "this information for diagnostic purposes ONLY. "
echo
echo "Please wait while we collect information about your system."
echo
echo "This process may take awhile to complete...."
echo "No changes will be made to your system during this process."
echo
echo "Press ENTER to continue, or CTRL-C to quit."
read IGNORE
STATUS="Determining Red Hat Linux version:"
catiffile "/etc/redhat-release"
STATUS="Determinding your current hostname: " 
catifexec "/bin/hostname"
STATUS="Getting the date:"
catifexec "/bin/date"
STATUS="Checking your systems current uptime and load average:"
catifexec "/usr/bin/uptime"
STATUS="Checking available memory:"
catifexec "/usr/bin/free"
STATUS="Checking currently running processes:"
catifexec "/bin/ps" "auxww"
STATUS="Checking current process tree:"
catifexec "/usr/bin/pstree"
STATUS="Currently getting ksysms information:"
catifexec "/sbin/ksyms"
STATUS="Looking at your systems partition information:"
catifexec "/usr/share/sysreport/sysreport-fdisk"
STATUS="Checking mounted file systems:"
catifexec "/bin/mount"
STATUS="Getting kernel version:"
catifexec "/bin/uname" "-a"
STATUS="Checking module information:"
catifexec "/sbin/lsmod"
STATUS="Collecting information regarding kernel modules"
catiffile "/lib/modules/$VER/modules.dep"
catiffile "/etc/conf.modules"
STATUS="Collecting information about ld.so:"
catiffile "/etc/ld.so.conf"
STATUS="Checking free disk space:"
catifexec "/bin/df" "-a"
STATUS="Collecting information about currently installed packages:"
catifexec "/bin/rpm" "-qa"
STATUS="Getting bootloader information:"
catifexec "/sbin/lilo" "-q"
/bin/ls -l /boot > $ROOT/boot
STATUS="Collecting information about your mountpoints:"
catiffile "/etc/fstab"
STATUS="Collecting information about the boot process (lilo.conf):"
catiffile "/etc/lilo.conf"
STATUS="Collecting information about the boot process (silo.conf):"
catiffile "/etc/silo.conf"
STATUS="Collecting information about the boot process (milo.conf):"
catiffile "/etc/milo.conf"
STATUS="Collecting information from dmesg:"
catiffile "/var/log/dmesg"
STATUS="Collecting information from system logs:"
catiffile "/var/log/messages"
STATUS="Collecting information about X:"
catiffile "/etc/X11/XF86Config"
STATUS="Collecting information from the proc directory:"
echo
echo "Currently gathering information from /proc/pci:"
echo
catiffile "/proc/pci"
STATUS="Gathering information about your CPU:"
catiffile "/proc/cpuinfo"
STATUS="Gathering information about your Ram:"
catiffile "/proc/meminfo"
STATUS="Gathering information about your ioports:"
catiffile "/proc/ioports"
STATUS="Gathering information about your interrupts:"
catiffile "/proc/interrupts"
STATUS="Gathering information about your scsi devices:"
catiffile "/proc/scsi"
STATUS="Gathering information about your dma:"
catiffile "/proc/dma"
STATUS="Gathering information about your devices (/proc/devices):"
catiffile "/proc/devices"
STATUS="Gathering information about your rtc:"
catiffile "/proc/rtc"
STATUS="Gathering information about your filesystems:"
catiffile "/proc/filesystems"
STATUS="Gathering information about your system stat:"
catiffile "/proc/stat"
STATUS="Gathering information about your ide drivers:"
catiffile "/proc/ide/drivers"
STATUS="Gathering information about your sound devices:"
catiffile "/proc/sound"
STATUS="Gathering information about your partitions (/proc/partitions):"
catiffile "/proc/partitions"
STATUS="Gathering information about your ksysms:"
catiffile "/proc/ksyms"
STATUS="Gathering information about your bus (/proc/bus):"
catiffile "/proc/bus"
STATUS="Gathering information about your IDE harddrives:"
for x in `/bin/ls -d /proc/ide/hd*` ; do
  catiffile "$x"
done
STATUS="Collecting information about cron:"
for x in `/bin/ls -d /etc/cron*` ; do
  catiffile "$x"
done
echo
echo "Gathering network information:"
echo
STATUS="Gathering IP information (/sbin/ifconfig):"
catifexec "/sbin/ifconfig" "-a"
STATUS="Checking network routes:"
catifexec "/sbin/route" "-n"
STATUS="Collecting information about system services (inetd.conf)"
catiffile "/etc/inetd.conf"
STATUS="Collecting information about system services (inetd.d)"
catiffile "/etc/inetd.d"
STATUS="Collecting information from /etc/host,host.allow, etc:"
for x in `/bin/ls -d /etc/host*` ; do
  catiffile "$x"
done
STATUS="Collecting information about the ftp servers:"
for x in `/bin/ls -d /etc/ftp*` ; do
  catiffile "$x"
done
STATUS="Getting ipchains information:"
catifexec "/sbin/ipchains" "-L"
STATUS="Sendmail Configuration (/etc/sendmail.cf):"
catiffile "/etc/sendmail.cf"
STATUS="Sendmail Machine aliases (/etc/sendmail.cw):"
catiffile "/etc/sendmail.cw"
STATUS="Sendmail User aliases (/etc/aliases):"
catiffile "/etc/aliases"
STATUS="Collecting host resolution information"
catiffile "/etc/resolv.conf"
STATUS="Collecting system configuration information"
catiffile "/etc/sysconfig"
STATUS="Collecting information about system authentication (pam)"
catiffile "/etc/pam.d"
STATUS="Collecting information about the nameserver (named.conf)"
catiffile "/etc/named.conf"
STATUS="Collecting information about the nameserver (named.boot)"
catiffile "/etc/named.boot"
DNSDIR=""
if [ -f /etc/named.conf ]; then
  DNSDIR=$(/bin/grep -i directory /etc/named.conf |/bin/gawk '{ print $2 ;}'|\
    /bin/sed s/\"//g|/bin/sed s/\;//g)
elif [ -f /etc/named.boot ]; then
  DNSDIR=$(/bin/grep -i directory /etc/named.boot|/bin/gawk '{ print $2 ;}')
fi

if [ -n $DNSDIR ]; then
  for x in $DNSDIR ; do
    STATUS="Collecting information about the nameserver ($DNSDIR)"
    catiffile "$DNSDIR"
  done
fi

cd /tmp
/bin/echo -n "Enter your first initial and last name (ex: jsmith): "
read NAME
if [ ! $NAME ]; then
  NAME=$LOGNAME.$HOSTNAME
fi
/bin/rm -rf $NAME.$$
/bin/mv sysreport.$$ $NAME.$$
PATH=/bin tar cf $NAME.$$.tar $NAME.$$
/bin/gzip -9 $NAME.$$.tar
/bin/rm -rf $NAME.$$
/bin/echo 
/bin/echo "Please mail /tmp/$NAME.$$.tar.gz to sysreport@redhat.com"
/bin/echo "with 'System Report' as the subject of the message."
/bin/echo 
