#!/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

echo
echo "Getting system configuration information."
echo
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 free disk space:"
catifexec "/bin/df" "-al"
STATUS="Checking currently running processes:"
catifexec "/bin/ps" "auxww"
STATUS="Checking current process tree:"
catifexec "/usr/bin/pstree"
STATUS="Collecting information about ld.so:"
catiffile "/etc/ld.so.conf"

echo "Collecting information about currently installed packages:"
echo -n "This may take several minutes...."
/bin/rpm -qa > $ROOT/installed-rpms
/bin/rpm -Va > $ROOT/rpm-Va
echo_success

STATUS="Getting bootloader information:"
/bin/ls -alR /boot > $ROOT/ls-boot 2>&1
# This covers sparc, alpha, and intel (respectively)
# updated for grub -mpg
if [ -f /etc/silo.conf ]; then
  STATUS="Collecting information about the boot process (silo):"
  catiffile "/etc/silo.conf"
fi
if [ -f /etc/milo.conf ]; then
  STATUS="Collecting information about the boot process (milo):"
  catiffile "/etc/milo.conf"
fi
if [ -f /etc/lilo.conf ]; then
  STATUS="Collecting information about the boot process (lilo):"
  catiffile "/etc/lilo.conf"
  catifexec "/sbin/lilo" "-q"
fi
if [ -d /boot/grub ]; then
  STATUS="Collecting information about the boot process (grub):"
  catiffile "/boot/grub/grub.conf"
  catiffile "/boot/grub/device.map"
fi

STATUS="Collecting information about X:"
catiffile "/etc/X11"
STATUS="Gathering sysctl information:"
catiffile "/proc/sys"
catiffile "/etc/sysctl.conf"
STATUS="Collecting information about cron:"
for x in `/bin/ls -d /etc/cron*` ; do
  catiffile "$x"
done
STATUS="Gathering IP information (/sbin/ifconfig):"
catifexec "/sbin/ifconfig" "-a"
STATUS="Checking network routes:"
catifexec "/sbin/route" "-n"
STATUS="Collecting system configuration information"
catiffile "/etc/sysconfig"
STATUS="Collecting information about system authentication (pam)"
catiffile "/etc/pam.d"

echo
echo "Getting information about the kernel."
echo
STATUS="Getting kernel version:"
catifexec "/bin/uname" "-a"
STATUS="Checking module information:"
catifexec "/sbin/lsmod"
STATUS="Currently getting ksysms information:"
catifexec "/sbin/ksyms"
STATUS="Gathering information about your filesystems:"
catiffile "/proc/filesystems"
STATUS="Gathering information about your system stat:"
catiffile "/proc/stat"
STATUS="Gathering information about your partitions (/proc/partitions):"
catiffile "/proc/partitions"
STATUS="Gathering information about your ksysms:"
catiffile "/proc/ksyms"

# 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


echo
echo "Getting information about the hardware."
echo
STATUS="Collecting information from the proc directory:"
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 ide drivers:"
catiffile "/proc/ide"
STATUS="Gathering information about your bus:"
catifexec "/sbin/lspci" "-vm"

echo
echo "Getting disk and filesystem information."
echo
STATUS="Collecting information from /etc/fstab:"
catiffile "/etc/fstab"
STATUS="Collecting disk partition information:"
PATH=/bin getpartinfo > $ROOT/fdisk-l
STATUS="Checking mounted file systems:"
catifexec "/bin/mount"
catiffile "/proc/mounts"
STATUS="Collecting Software RAID information:"
catiffile "/proc/mdstat"
catiffile "/etc/raidtab"

echo
echo "collecting information about commonly used network services"
echo
# 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
ftpconfigfiles=`/bin/ls -d /etc/ftp* 2>/dev/null`  
  STATUS="Collecting information about the ftp servers:"
  for x in $ftpconfigfiles; do
    STATUS="Collecting information about the ftp servers:"
    catiffile "$x"
  done


KERNELMIN=`/bin/uname -r | /bin/sed -e 's,[^\.]*\.,,' -e 's,\..*,,'`
ipchainsmod=`/sbin/lsmod | /bin/grep ipchains`

if [ "$KERNELMIN" -lt 3 ] || [ -n $ipchainsmod ] ; then
  STATUS="Getting ipchains information:"
  catifexec "/sbin/ipchains" "-nvL"
elif [ "$KERNELMIN" -gt 3 ]; then
  STATUS="Getting iptables information:"
  /bin/echo "<--iptables -t filter -nvL-->" > $ROOT/iptables
  /sbin/iptables -t filter -nvL >> $ROOT/iptables
  /bin/echo "<--iptables -t mangle -nvL-->" >> $ROOT/iptables
  /sbin/iptables -t mangle -nvL >> $ROOT/iptables
  /bin/echo "<--iptables -t nat -nvL-->" >> $ROOT/iptables
  /sbin/iptables -t nat -nvL >> $ROOT/iptables
  echo_success
fi

#sendmail
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="Getting files from /etc/mail"
for f in `/bin/ls -d /etc/mail/* | /bin/grep -v \.db`; do
  catiffile $f
done

STATUS="Collecting host resolution information"
catiffile "/etc/resolv.conf"
# 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

echo
echo "Gathering information from system logs"
echo
STATUS="Collecting information from dmesg:"
catiffile "/var/log/dmesg"
STATUS="Collecting messages and system accounting information"
catiffile "/var/log/messages"
catiffile "/var/log/sa"
catiffile "/var/log/XFree86.0.log"


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.$$
if [ -x /usr/bin/bzip2 ]; then
  /usr/bin/bzip2 $NAME.$$.tar
  SUFFIX="tar.bz2"
else 
  /bin/gzip -9 $NAME.$$.tar
  SUFFIX="tar.gz"
fi
/bin/rm -Rf $NAME.$$
/bin/echo 
/bin/echo "Please send /tmp/${NAME}.${$}.${SUFFIX} to your support"
/bin/echo "representative."
/bin/echo 

# changes (done by Mike Gahagan, mgahagan@redhat.com)
# 3-7-2002
# getpartinfo function to replace sysreport-fdisk
# Get all of /etc/X11, not just the config file.
# 3-8-2002
# Make df only check local filesystems
# Add grub, iptables, bzip2 the tar file if available, add rpm -Va as
# an additional check.
# /var/log/sa and Xfree86 logs 
# Get more sendmail config files (/etc/mail)
# 3-12-2002
# Grab software raid config files
# various cleanups and fixes
