2 # Submit a problem report to a GNATS site.
3 # Copyright (C) 1993 Free Software Foundation, Inc.
4 # Contributed by Brendan Kehoe (brendan@cygnus.com), based on a
5 # version written by Heinz G. Seidl (hgs@cygnus.com).
7 # This file is part of GNU GNATS.
9 # GNU GNATS is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 2, or (at your option)
14 # GNU GNATS is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with GNU GNATS; see the file COPYING. If not, write to
21 # the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
23 # The version of this send-pr.
26 # The submitter-id for your site.
29 # Where the GNATS directory lives, if at all.
30 [ -z "$GNATS_ROOT" ] &&
31 GNATS_ROOT=/usr/lib/gnats/gnats-db
33 # The default mail address for PR submissions.
34 GNATS_ADDR=bugs@xemacs.org
36 # Where the gnats category tree lives.
40 # If we've been moved around, try using GCC_EXEC_PREFIX.
41 [ ! -d $DATADIR/gnats -a -d "$GCC_EXEC_PREFIX" ] &&
42 DATADIR=${GCC_EXEC_PREFIX}../../../lib
45 # The default release for this host.
46 DEFAULT_RELEASE="gnats-3.101"
48 # The default organization.
49 DEFAULT_ORGANIZATION="XEmacs Users"
51 # The default site to look for.
54 # Newer config information?
55 [ -f ${GNATS_ROOT}/gnats-adm/config ] && . ${GNATS_ROOT}/gnats-adm/config
57 # What mailer to use. This must come after the config file, since it is
59 MAIL_AGENT="/usr/lib/sendmail -oi -t"
61 # How to read the passwd database.
62 PASSWD="cat /etc/passwd"
66 if [ $ECHON = bsd ] ; then
69 elif [ $ECHON = sysv ] ; then
79 if [ -z "$TMPDIR" ]; then
82 if [ "`echo $TMPDIR | grep '/$'`" != "" ]; then
83 TMPDIR="`echo $TMPDIR | sed -e 's,/$,,'`"
92 if [ "$LOGNAME" = "" ]; then
93 if [ "$USER" != "" ]; then
101 if [ -z "$REPLYTO" ]; then
105 # Find out the name of the originator of this PR.
106 if [ -n "$NAME" ]; then
108 elif [ -f $HOME/.fullname ]; then
109 ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
111 # Must use temp file due to incompatibilities in quoting behavior
112 # and to protect shell metacharacters in the expansion of $LOGNAME
113 $PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP
114 ORIGINATOR="`cat $TEMP`"
118 if [ -n "$ORGANIZATION" ]; then
119 if [ -f "$ORGANIZATION" ]; then
120 ORGANIZATION="`cat $ORGANIZATION`"
123 if [ -n "$DEFAULT_ORGANIZATION" ]; then
124 ORGANIZATION="$DEFAULT_ORGANIZATION"
125 elif [ -f $HOME/.organization ]; then
126 ORGANIZATION="`cat $HOME/.organization`"
127 elif [ -f $HOME/.signature ]; then
128 ORGANIZATION="`cat $HOME/.signature`"
132 # If they don't have a preferred editor set, then use
133 if [ -z "$VISUAL" ]; then
134 if [ -z "$EDITOR" ]; then
143 # Find out some information.
144 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
145 ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
146 ARCH=`[ -f /bin/arch ] && /bin/arch`
147 MACHINE=`[ -f /bin/machine ] && /bin/machine`
149 COMMAND=`echo $0 | sed -e 's,.*/,,'`
150 USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [-s severity]
151 [-c address] [--request-id] [--version]"
157 while [ $# -gt 0 ]; do
159 -r) ;; # Ignore for backward compat.
160 -t | --to) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
161 shift ; GNATS_ADDR="$1"
162 EXPLICIT_GNATS_ADDR=true
164 -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
166 if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
167 echo "$COMMAND: cannot read $IN_FILE"
171 -b | --batch) BATCH=true ;;
172 -c | --cc) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
175 -s | --severity) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
176 shift ; SEVERITY_C="$1"
178 -p | -P | --print) PRINT=true ;;
179 -L | --list) FORMAT=norm ;;
180 -l | -CL | --lisp) FORMAT=lisp ;;
181 --request-id) REQUEST_ID=true ;;
182 -h | --help) echo "$USAGE"; exit 0 ;;
183 -V | --version) echo "$VERSION"; exit 0 ;;
184 -*) echo "$USAGE" ; exit 1 ;;
185 *) if [ -z "$USER_GNATS_SITE" ]; then
186 if [ ! -r "$DATADIR/gnats/$1" ]; then
187 echo "$COMMAND: the GNATS site $1 does not have a categories list."
190 # The site name is the alias they'll have to have created.
194 echo "$USAGE" ; exit 1
201 if [ -n "$USER_GNATS_SITE" ] && [ "$USER_GNATS_SITE" != "$GNATS_SITE" ]; then
202 GNATS_SITE=$USER_GNATS_SITE
203 GNATS_ADDR=$USER_GNATS_SITE-gnats
206 if [ "$SUBMITTER" = "unknown" -a -z "$REQUEST_ID" -a -z "$IN_FILE" ]; then
208 It seems that send-pr is not installed with your unique submitter-id.
213 where YOUR-SID is the identification code you received with `send-pr'.
214 `send-pr' will automatically insert this value into the template field
215 `>Submitter-Id'. If you've downloaded `send-pr' from the Net, use `net'
216 for this value. If you do not know your id, run `send-pr --request-id' to
217 get one from your support site.
222 if [ -r "$DATADIR/gnats/$GNATS_SITE" ]; then
223 CATEGORIES=`grep -v '^#' $DATADIR/gnats/$GNATS_SITE | sort`
225 echo "$COMMAND: could not read $DATADIR/gnats/$GNATS_SITE for categories list."
229 if [ -z "$CATEGORIES" ]; then
230 echo "$COMMAND: the categories list for $GNATS_SITE was empty!"
235 lisp) echo "$CATEGORIES" | \
236 awk 'BEGIN {printf "( "} {printf "(\"%s\") ",$0} END {printf ")\n"}'
239 norm) l=`echo "$CATEGORIES" | \
240 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
241 END {print max + 1;}'`
243 if [ $c -eq 0 ]; then c=1; fi
244 echo "$CATEGORIES" | \
245 awk 'BEGIN {print "Known categories:"; i = 0 }
246 { printf ("%-'$l'.'$l's", $0); if ((++i % '$c') == 0) { print "" } }
252 ORIGINATOR_C='<name of the PR author (one line)>'
253 ORGANIZATION_C='<organization of PR author (multiple lines)>'
254 CONFIDENTIAL_C='<[ yes | no ] (one line)>'
255 SYNOPSIS_C='<synopsis of the problem (one line)>'
256 if [ -z "$SEVERITY_C" ]; then
257 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
259 PRIORITY_C='<[ low | medium | high ] (one line)>'
260 CATEGORY_C='<name of the product (one line)>'
261 CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
262 RELEASE_C='<release number or tag (one line)>'
263 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
264 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
265 HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
266 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
268 # Catch some signals. ($xs kludge needed by Sun /bin/sh)
270 trap 'rm -f $REF $TEMP; exit $xs' 0
271 trap 'echo "$COMMAND: Aborting ..."; rm -f $REF $TEMP; xs=1; exit' 1 2 3 13 15
273 # If they told us to use a specific file, then do so.
274 if [ -n "$IN_FILE" ]; then
275 if [ "$IN_FILE" = "-" ]; then
276 # The PR is coming from the standard input.
277 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
278 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" > $TEMP
283 # Use the file they named.
284 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
285 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" $IN_FILE > $TEMP
292 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
293 # If their PR_FORM points to a bogus entry, then bail.
294 if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
295 echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
297 PRINT_INTERN=bad_prform
301 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
303 ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
305 for file in $TEMP $REF ; do
306 cat > $file << '__EOF__'
307 SEND-PR: -*- send-pr -*-
308 SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
309 SEND-PR: will all comments (text enclosed in `<' and `>').
311 SEND-PR: Please consult the send-pr man page `send-pr(1)' or the Texinfo
312 SEND-PR: manual if you are not sure how to fill out a problem report.
314 SEND-PR: Choose from the following categories:
318 # Format the categories so they fit onto lines.
319 l=`echo "$CATEGORIES" | \
320 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
321 END {print max + 1;}'`
323 if [ $c -eq 0 ]; then c=1; fi
324 echo "$CATEGORIES" | \
325 awk 'BEGIN {printf "SEND-PR: "; i = 0 }
326 { printf ("%-'$l'.'$l's", $0);
327 if ((++i % '$c') == 0) { printf "\nSEND-PR: " } }
328 END { printf "\nSEND-PR:\n"; }' >> $file
330 cat >> $file << __EOF__
336 X-send-pr-version: $VERSION
339 >Submitter-Id: $SUBMITTER
340 >Originator: $ORIGINATOR
342 ${ORGANIZATION- $ORGANIZATION_C}
343 >Confidential: $CONFIDENTIAL_C
344 >Synopsis: $SYNOPSIS_C
345 >Severity: $SEVERITY_C
346 >Priority: $PRIORITY_C
347 >Category: $CATEGORY_C
349 >Release: ${DEFAULT_RELEASE-$RELEASE_C}
352 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
353 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
354 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
365 if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
371 if [ -z "$REQUEST_ID" ]; then
374 ed -s $TEMP << '__EOF__'
375 /^Subject/s/^Subject:.*/Subject: request for a customer id/
376 /^>Category/s/^>Category:.*/>Category: send-pr/
382 if cmp -s $REF $TEMP ; then
383 echo "$COMMAND: problem report not filled out, therefore not sent"
389 # Check the enumeration fields
391 # This is a "sed-subroutine" with one keyword parameter
392 # (with workaround for Sun sed bug)
405 while [ -z "$REQUEST_ID" ]; do
410 PATTERN=">Confidential:"
411 CONFIDENTIAL=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
412 case "$CONFIDENTIAL" in
413 ""|yes|no) CNT=`expr $CNT + 1` ;;
414 *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
420 SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
422 ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
423 *) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
429 PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
431 ""|low|medium|high) CNT=`expr $CNT + 1` ;;
432 *) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
438 CATEGORY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
442 if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
444 if [ -n "$FOUND" ]; then
447 if [ -z "$CATEGORY" ]; then
448 echo "$COMMAND: you must include a Category: field in your report."
450 echo "$COMMAND: \`$CATEGORY' is not a known category."
457 CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
459 ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
460 *) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
463 [ $CNT -lt 5 -a -z "$BATCH" ] &&
464 echo "Errors were found with the problem report."
467 if [ -z "$BATCH" ]; then
468 $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
471 if [ $CNT -eq 5 ]; then
479 if [ -z "$BATCH" ]; then
480 echo "$COMMAND: the problem report remains in $BAD and is not sent."
483 echo "$COMMAND: the problem report is not sent."
498 # Remove comments and send the problem report
499 # (we have to use patterns, where the comment contains regex chars)
501 # /^>Originator:/s;$ORIGINATOR;;
504 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
505 /^>Confidential:/s;<.*>;;
506 /^>Synopsis:/s;$SYNOPSIS_C;;
507 /^>Severity:/s;<.*>;;
508 /^>Priority:/s;<.*>;;
509 /^>Category:/s;$CATEGORY_C;;
511 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
512 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
513 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
514 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
515 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
518 if $MAIL_AGENT < $REF; then
519 echo "$COMMAND: problem report sent"
522 echo "$COMMAND: mysterious mail failure."
523 if [ -z "$BATCH" ]; then
524 echo "$COMMAND: the problem report remains in $BAD and is not sent."
527 echo "$COMMAND: the problem report is not sent."