#! /bin/sh
# -*- sh -*-
#
# $ApsCVS: src/apsfilter/bin/apsfilter-bug.in,v 1.1.2.1 2001/12/29 16:03:09 andreas Exp $
#
# apsfilter-bug  --  create a bug report and mail it to the bug address.
#

# create bug report template
TEMP=`mktemp -q /tmp/apsbug.XXXXXX 2>/dev/null`
if [ $? -ne 0 ]; then
    TEMP=/tmp/apsbug.$$
    echo > $TEMP
    chmod 600 $TEMP
fi
TEMP2=`mktemp -q /tmp/apsbug.XXXXXX 2>/dev/null`
if [ $? -ne 0 ]; then
    TEMP2=/tmp/apsbug.$$
    echo > $TEMP2
    chmod 600 $TEMP2
fi

trap 'rm -f $TEMP $TEMP2; exit 1' 1 2 3 13 15
trap 'rm -f $TEMP $TEMP2' 0

: ${EDITOR:=emacs}


cat > $TEMP <<EOF
#
# -= automatic apsfilter bug report =-
#
# Please add any information that might help us resolve the bug.
# Lines starting with '#' will be removed automatically.
#
#
# make this a valid e-mail address
From: $USER@$HOSTNAME
#
# don't change this unless you _absolutely_ know better
To: apsfilter-stable@apsfilter.org
#
# add a short description of the problem here
Subject: apsfilter bug:
#
# when did the error occur?
# (one of: configure, install, setup, usage, other, unknown)
>Error type:
#
# how can others repeat that error?
>How to repeat:
#
# VERY IMPORTANT:
# please read the handbook and/or manpage about using "aps2file -D ..."
# to create an error log, then insert that stuff here
# (does not apply to configure, install or setup errors)
>Error log:
#
# which settings in (global or local) apsfilterrc did you change?
>apsfilterrc changes:
#
# did you receive any error mails from apsfilter, and if so, which ones?
>Error mails:
#
# what did you expect to happen?
>Expected:
#
# if you already have a fix, please give us a description and/or
# a patch here (doesn't have to be elegant, just functional)
>Fix:
#
# any additional comment you'd like to add
>Comment:
#
# Thanks for your bug report!
#
# Now save the file (under its original name) and exit from your editor.
# If you don't want to submit this report, just exit without saving.
#
EOF

chmod u+w $TEMP2
cp $TEMP $TEMP2

eval $EDITOR $TEMP

if cmp -s $TEMP $TEMP2 ; then
    echo "File not changed, no bug report submitted."
    exit 1
fi

{
    # remove comment lines and add relevant details
    grep -v "^#" $TEMP

    gs_version=$(gs --version)
    system_id=$(uname -a)
    cat <<EOF

-------------------------------------------------
additional information (automatically generated):

apsfilter version:     7.2.7-stable
ghostscript version:   $gs_version
system identification: $system_id

configure options:     --prefix=/usr/local --sysconfdir=/etc --with-shell=/bin/sh --with-awk=/usr/bin/awk
    shell:             /bin/sh
    awk:               /usr/bin/awk
    sendmail:          /usr/sbin/sendmail
EOF
} > $TEMP2

if "/usr/sbin/sendmail" -oem -t < $TEMP2; then
    echo "apsfilter bug report has been sent"
    exit 0
else
    echo "unknown sendmail failure, bug report not sent"
    exit 1
fi
