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
=xGNATS_ROOTx
33 # The default mail address for PR submissions.
34 GNATS_ADDR
=xGNATS_ADDRx
36 # Where the gnats category tree lives.
39 # If we've been moved around, try using GCC_EXEC_PREFIX.
40 [ ! -d $DATADIR/gnats
-a -d "$GCC_EXEC_PREFIX" ] &&
41 DATADIR
=${GCC_EXEC_PREFIX}..
/..
/..
/lib
43 # The default release for this host.
44 DEFAULT_RELEASE
="xDEFAULT_RELEASEx"
46 # The default organization.
47 DEFAULT_ORGANIZATION
="xDEFAULT_ORGANIZATIONx"
49 # The default site to look for.
50 GNATS_SITE
=xGNATS_SITEx
52 # Newer config information?
53 [ -f ${GNATS_ROOT}/gnats-adm
/config
] && .
${GNATS_ROOT}/gnats-adm
/config
55 # What mailer to use. This must come after the config file, since it is
57 MAIL_AGENT
="xMAIL_AGENTx"
59 # How to read the passwd database.
64 if [ $ECHON = bsd
] ; then
67 elif [ $ECHON = sysv
] ; then
77 if [ -z "$TMPDIR" ]; then
80 if [ "`echo $TMPDIR | grep '/$'`" != "" ]; then
81 TMPDIR
="`echo $TMPDIR | sed -e 's,/$,,'`"
85 TEMP
=`mktemp -t p` ||
exit 1
86 BAD
=`mktemp -t pbad` ||
exit 1
87 REF
=`mktemp -t pf` ||
exit 1
90 if [ "$LOGNAME" = "" ]; then
91 if [ "$USER" != "" ]; then
99 if [ -z "$REPLYTO" ]; then
103 # Find out the name of the originator of this PR.
104 if [ -n "$NAME" ]; then
106 elif [ -f $HOME/.fullname
]; then
107 ORIGINATOR
="`sed -e '1q' $HOME/.fullname`"
109 ORIGINATOR
=`$PASSWD | sed -e /"^${LOGNAME}:"/'{s/^[^:]*:[^:]*:[^:]*:[^:]*:\([^,:;]*\).*$/\1/' -e q -e } -e d`
110 case "$ORIGINATOR" in
112 AMP
=`echo $LOGNAME | tr '[a-z]' '[A-Z]'`
113 AMP
=`echo $AMP $LOGNAME | sed 's/^\(.\)[^ ]* ./\1/'`
114 ORIGINATOR
=`echo "$ORIGINATOR" | sed "s/&/$AMP/"`
119 if [ -n "$ORGANIZATION" ]; then
120 if [ -f "$ORGANIZATION" ]; then
121 ORGANIZATION
="`cat $ORGANIZATION`"
124 if [ -n "$DEFAULT_ORGANIZATION" ]; then
125 ORGANIZATION
="$DEFAULT_ORGANIZATION"
126 elif [ -f $HOME/.organization
]; then
127 ORGANIZATION
="`cat $HOME/.organization`"
128 elif [ -f $HOME/.signature
]; then
129 ORGANIZATION
="`cat $HOME/.signature`"
133 # If they don't have a preferred editor set, then use
134 if [ -z "$VISUAL" ]; then
135 if [ -z "$EDITOR" ]; then
144 # Find out some information.
145 if [ -f /bin
/uname
]; then
147 elif [ -f /usr
/bin
/uname
]; then
148 UNAME
="/usr/bin/uname"
154 if [ -z "$ARCH" -a -f /bin
/arch
]; then
158 if [ -z "$ARCH" -a -f /bin
/machine
]; then
162 COMMAND
=`echo $0 | sed -e 's,.*/,,'`
163 USAGE
="Usage: $COMMAND [-PVL] [-t address] [-f filename] [--request-id]
168 while [ $# -gt 0 ]; do
170 -r) ;; # Ignore for backward compat.
171 -t |
--to) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
172 shift ; GNATS_ADDR
="$1"
173 EXPLICIT_GNATS_ADDR
=true
175 -f |
--file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
177 if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
178 echo "$COMMAND: cannot read $IN_FILE"
182 -b |
--batch) BATCH
=true
;;
183 -p |
-P |
--print) PRINT
=true
;;
184 -L |
--list) FORMAT
=norm
;;
185 -l |
-CL |
--lisp) FORMAT
=lisp
;;
186 --request-id) REQUEST_ID
=true
;;
187 -h |
--help) echo "$USAGE"; exit 0 ;;
188 -V |
--version) echo "$VERSION"; exit 0 ;;
189 -*) echo "$USAGE" ; exit 1 ;;
190 *) if [ -z "$USER_GNATS_SITE" ]; then
191 if [ ! -r "$DATADIR/gnats/$1" ]; then
192 echo "$COMMAND: the GNATS site $1 does not have a categories list."
195 # The site name is the alias they'll have to have created.
199 echo "$USAGE" ; exit 1
206 if [ -n "$USER_GNATS_SITE" ] && [ "$USER_GNATS_SITE" != "$GNATS_SITE" ]; then
207 GNATS_SITE
=$USER_GNATS_SITE
208 GNATS_ADDR
=$USER_GNATS_SITE-gnats
211 if [ "$SUBMITTER" = "unknown" -a -z "$REQUEST_ID" -a -z "$IN_FILE" ]; then
213 It seems that send-pr is not installed with your unique submitter-id.
218 where YOUR-SID is the identification code you received with
`send-pr'.
219 `send-pr
' will automatically insert this value into the template field
220 `>Submitter-Id'. If you
've downloaded `send-pr' from the Net
, use
`net'
221 for this value. If you do not know your id, run `send-pr
--request-id' to
222 get one from your support site.
227 if [ -r "$DATADIR/gnats/$GNATS_SITE" ]; then
228 CATEGORIES=`grep -v '^
#' $DATADIR/gnats/$GNATS_SITE | sort`
230 echo "$COMMAND: could not read $DATADIR/gnats/$GNATS_SITE for categories list."
234 if [ -z "$CATEGORIES" ]; then
235 echo "$COMMAND: the categories list for $GNATS_SITE was empty!"
240 lisp
) echo "$CATEGORIES" | \
241 awk 'BEGIN {printf "( "} {printf "(\"%s\") ",$0} END {printf ")\n"}'
244 norm
) l
=`echo "$CATEGORIES" | \
245 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
246 END {print max + 1;}'`
248 if [ $c -eq 0 ]; then c
=1; fi
249 echo "$CATEGORIES" | \
250 awk 'BEGIN {print "Known categories:"; i = 0 }
251 { printf ("%-'$l'.'$l's", $0); if ((++i % '$c') == 0) { print "" } }
257 ORIGINATOR_C
='<name of the PR author (one line)>'
258 ORGANIZATION_C
='<organization of PR author (multiple lines)>'
259 CONFIDENTIAL_C
='<[ no | yes ] (one line)>'
260 SYNOPSIS_C
='<synopsis of the problem (one line)>'
261 SEVERITY_C
='<[ non-critical | serious | critical ] (one line)>'
262 PRIORITY_C
='<[ low | medium | high ] (one line)>'
263 CATEGORY_C
='<problem report category - see top for list (one line)>'
264 CLASS_C
='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
265 RELEASE_C_1
='<Please check that the above is correct for the bug being reported,>'
266 RELEASE_C_2
='<and append source date of snapshot, if applicable (one line).>'
267 ENVIRONMENT_C_1
='<The following information is extracted from your kernel. Please>'
268 ENVIRONMENT_C_2
='<append output of "ldd", "ident" where relevant (multiple lines).>'
269 DESCRIPTION_C
='<precise description of the problem (multiple lines)>'
270 HOW_TO_REPEAT_C
='<code/input/activities to reproduce the problem (multiple lines)>'
271 FIX_C
='<how to correct or work around the problem, if known (multiple lines)>'
273 # Catch some signals. ($xs kludge needed by Sun /bin/sh)
275 TRAP_EXIT_ACTION
='rm -f $REF $TEMP; exit $xs'
276 TRAP_IGNORE_ACTION
=''
277 TRAP_ABORT_ACTION
='echo "$COMMAND: Aborting ..."; rm -f $REF $TEMP; xs=1; exit'
278 TRAP_ABORTSAVE_ACTION
='
279 echo "$COMMAND: Aborting ...";
280 if cmp -s $REF $TEMP ; then
283 echo "$COMMAND: the problem report remains in $BAD and is not sent."
286 rm -f $TEMP; xs=1; exit'
287 trap "$TRAP_EXIT_ACTION" 0
288 trap "$TRAP_ABORT_ACTION" 1 2 3 13 15
290 # If they told us to use a specific file, then do so.
291 if [ -n "$IN_FILE" ]; then
292 if [ "$IN_FILE" = "-" ]; then
293 # The PR is coming from the standard input.
294 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
295 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" > $TEMP
300 # Use the file they named.
301 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
302 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" $IN_FILE > $TEMP
309 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
310 # If their PR_FORM points to a bogus entry, then bail.
311 if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
312 echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
314 PRINT_INTERN
=bad_prform
318 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
320 ( echo "$COMMAND: could not copy $PR_FORM" ; xs
=1; exit )
322 for file in $TEMP $REF ; do
323 cat > $file << '__EOF__'
324 SEND-PR
: -*- send-pr
-*-
325 SEND-PR
: Lines starting with
`SEND-PR' will be removed automatically, as
326 SEND-PR: will all comments (text enclosed in `<' and `>').
328 SEND-PR
: Please consult the send-pr man page
`send-pr(1)' or the Texinfo
329 SEND-PR: manual if you are not sure how to fill out a problem report.
331 SEND-PR: NOTE: If you include a patch that corrects the problem, the
332 SEND-PR: issue will probably be handled much more quickly.
334 SEND-PR: Choose from the following categories:
338 # Format the categories so they fit onto lines.
339 l=`echo "$CATEGORIES" | \
340 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
341 END {print max + 1;}'`
343 if [ $c -eq 0 ]; then c=1; fi
344 echo "$CATEGORIES" | \
345 awk 'BEGIN {printf "SEND-PR: "; i = 0 }
346 { printf ("%-'$l'.'$l's", $0);
347 if ((++i % '$c') == 0) { printf "\nSEND-PR: " } }
348 END { printf "\nSEND-PR:\n"; }' >> $file
350 cat >> $file << __EOF__
355 X-send-pr-version: $VERSION
358 >Submitter-Id: $SUBMITTER
359 >Originator: $ORIGINATOR
361 ${ORGANIZATION- $ORGANIZATION_C}
362 >Confidential: $CONFIDENTIAL_C
363 >Synopsis: $SYNOPSIS_C
364 >Severity: $SEVERITY_C
365 >Priority: $PRIORITY_C
366 >Category: $CATEGORY_C
368 >Release: ${DEFAULT_RELEASE:-"unreleased"}
374 `[ -n "$SYSTEM" ] && echo System
: $SYSTEM`
375 `[ -n "$ARCH" ] && echo Architecture
: $ARCH`
376 `[ -n "$MACHINE" ] && echo Machine
: $MACHINE`
387 if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
393 if [ -z "$REQUEST_ID" ]; then
394 trap "$TRAP_IGNORE_ACTION" 2 3
396 trap "$TRAP_ABORTSAVE_ACTION" 2 3
398 ed -s $TEMP << '__EOF__'
399 /^Subject/s/^Subject:.*/Subject: request for a customer id/
400 /^>Category/s/^>Category:.*/>Category: send-pr/
406 if cmp -s $REF $TEMP ; then
407 echo "$COMMAND: problem report not filled out, therefore not sent"
413 # Check the enumeration fields
415 # This is a "sed-subroutine" with one keyword parameter
416 # (with workaround for Sun sed bug)
429 while [ -z "$REQUEST_ID" ]; do
434 PATTERN=">Confidential:"
435 CONFIDENTIAL=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
436 case "$CONFIDENTIAL" in
437 ""|yes|no) CNT=`expr $CNT + 1` ;;
438 *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'.
" ;;
444 SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
446 ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
447 *) echo "$COMMAND: \
`$SEVERITY' is not a valid value for \`Severity
'."
453 PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
455 ""|low|medium|high) CNT=`expr $CNT + 1` ;;
456 *) echo "$COMMAND: \`$PRIORITY' is not a valid value
for \
`Priority'."
462 CATEGORY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
466 if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
468 if [ -n "$FOUND" ]; then
471 if [ -z "$CATEGORY" ]; then
472 echo "$COMMAND: you must include a Category: field in your report."
474 echo "$COMMAND: \`$CATEGORY' is not a known category."
481 CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
483 ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
484 *) echo "$COMMAND: \`$CLASS' is not a valid value
for \
`Class'."
490 RELEASE=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
491 if [ -z "$RELEASE" ]; then
492 echo "$COMMAND: you must include a Release: field in your report."
497 [ $CNT -lt 6 -a -z "$BATCH" ] &&
498 echo "Errors were found with the problem report."
501 if [ -z "$BATCH" ]; then
502 $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
505 if [ $CNT -eq 6 ]; then
513 if [ -z "$BATCH" ]; then
514 echo "$COMMAND: the problem report remains in $BAD and is not sent."
517 echo "$COMMAND: the problem report is not sent."
522 trap "$TRAP_IGNORE_ACTION" 2 3
524 trap "$TRAP_ABORTSAVE_ACTION" 2 3
534 # Remove comments and send the problem report
535 # (we have to use patterns, where the comment contains regex chars)
537 # /^>Originator:/s;$ORIGINATOR;;
540 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
541 /^>Confidential:/s;<.*>;;
542 /^>Synopsis:/s;$SYNOPSIS_C;;
543 /^>Severity:/s;<.*>;;
544 /^>Priority:/s;<.*>;;
545 /^>Category:/s;$CATEGORY_C;;
547 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C_1;;
548 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C_2;;
549 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C_1;;
550 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C_2;;
551 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
552 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
553 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
556 if $MAIL_AGENT < $REF; then
557 echo "$COMMAND: problem report sent"
560 echo "$COMMAND: mysterious mail failure."
561 if [ -z "$BATCH" ]; then
562 echo "$COMMAND: the problem report remains in $BAD and is not sent."
565 echo "$COMMAND: the problem report is not sent."