2 # Submit a problem report to a GNATS site.
3 # Copyright (C) 1993, 2000 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 # The default mail address for PR submissions.
30 GNATS_ADDR=gcc-gnats@gcc.gnu.org
32 # The default release for this host.
33 DEFAULT_RELEASE="@gcc_version@"
35 # The default organization.
38 # What mailer to use. This must come after the config file, since it is
41 if [ -f /usr/sbin/sendmail ]; then
42 MAIL_AGENT="/usr/sbin/sendmail -oi -t"
44 MAIL_AGENT="/usr/lib/sendmail -oi -t"
46 MAILER=`echo $MAIL_AGENT | sed -e 's, .*,,'`
47 if [ ! -f "$MAILER" ] ; then
48 echo "$COMMAND: Cannot file mail program \"$MAILER\"."
49 echo "$COMMAND: Please fix the MAIL_AGENT entry in the $COMMAND file."
54 # How to read the passwd database.
55 PASSWD="cat /etc/passwd"
59 if [ $ECHON = bsd ] ; then
62 elif [ $ECHON = sysv ] ; then
72 if [ -z "$TMPDIR" ]; then
75 if [ "`echo $TMPDIR | grep '/$'`" != "" ]; then
76 TMPDIR="`echo $TMPDIR | sed -e 's,/$,,'`"
85 if [ "$LOGNAME" = "" ]; then
86 if [ "$USER" != "" ]; then
94 REPLY_TO="${REPLY_TO:-${REPLYTO:-$LOGNAME}}"
96 # Find out the name of the originator of this PR.
97 if [ -n "$NAME" ]; then
99 elif [ -f $HOME/.fullname ]; then
100 ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
102 # Must use temp file due to incompatibilities in quoting behavior
103 # and to protect shell metacharacters in the expansion of $LOGNAME
104 $PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP
105 ORIGINATOR="`cat $TEMP`"
109 if [ -n "$ORGANIZATION" ]; then
110 if [ -f "$ORGANIZATION" ]; then
111 ORGANIZATION="`cat $ORGANIZATION`"
114 if [ -n "$DEFAULT_ORGANIZATION" ]; then
115 ORGANIZATION="$DEFAULT_ORGANIZATION"
116 elif [ -f $HOME/.organization ]; then
117 ORGANIZATION="`cat $HOME/.organization`"
121 # If they don't have a preferred editor set, then use
122 if [ -z "$VISUAL" ]; then
123 if [ -z "$EDITOR" ]; then
132 # Find out some information.
133 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
134 ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
135 ARCH=`[ -f /bin/arch ] && /bin/arch`
136 MACHINE=`[ -f /bin/machine ] && /bin/machine`
138 COMMAND=`echo $0 | sed -e 's,.*/,,'`
139 USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [-s severity]
140 [-c address] [--request-id] [--version]"
146 while [ $# -gt 0 ]; do
148 -r) ;; # Ignore for backward compat.
149 -t | --to) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
150 shift ; GNATS_ADDR="$1"
151 EXPLICIT_GNATS_ADDR=true
153 -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
155 if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
156 echo "$COMMAND: cannot read $IN_FILE"
160 -b | --batch) BATCH=true ;;
161 -c | --cc) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
164 -s | --severity) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
165 shift ; SEVERITY_C="$1"
167 -p | -P | --print) PRINT=true ;;
168 -L | --list) FORMAT=norm ;;
169 -l | -CL | --lisp) FORMAT=lisp ;;
170 --request-id) REQUEST_ID=true ;;
171 -h | --help) echo "$USAGE"; exit 0 ;;
172 -V | --version) echo "$VERSION"; exit 0 ;;
173 -*) echo "$USAGE" ; exit 1 ;;
174 *) echo "$USAGE" ; exit 1
179 # spam does not need to be listed here
180 CATEGORIES="c++ c debug fortran gc host java libf2c libgcc libobjc libstdc++ middle-end objc optimization other profiling target web"
183 lisp) echo "$CATEGORIES" | \
184 awk 'BEGIN {printf "( "} {printf "(\"%s\") ",$0} END {printf ")\n"}'
187 norm) l=`echo "$CATEGORIES" | \
188 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
189 END {print max + 1;}'`
191 if [ $c -eq 0 ]; then c=1; fi
192 echo "$CATEGORIES" | \
193 awk 'BEGIN {print "Known categories:"; i = 0 }
194 { printf ("%-'$l'.'$l's", $0); if ((++i % '$c') == 0) { print "" } }
200 ORIGINATOR_C='<name of the PR author (one line)>'
201 ORGANIZATION_C='<organization of PR author (multiple lines)>'
202 CONFIDENTIAL_C='<[ yes | no ] (one line)>'
203 SYNOPSIS_C='<synopsis of the problem (one line)>'
204 if [ -z "$SEVERITY_C" ]; then
205 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
207 PRIORITY_C='<[ low | medium | high ] (one line)>'
208 CATEGORY_C='<choose from the list of categories above (one line)>'
209 CLASS_C='<[ doc-bug | accepts-illegal | rejects-legal | wrong-code | ice-on-legal-code| ice-on-illegal-code | pessimizes-code | sw-bug | change-request | support ] (one line)>'
210 RELEASE_C='<release number or tag (one line)>'
211 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
212 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
213 HOW_TO_REPEAT_C='<When reporting a compiler error, preprocessor output must be included>'
214 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
216 # Catch some signals. ($xs kludge needed by Sun /bin/sh)
218 trap 'rm -f $REF $TEMP; exit $xs' 0
219 trap 'echo "$COMMAND: Aborting ..."; rm -f $REF $TEMP; xs=1; exit' 1 3 13 15
221 # If they told us to use a specific file, then do so.
222 if [ -n "$IN_FILE" ]; then
223 if [ "$IN_FILE" = "-" ]; then
224 # The PR is coming from the standard input.
225 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
226 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" > $TEMP
231 # Use the file they named.
232 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
233 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" $IN_FILE > $TEMP
240 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
241 # If their PR_FORM points to a bogus entry, then bail.
242 if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
243 echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
245 PRINT_INTERN=bad_prform
249 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
251 ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
253 for file in $TEMP $REF ; do
254 cat > $file << '__EOF__'
255 SEND-PR: -*- send-pr -*-
256 SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
257 SEND-PR: will all comments (text enclosed in `<' and `>').
259 SEND-PR: Please consult the send-pr man page `send-pr(1)' or the Texinfo
260 SEND-PR: manual if you are not sure how to fill out a problem report.
261 SEND-PR: Note that the Synopsis field is mandatory. The Subject (for
262 SEND-PR: the mail) will be made the same as Synopsis unless explicitly
265 SEND-PR: Choose from the following categories:
269 # Format the categories so they fit onto lines.
270 l=`echo "$CATEGORIES" | \
271 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
272 END {print max + 1;}'`
274 if [ $c -eq 0 ]; then c=1; fi
275 echo "$CATEGORIES" | \
276 awk 'BEGIN {printf "SEND-PR: "; i = 0 }
277 { printf ("%-'$l'.'$l's", $0);
278 if ((++i % '$c') == 0) { printf "\nSEND-PR: " } }
279 END { printf "\nSEND-PR:\n"; }' >> $file
281 cat >> $file << __EOF__
287 X-send-pr-version: $VERSION
291 >Submitter-Id: $SUBMITTER
292 >Originator: $ORIGINATOR
293 >Organization: ${ORGANIZATION-$ORGANIZATION_C}
294 >Confidential: $CONFIDENTIAL_C
295 >Synopsis: $SYNOPSIS_C
296 >Severity: $SEVERITY_C
297 >Priority: $PRIORITY_C
298 >Category: $CATEGORY_C
300 >Release: ${DEFAULT_RELEASE-$RELEASE_C}
302 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
303 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
304 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
319 if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
325 if [ -z "$REQUEST_ID" ]; then
328 ed -s $TEMP << '__EOF__'
329 /^Subject/s/^Subject:.*/Subject: request for a customer id/
330 /^>Category/s/^>Category:.*/>Category: send-pr/
336 if cmp -s $REF $TEMP ; then
337 echo "$COMMAND: problem report not filled out, therefore not sent"
343 # Check the enumeration fields
345 # This is a "sed-subroutine" with one keyword parameter
346 # (with workaround for Sun sed bug)
359 while [ -z "$REQUEST_ID" ]; do
364 PATTERN=">Confidential:"
365 CONFIDENTIAL=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
366 case "$CONFIDENTIAL" in
367 ""|yes|no) CNT=`expr $CNT + 1` ;;
368 *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
374 SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
376 ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
377 *) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
383 PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
385 ""|low|medium|high) CNT=`expr $CNT + 1` ;;
386 *) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
392 CATEGORY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
396 if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
398 if [ -n "$FOUND" ]; then
401 if [ -z "$CATEGORY" ]; then
402 echo "$COMMAND: you must include a Category: field in your report."
404 echo "$COMMAND: \`$CATEGORY' is not a known category."
411 CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
413 ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
414 *) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
417 # 6) Check that synopsis is not empty
419 if grep "^>Synopsis:[ ]*${SYNOPSIS_C}\$" $TEMP > /dev/null
421 echo "$COMMAND: Synopsis must not be empty."
426 [ $CNT -lt 6 -a -z "$BATCH" ] &&
427 echo "Errors were found with the problem report."
430 if [ -z "$BATCH" ]; then
431 $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
434 if [ $CNT -eq 6 ]; then
442 if [ -z "$BATCH" ]; then
443 echo "$COMMAND: the problem report remains in $BAD and is not sent."
446 echo "$COMMAND: the problem report is not sent."
462 # Make sure the mail has got a Subject. If not, use the same as
466 if grep '^Subject:[ ]*$' $TEMP > /dev/null
468 SYNOPSIS=`grep '^>Synopsis:' $TEMP | sed -e 's/^>Synopsis:[ ]*//'`
469 ed -s $TEMP << __EOF__
470 /^Subject:/s/:.*\$/: $SYNOPSIS/
477 # Remove comments and send the problem report
478 # (we have to use patterns, where the comment contains regex chars)
480 # /^>Originator:/s;$ORIGINATOR;;
483 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
484 /^>Confidential:/s;<.*>;;
485 /^>Synopsis:/s;$SYNOPSIS_C;;
486 /^>Severity:/s;<.*>;;
487 /^>Priority:/s;<.*>;;
488 /^>Category:/s;$CATEGORY_C;;
490 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
491 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
492 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
493 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
494 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
497 if $MAIL_AGENT < $REF; then
498 echo "$COMMAND: problem report sent"
501 echo "$COMMAND: mysterious mail failure."
502 if [ -z "$BATCH" ]; then
503 echo "$COMMAND: the problem report remains in $BAD and is not sent."
506 echo "$COMMAND: the problem report is not sent."