#!/bin/sh
# Generated automatically from nntpcache-gdb.sh.in by configure.
PATH=$PATH:/bin:/sbin:/usr/bin:/usr/sbin:/usr/ucb:/usr/local/bin:/usr/local/sbin:/opt/gnu:/opt/gnu/bin:/usr/local/gnu:/usr/local/gnu/bin:${exec_prefix}/bin:/usr/pkg/bin
export PATH

cdir="$1"
prog="$2"
pid="$3"
ver="$4"
msg="$5"
to=nntpcache-gdb-bug-reports@nntpcache.com
sub="$ver `uname -s -p -r 2>/dev/null || uname -a 2>/dev/null || uname 2>/dev/null` $msg"
gdb=/usr/bin/gdb
prefix=/usr/pkg
exec_prefix=/usr/pkg
sbindir=${exec_prefix}/sbin
libexec=${exec_prefix}/libexec

getcore () {
    rm -f .debugimage
    core=""
    for n in *core* /var/core*/core.nntpcached /var/core*/core.nntpcached.$pid; do
	if test -r $n; then
	    core="$n"
	    break
	fi
    done
    if [ -z "$core" ]; then
	echo ""
	rm -f *core*
	return 1
    else
	mv $core .debugimage
	echo .debugimage
	rm -f *core*
	return 0
    fi
}

find_prog () {
  pr="$1"
  old_ifs="${IFS:-\" \"}"
  IFS=":"
  path_ifs="$PATH"
  for dir in $path_ifs; do
    test -z "$dir" && dir=.
    if test -e "$dir/$pr"; then
	echo "$dir/$pr"
	IFS="$old_ifs"
	return 0
    fi
  done
  IFS="$old_ifs"
  return 1
}

p2=`basename $prog`
for n in $libexec/nntpcached.debug $prog $sbindir/$prog `find_prog $p2`; do
    if test -r $n; then
	prog=$n
	break
    fi
done

(
echo === uname -a
uname -a
echo === id
id
echo === cdir
echo $cdir
echo === prog
echo $prog
echo === pid
echo $pid
if cd $cdir; then
    core=`getcore`
    if [ -n "$core" ]; then
	echo === core
	echo $core
	echo === gdb
	exec $gdb -batch -n -q -x $libexec/nntpcache.gdb $prog $core 2>&1 </dev/null
    fi
fi
)| ( mail -s "$sub" $to || mailx -s "$sub" $to || elm -s "$sub" $to || mail $to ) >/dev/null 2>&1
