#!/bin/sh
# Submit a problem report to a GNATS site.
# Copyright (C) 1993 Free Software Foundation, Inc.
# Contributed by Brendan Kehoe (brendan@cygnus.com), based on a
# version written by Heinz G. Seidl (hgs@cygnus.com).
#
# This file is part of GNU GNATS.
#
# GNU GNATS is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# GNU GNATS is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU GNATS; see the file COPYING. If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# The version of this send-pr.
VERSION=3.99
# The submitter-id for your site.
SUBMITTER=net
# Where the GNATS directory lives, if at all.
[ -z "$GNATS_ROOT" ] &&
GNATS_ROOT=
# The default mail address for PR submissions.
GNATS_ADDR=krb5-bugs@mit.edu
# Where the gnats category tree lives.
DATADIR=/usr/share
# If we've been moved around, try using GCC_EXEC_PREFIX.
[ ! -d $DATADIR/gnats -a -d "$GCC_EXEC_PREFIX" ] &&
DATADIR=/usr/share
# The default release for this host.
DEFAULT_RELEASE="1.10.3"
# The default organization.
DEFAULT_ORGANIZATION=
# The default site to look for.
GNATS_SITE=mit
# Newer config information?
[ -f ${GNATS_ROOT}/gnats-adm/config ] && . ${GNATS_ROOT}/gnats-adm/config
# What mailer to use. This must come after the config file, since it is
# host-dependent.
for dir in /usr/lib /usr/sbin /usr/ucblib; do
if test -f $dir/sendmail; then
MAIL_AGENT="$dir/sendmail -oi -t"
break
fi
done
# How to read the passwd database.
PASSWD="cat /etc/passwd"
if test -f /bin/domainname && test -n "`/bin/domainname`"; then
if test -f /usr/bin/niscat &&
/usr/bin/niscat passwd.org_dir > /dev/null 2>&1; then
PASSWD="/usr/bin/niscat passwd.org_dir"
elif test -f /usr/bin/ypcat && /usr/bin/ypcat passwd > /dev/null 2>&1; then
PASSWD="/usr/bin/ypcat passwd"
fi
fi
# Figure out how to do "echo -n"
if test "`echo -n foo`" = foo; then
ECHON1="echo -n"
ECHON2=
elif test "`echo 'foo\c'`" = foo; then
ECHON1=echo
ECHON2='\c'
else
ECHON1=echo
ECHON2=
fi
#
if [ -z "$TMPDIR" ]; then
TMPDIR=/tmp
else
if [ "`echo $TMPDIR | grep '/$'`" != "" ]; then
TMPDIR="`echo $TMPDIR | sed -e 's,/$,,'`"
fi
fi
TEMP=`mktemp "$TMPDIR"/p.XXXXXX` || exit 1
BAD=`mktemp "$TMPDIR"/pbad.XXXXXX` || exit 1
REF=`mktemp "$TMPDIR"/pf.XXXXXX` || exit 1
# find a user name
if [ "$LOGNAME" = "" ]; then
if [ "$USER" != "" ]; then
LOGNAME="$USER"
else
LOGNAME="UNKNOWN"
fi
fi
FROM="$LOGNAME"
if [ -z "$REPLYTO" ]; then
REPLYTO="$LOGNAME"
fi
# Find out the name of the originator of this PR.
if [ -n "$NAME" ]; then
ORIGINATOR="$NAME"
elif [ -f $HOME/.fullname ]; then
ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
else
# Must use temp file due to incompatibilities in quoting behavior
# and to protect shell metacharacters in the expansion of $LOGNAME
TEMP2=`mktemp "$TMPDIR"/plogname.XXXXXX` || exit 1
$PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP2
ORIGINATOR="`cat $TEMP2`"
rm -f $TEMP2
fi
if [ -n "$ORGANIZATION" ]; then
if [ -f "$ORGANIZATION" ]; then
ORGANIZATION="`cat $ORGANIZATION`"
fi
else
if [ -n "$DEFAULT_ORGANIZATION" ]; then
ORGANIZATION="$DEFAULT_ORGANIZATION"
elif [ -f $HOME/.organization ]; then
ORGANIZATION="`cat $HOME/.organization`"
elif [ -f $HOME/.signature ]; then
ORGANIZATION="`cat $HOME/.signature`"
fi
fi
# If they don't have a preferred editor set, then use
if [ -z "$VISUAL" ]; then
if [ -z "$EDITOR" ]; then
EDIT=vi
else
EDIT="$EDITOR"
fi
else
EDIT="$VISUAL"
fi
# Find out some information.
SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
ARCH=`[ -f /bin/arch ] && /bin/arch`
MACHINE=`[ -f /bin/machine ] && /bin/machine`
COMMAND=`echo $0 | sed -e 's,.*/,,'`
USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [-s severity]
[-c address] [--request-id] [--version]"
REMOVE=
BATCH=
CC=
SEVERITY_C=
while [ $# -gt 0 ]; do
case "$1" in
-r) ;; # Ignore for backward compat.
-t | --to) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
shift ; GNATS_ADDR="$1"
EXPLICIT_GNATS_ADDR=true
;;
-f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
shift ; IN_FILE="$1"
if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
echo "$COMMAND: cannot read $IN_FILE"
exit 1
fi
;;
-b | --batch) BATCH=true ;;
-c | --cc) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
shift ; CC="$1"
;;
-s | --severity) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
shift ; SEVERITY_C="$1"
;;
-p | -P | --print) PRINT=true ;;
-L | --list) FORMAT=norm ;;
-l | -CL | --lisp) FORMAT=lisp ;;
--request-id) REQUEST_ID=true ;;
-h | --help) echo "$USAGE"; exit 0 ;;
-V | --version) echo "$VERSION"; exit 0 ;;
-*) echo "$USAGE" ; exit 1 ;;
*) if [ -z "$USER_GNATS_SITE" ]; then
if [ ! -r "$DATADIR/gnats/$1" ]; then
echo "$COMMAND: the GNATS site $1 does not have a categories list."
exit 1
else
# The site name is the alias they'll have to have created.
USER_GNATS_SITE=$1
fi
else
echo "$USAGE" ; exit 1
fi
;;
esac
shift
done
if [ -n "$USER_GNATS_SITE" ] && [ "$USER_GNATS_SITE" != "$GNATS_SITE" ]; then
GNATS_SITE=$USER_GNATS_SITE
GNATS_ADDR=$USER_GNATS_SITE-gnats
fi
if [ "$SUBMITTER" = "unknown" -a -z "$REQUEST_ID" -a -z "$IN_FILE" ]; then
cat << '__EOF__'
It seems that send-pr is not installed with your unique submitter-id.
You need to run
install-sid YOUR-SID
where YOUR-SID is the identification code you received with `send-pr'.
`send-pr' will automatically insert this value into the template field
`>Submitter-Id'. If you've downloaded `send-pr' from the Net, use `net'
for this value. If you do not know your id, run `send-pr --request-id' to
get one from your support site.
__EOF__
exit 1
fi
if [ -r "$DATADIR/gnats/$GNATS_SITE" ]; then
CATEGORIES=`grep -v '^#' $DATADIR/gnats/$GNATS_SITE | sort`
else
echo "$COMMAND: could not read $DATADIR/gnats/$GNATS_SITE for categories list."
exit 1
fi
if [ -z "$CATEGORIES" ]; then
echo "$COMMAND: the categories list for $GNATS_SITE was empty!"
exit 1
fi
case "$FORMAT" in
lisp) echo "$CATEGORIES" | \
awk 'BEGIN {printf "( "} {printf "(\"%s\") ",$0} END {printf ")\n"}'
exit 0
;;
norm) l=`echo "$CATEGORIES" | \
awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
END {print max + 1;}'`
c=`expr 70 / $l`
if [ $c -eq 0 ]; then c=1; fi
echo "$CATEGORIES" | \
awk 'BEGIN {print "Known categories:"; i = 0 }
{ printf ("%-'$l'.'$l's", $0); if ((++i % '$c') == 0) { print "" } }
END { print ""; }'
exit 0
;;
esac
ORIGINATOR_C=''
FIX_C='