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@ide.com).
7 # This file is part of GNU GNATS.
8 # Modified by Berliner for CVS.
10 # GNU GNATS is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2, or (at your option)
15 # GNU GNATS is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # The version of this send-pr.
23 # The submitter-id for your site.
26 ## # Where the GNATS directory lives, if at all.
27 ## [ -z "$GNATS_ROOT" ] &&
28 ## GNATS_ROOT=/usr/local/lib/gnats/gnats-db
30 # The default mail address for PR submissions.
31 GNATS_ADDR=@PACKAGE_BUGREPORT@
33 ## # Where the gnats category tree lives.
34 ## DATADIR=/usr/local/lib
36 ## # If we've been moved around, try using GCC_EXEC_PREFIX.
37 ## [ ! -d $DATADIR/gnats -a -d "$GCC_EXEC_PREFIX" ] && DATADIR=${GCC_EXEC_PREFIX}..
39 # The default release for this host.
40 DEFAULT_RELEASE="@VERSION@"
42 # The default organization.
43 DEFAULT_ORGANIZATION="net"
45 ## # The default site to look for.
48 ## # Newer config information?
49 ## [ -f ${GNATS_ROOT}/gnats-adm/config ] && . ${GNATS_ROOT}/gnats-adm/config
51 # Hack mktemp on systems that don't have it.
55 # What mailer to use. This must come after the config file, since it is
58 MAIL_AGENT="$SENDMAIL -oi -t"
59 MAILER=`echo $MAIL_AGENT | sed -e 's, .*,,'`
60 if [ ! -f "$MAILER" ] ; then
61 echo "$COMMAND: Cannot find mail program \"$MAILER\"."
62 echo "$COMMAND: Please fix the MAIL_AGENT entry in the $COMMAND file."
66 if test "`echo -n foo`" = foo ; then
68 elif test "`echo 'foo\c'`" = foo ; then
74 if [ $ECHON = bsd ] ; then
77 elif [ $ECHON = sysv ] ; then
87 [ -z "$TMPDIR" ] && TMPDIR=/tmp
89 TEMP="`$MKTEMP $TMPDIR/p.XXXXXX`"
90 BAD="`$MKTEMP $TMPDIR/pbad.XXXXXX`"
91 REF="`$MKTEMP $TMPDIR/pf.XXXXXX`"
93 if [ -z "$LOGNAME" -a -n "$USER" ]; then
100 # Find out the name of the originator of this PR.
101 if [ -n "$NAME" ]; then
103 elif [ -f $HOME/.fullname ]; then
104 ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
105 elif [ -f /bin/domainname ]; then
106 if [ "`/bin/domainname`" != "" -a -f /usr/bin/ypcat ]; then
107 # Must use temp file due to incompatibilities in quoting behavior
108 # and to protect shell metacharacters in the expansion of $LOGNAME
109 /usr/bin/ypcat passwd 2>/dev/null | cat - /etc/passwd | grep "^$LOGNAME:" |
110 cut -f5 -d':' | sed -e 's/,.*//' > $TEMP
111 ORIGINATOR="`cat $TEMP`"
115 if [ "$ORIGINATOR" = "" ]; then
116 grep "^$LOGNAME:" /etc/passwd | cut -f5 -d':' | sed -e 's/,.*//' > $TEMP
117 ORIGINATOR="`cat $TEMP`"
120 if [ -n "$ORGANIZATION" ]; then
121 if [ -f "$ORGANIZATION" ]; then
122 ORGANIZATION="`cat $ORGANIZATION`"
125 if [ -n "$DEFAULT_ORGANIZATION" ]; then
126 ORGANIZATION="$DEFAULT_ORGANIZATION"
127 elif [ -f $HOME/.organization ]; then
128 ORGANIZATION="`cat $HOME/.organization`"
129 elif [ -f $HOME/.signature ]; then
130 ORGANIZATION="`cat $HOME/.signature`"
134 # If they don't have a preferred editor set, then use
135 if [ -z "$VISUAL" ]; then
136 if [ -z "$EDITOR" ]; then
145 # Find out some information.
146 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
147 ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
148 ARCH=`[ -f /bin/arch ] && /bin/arch`
149 MACHINE=`[ -f /bin/machine ] && /bin/machine`
151 COMMAND=`echo $0 | sed -e 's,.*/,,'`
152 ## USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [--request-id]
153 USAGE="Usage: $COMMAND [-PVL]
158 while [ $# -gt 0 ]; do
160 -r) ;; # Ignore for backward compat.
161 ## -t | --to) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
162 ## shift ; GNATS_ADDR="$1"
163 ## EXPLICIT_GNATS_ADDR=true
165 ## -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
166 ## shift ; IN_FILE="$1"
167 ## if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
168 ## echo "$COMMAND: cannot read $IN_FILE"
172 -b | --batch) BATCH=true ;;
173 -p | -P | --print) PRINT=true ;;
174 -L | --list) FORMAT=norm ;;
175 -l | -CL | --lisp) FORMAT=lisp ;;
176 ## --request-id) REQUEST_ID=true ;;
177 -h | --help) echo "$USAGE"; exit 0 ;;
178 -V | --version) echo "$VERSION"; exit 0 ;;
179 -*) echo "$USAGE" ; exit 1 ;;
180 *) echo "$USAGE" ; exit 1
181 ## if [ -z "$USER_GNATS_SITE" ]; then
182 ## if [ ! -r "$DATADIR/gnats/$1" ]; then
183 ## echo "$COMMAND: the GNATS site $1 does not have a categories list."
186 ## # The site name is the alias they'll have to have created.
187 ## USER_GNATS_SITE=$1
190 ## echo "$USAGE" ; exit 1
197 if [ -n "$USER_GNATS_SITE" ]; then
198 GNATS_SITE=$USER_GNATS_SITE
199 GNATS_ADDR=$USER_GNATS_SITE-gnats
202 if [ "$SUBMITTER" = "unknown" -a -z "$REQUEST_ID" -a -z "$IN_FILE" ]; then
204 It seems that send-pr is not installed with your unique submitter-id.
209 where YOUR-SID is the identification code you received with `send-pr'.
210 `send-pr' will automatically insert this value into the template field
211 `>Submitter-Id'. If you've downloaded `send-pr' from the Net, use `net'
212 for this value. If you do not know your id, run `send-pr --request-id' to
213 get one from your support site.
218 ## if [ -r "$DATADIR/gnats/$GNATS_SITE" ]; then
219 ## CATEGORIES=`grep -v '^#' $DATADIR/gnats/$GNATS_SITE | sort`
221 ## echo "$COMMAND: could not read $DATADIR/gnats/$GNATS_SITE for categories list."
224 CATEGORIES="contrib cvs doc pcl-cvs portability"
226 if [ -z "$CATEGORIES" ]; then
227 echo "$COMMAND: the categories list for $GNATS_SITE was empty!"
232 lisp) echo "$CATEGORIES" | \
233 awk 'BEGIN {printf "( "}
234 {printf "(\"%s\") ",$0}
238 norm) l=`echo "$CATEGORIES" | \
239 awk 'BEGIN {max = 0; }
240 { 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 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
257 PRIORITY_C='<[ low | medium | high ] (one line)>'
258 CATEGORY_C='<name of the product (one line)>'
259 CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
260 RELEASE_C='<release number or tag (one line)>'
261 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
262 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
263 HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
264 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
266 # Catch some signals. ($xs kludge needed by Sun /bin/sh)
268 trap 'rm -f $REF $TEMP; exit $xs' 0
269 trap 'echo "$COMMAND: Aborting ..."; rm -f $REF $TEMP; xs=1; exit' 1 2 3 13 15
271 # If they told us to use a specific file, then do so.
272 if [ -n "$IN_FILE" ]; then
273 if [ "$IN_FILE" = "-" ]; then
274 # The PR is coming from the standard input.
275 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
276 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" > $TEMP
281 # Use the file they named.
282 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
283 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" $IN_FILE > $TEMP
290 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
291 # If their PR_FORM points to a bogus entry, then bail.
292 if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
293 echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
295 PRINT_INTERN=bad_prform
299 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
301 ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
303 for file in $TEMP $REF ; do
304 cat > $file << '__EOF__'
305 SEND-PR: -*- send-pr -*-
306 SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
307 SEND-PR: will all comments (text enclosed in `<' and `>').
309 SEND-PR: Choose from the following categories:
313 # Format the categories so they fit onto lines.
314 l=`echo "$CATEGORIES" | \
315 awk 'BEGIN {max = 0; }
316 { if (length($0) > max) { max = length($0); } }
317 END {print max + 1;}'`
319 if [ $c -eq 0 ]; then c=1; fi
320 echo "$CATEGORIES" | \
321 awk 'BEGIN {printf "SEND-PR: "; i = 0 }
322 { printf ("%-'$l'.'$l's", $0);
323 if ((++i % '$c') == 0) { printf "\nSEND-PR: " } }
324 END { printf "\nSEND-PR:\n"; }' >> $file
326 cat >> $file << __EOF__
331 X-send-pr-version: $VERSION
334 >Submitter-Id: $SUBMITTER
335 >Originator: $ORIGINATOR
337 ${ORGANIZATION-$ORGANIZATION_C}
338 >Confidential: $CONFIDENTIAL_C
339 >Synopsis: $SYNOPSIS_C
340 >Severity: $SEVERITY_C
341 >Priority: $PRIORITY_C
342 >Category: $CATEGORY_C
344 >Release: ${DEFAULT_RELEASE-$RELEASE_C}
347 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
348 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
349 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
360 if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
366 if [ -z "$REQUEST_ID" ]; then
369 ed -s $TEMP << '__EOF__'
370 /^Subject/s/^Subject:.*/Subject: request for a customer id/
371 /^>Category/s/^>Category:.*/>Category: send-pr/
377 if cmp -s $REF $TEMP ; then
378 echo "$COMMAND: problem report not filled out, therefore not sent"
384 # Check the enumeration fields
386 # This is a "sed-subroutine" with one keyword parameter
387 # (with workaround for Sun sed bug)
400 while [ -z "$REQUEST_ID" ]; do
405 PATTERN=">Confidential:"
406 CONFIDENTIAL=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
407 case "$CONFIDENTIAL" in
408 ""|yes|no) CNT=`expr $CNT + 1` ;;
409 *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
415 SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
417 ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
418 *) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
424 PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
426 ""|low|medium|high) CNT=`expr $CNT + 1` ;;
427 *) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
433 CATEGORY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
437 if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
439 if [ -n "$FOUND" ]; then
442 if [ -z "$CATEGORY" ]; then
443 echo "$COMMAND: you must include a Category: field in your report."
445 echo "$COMMAND: \`$CATEGORY' is not a known category."
452 CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
454 ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
455 *) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
458 [ $CNT -lt 5 -a -z "$BATCH" ] &&
459 echo "Errors were found with the problem report."
462 if [ -z "$BATCH" ]; then
463 $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
466 if [ $CNT -eq 5 ]; then
474 if [ -z "$BATCH" ]; then
475 echo "$COMMAND: the problem report remains in $BAD and is not sent."
478 echo "$COMMAND: the problem report is not sent."
493 # Remove comments and send the problem report
494 # (we have to use patterns, where the comment contains regex chars)
496 # /^>Originator:/s;$ORIGINATOR;;
499 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
500 /^>Confidential:/s;<.*>;;
501 /^>Synopsis:/s;$SYNOPSIS_C;;
502 /^>Severity:/s;<.*>;;
503 /^>Priority:/s;<.*>;;
504 /^>Category:/s;$CATEGORY_C;;
506 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
507 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
508 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
509 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
510 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
513 if $MAIL_AGENT < $REF; then
514 echo "$COMMAND: problem report sent"
517 echo "$COMMAND: mysterious mail failure."
518 if [ -z "$BATCH" ]; then
519 echo "$COMMAND: the problem report remains in $BAD and is not sent."
522 echo "$COMMAND: the problem report is not sent."