#!/bin/bash
#
# System Report
# Copyright (c) 1999-2001 Red Hat, Inc. All rights reserved.
#
# Written by:
#     Wil Harris <wil@redhat.com>
#     Peter Jones <pjones@redhat.com>
#     Preston Brown <pbrown@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
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 "NOTE: You can safely ignore a failed message.This only means a file"
echo "we were checking for did not exist."
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"

# Added support to cover for the new modules.conf layout in Red Hat 7

STATUS="Collecting information regarding kernel modules"
catiffile "/lib/modules/$VER/modules.dep"
if [ -f /etc/conf.modules ]; then
  catiffile "/etc/conf.modules"
elif [ -f /etc/modules.conf ]; then
  catiffile "/etc/modules.conf"
fi

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"

# This covers sparc, alpha, and intel (respectively)

if [ -f /etc/silo.conf ]; then
  STATUS="Collecting information about the boot process (silo.conf):"
  catiffile "/etc/silo.conf"
elif [ -f /etc/milo.conf ]; then
  STATUS="Collecting information about the boot process (milo.conf):"
  catiffile "/etc/milo.conf"
elif [ -f /etc/lilo.conf ]; then
  STATUS="Collecting information about the boot process (lilo.conf):"
  catiffile "/etc/lilo.conf"
fi

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):"
catifexec "lspci" "-n"
catifexec "lspci" "-vn"

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"

# This covers backwards compatiablity for systems with inetd while keeping 
# support for the new 7.x xinetd

if [ -f /etc/inetd.conf ]; then
  STATUS="Collecting information about system services (inetd.conf)"
  catiffile "/etc/inetd.conf"
elif [ -f /etc/xinetd.conf ]; then
  STATUS="Collecting information about system services (xinetd.conf)"
  catiffile "/etc/xinetd.conf"
  STATUS="Collecting information about system services (xinetd.d)"
  for x in `/bin/ls -d /etc/xinetd.d/*`; do
    catiffile "$x"
  done
fi

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"
if [ -f /etc/sendmail.cw ]; then
  STATUS="Sendmail Machine aliases (/etc/sendmail.cw):"
  catiffile "/etc/sendmail.cw"
fi

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"

# Make sure we have support for both versions of bind

if [ -f /etc/named.boot ]; then
  STATUS="Collecting information about the nameserver (named.boot)"
  catiffile "/etc/named.boot"
elif [ -f /etc/named.conf ]; then
  STATUS="Collecting information about the nameserver (named.conf)"
  catiffile "/etc/named.conf"
fi

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 with no spaces (example: jsmith): "
/bin/echo 
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 
