#! /bin/bash
#
# please run this file after gallery has crashed to create bug report
#

b()
{
	echo "$*" >> /tmp/gallery-bugreport
	printf "\033[0;36m%s\033[0m\n" "$*"
}

echo "This script attempts to create bug report for gallery"
printf "lines printed in \033[0;36mblue\033[0m are sent to file\n"
echo "/tmp/gallery-bugreport which is genrated bug report and should be sent to me."
echo
b "*** automaticly generated gallery bug report ***"
b "*** please send to <malekith@topnet.pl> ***"
b `gallery --version`
b `gallery --options`
b "*** OS info ***"
b `uname -a`
b Libc: /lib/libc-*
if [ -f /etc/redhat-release ]
then
	b `cat /etc/redhat-release`
	echo "You are running RedHat, am I right ? If not, type your"
	echo "distribution and press enter. Otherwise press enter."
	echo -n "> "
	read
	b $REPLY
else
	# i have no idea how to detect anything else
	echo "Please type name and version of your distribution and"
	echo "press enter"
	echo -n "> "
	read
	b $REPLY
fi

if [ -f core ]
then
	echo "core file found. genrating back trace, this can take a while..."
	b "*** gdb back trace ***" 
	echo bt > /tmp/gdbc
	echo q >> /tmp/gdbc
	b "`gdb -q gallery core -x /tmp/gdbc`"
	rm /tmp/gdbc
else
	echo "core dump not found. "
	echo "maybe there was no coredump or you are not in directory in"
	echo "question. if the bug isn't of that kind, which"
	echo "causes signals or coredumps (you got some message from gallery"
	echo "itself, image was displayed incorrectly and so on)" 
	echo "your're finish with this script."
	echo "Else you may run command (in bash)"
	printf "        \033[1;37mulimit -c unlimited\033[0m\n"
	echo "run gallery again, with the same arguments, and check if it will"
	echo "crash. then run this script again."
	b "*** no core file ***"
	echo "Do you want to try unlimit core and try to crash gallery again / "
	echo "change directory ?"
	echo "y[enter] for yes, anything else for no..."
	read a
	if [ x$a = xy ]
	then
		echo "ok... so try and thnx for your patience"
		exit 0
	fi
fi
b "---==={ now, please describe a bug }===---"
echo
echo "Thnx for your help."
echo
echo "Now you should edit file /tmp/gallery-bugreport and describe a bug and then"
echo "send it to me with e-mail:"
echo "<malekith@topnet.pl>"
echo
