#! /bin/sh

echo "Wait a minute, I must summary information about Perl, OS, Tk, DBI etc."

UN=`uname -a`

: ${EDITOR=vi}

if [ -f /usr/lib/sendmail ]; then
	BUGMAIL="/usr/lib/sendmail -i"
elif [ -f /usr/sbin/sendmail ]; then
	BUGMAIL="/usr/sbin/sendmail -i"
else
	BUGMAIL="mail"
fi

ENV=`printenv | sort | perl -pe 's/^/\t/;'` || ENV=`set | sort | perl -pe 's/^/\t/;'`
PERLINF=`perl -V | perl -pe 's/^/\t/;'`
TKVER=`perl -MTk -e 'print $Tk::VERSION;'`
DBIVER=`perl -MDBI -e 'print $DBI::VERSION;'`
SOCKVER=`perl -MIO::Socket -e 'print $IO::Socket::VERSION;'`
STVER=`perl -MStorable -e 'print $Storable::VERSION;'`

cat <<EOF >/tmp/dbmanbug.$$
From: ${USER}
To: sorm@fi.muni.cz
Subject: dbMan bug report - [short description]

Version of dbMan:
	0.1.0

Description:
	[Detailed description of the problem, suggestion or complaint.]

Repeat-By:
	[Describe the sequence of events that causes the problem to occur.]

Fix:
	[Description of how to fix to problem. If you don't know a fix for
	the problem, don't include this section.]

---------------------------------------------------------------------------
Configuration information generated automatically:

uname output: 
	$UN

Perl information:
$PERLINF
	
Tk version:
	$TKVER

DBI version:
	$DBIVER

IO::Socket version:
	$SOCKVER

Storable version:
	$STVER

Environment:
$ENV

.
EOF

cp /tmp/dbmanbug.$$ /tmp/dbmanbug.$$.work

if $EDITOR /tmp/dbmanbug.$$ ; then
	if cmp -s /tmp/dbmanbug.$$ /tmp/dbmanbug.$$.work ; then
		echo "File not changed, no bug report submitted."
		rm -f /tmp/dbmanbug.$$
		rm -f /tmp/dbmanbug.$$.work
		exit
	fi
	
	${BUGMAIL} sorm@fi.muni.cz </tmp/dbmanbug.$$.work || {
		cat /tmp/dbmanbug.$$.work >>$HOME/dead.dbmanbug
		echo "$0: mail failed, report saved in $HOME/dead.dbmanbug" >&2
	}
fi

rm -f /tmp/dbmanbug.$$
rm -f /tmp/dbmanbug.$$.work

exit 0
