#!/bin/sh
#
# Collect support information
#
# Copyright (C) 2005, Digium, Inc.
#
# Written by John Bigelow (support@digium.com)
#
# Distributed under the terms of the GNU General Public
# License
#

OUTPUT=$HOME/digiuminfo.txt

MYUID=$(id -u);

if [ $MYUID -ne  0 ]; then

  echo "You must be root to run this."
  exit 1
fi

clear

echo
echo "This will gather information about your system such as:"
echo "pci listing, dmesg, running processes, and kernel version"
echo "This may take up to half a minute to run. Please be patient."
echo "To continue press 'y', to quit press any other key"
read ans

if [ "$ans" = "y" ]; then

  rm -f $OUTPUT

  echo "------------------" >> $OUTPUT;
  echo "PCI LIST" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  lspci -vvvb >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "PCI LIST(no lookup)" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  lspci -vvvbn >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "INTERRUPTS" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  cat /proc/interrupts >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "RUNNING PROCESSES" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  ps aux >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "KERNEL VERSION" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  uname -a >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "CPU INFO" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  cat /proc/cpuinfo >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "VERSION INFO" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  cat /proc/version >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "CMDLINE INFO" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  cat /proc/cmdline >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "KERNEL CONFIG" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  echo "/lib/modules/$(uname -r)/build/.config:" >> $OUTPUT;
  cat /lib/modules/$(uname -r)/build/.config >> $OUTPUT;
  echo >> $OUTPUT;
  echo "/usr/src/linux/.config:" >> $OUTPUT;
  cat /usr/src/linux/.config >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "DAHDI MODULE INFO" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  modinfo /lib/modules/$(uname -r)/dahdi/*.ko >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "OTHER INFO" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  echo "/etc/*issues*:" >> $OUTPUT;
  cat /etc/*issues* >> $OUTPUT;
  echo >> $OUTPUT;
  echo "/etc/*release*:" >> $OUTPUT;
  cat /etc/*release* >> $OUTPUT;
  echo >> $OUTPUT;
  echo "/etc/*motd*:" >> $OUTPUT;
  cat /etc/*motd* >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "LOADED MODULES" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  lsmod >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "DAHDI_TEST" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  dahdi_test -c 20 >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "DMESG OUTPUT" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  dmesg >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "DMIDECODE" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  dmidecode >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "DAHDI CONFIG" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  grep -v '^#' /etc/dahdi/system.conf >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "CHAN_DAHDI CONFIG" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  grep -v '^;' /etc/asterisk/chan_dahdi.conf >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

  echo "------------------" >> $OUTPUT;
  echo "EXTENSIONS CONFIG" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;
  grep -v '^;' /etc/asterisk/extensions.conf >> $OUTPUT;
  echo >> $OUTPUT;
  echo >> $OUTPUT;

else
  echo "terminated";
exit
fi

clear

echo
echo "Digium may require root level access to the system to help debug";
echo "the problem you are experiencing. Do you want to provide login";
echo "information at this time? Please note that if you do so, change";
echo "your root password to a secure temporary password for Digium support";
echo "Press 'y' for yes and any other key to exit and save the previous info collected"
read login

if [ "$login" = "y" ]; then

  echo "------------------" >> $OUTPUT;
  echo "LOGIN INFORMATION" >> $OUTPUT;
  echo "------------------" >> $OUTPUT;

  echo
  echo "What is your root password?"
  read rootpass

  echo
  echo "Root pass: "$rootpass >> $OUTPUT

  echo
  echo "What is your PUBLIC IP address?"
  read ip

  echo "IP address: "$ip >> $OUTPUT

  echo
  echo "Please provide any other login information that the technician"
  echo "may need to know to login to the system'(press enter if not)'"
  read adinfo

  echo "Additional login info: "$adinfo >> $OUTPUT

  clear
  echo
  echo "All information has been stored in $OUTPUT,"
  echo "Please attach this file to an email case you already"
  echo "have open with Digium Tech Support."

else
  clear
  echo
  echo "All information except login info has been stored in $OUTPUT,"
  echo "Please send this file to an email case you already"
  echo "have open with Digium Tech Support."
exit
fi
