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.
25 # The version of this send-pr.
28 # The submitter-id for your site.
29 # "current-users" is the only allowable value for FreeBSD.
30 SUBMITTER="current-users"
32 # Where the GNATS directory lives, if at all.
33 [ -z "$GNATS_ROOT" ] &&
36 # The default mail address for PR submissions.
37 GNATS_ADDR=FreeBSD-gnats-submit@freebsd.org
39 # Where the gnats category tree lives.
42 # If we've been moved around, try using GCC_EXEC_PREFIX.
43 [ ! -d $DATADIR/gnats -a -d "$GCC_EXEC_PREFIX" ] && DATADIR="$GCC_EXEC_PREFIX"
45 # The default release for this host.
46 DEFAULT_RELEASE="@DEFAULT_RELEASE@"
48 # The default organization.
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="${MAIL_AGENT:-/usr/sbin/sendmail -oi -t}"
66 if [ $ECHON = bsd ] ; then
69 elif [ $ECHON = sysv ] ; then
80 if [ "$LOGNAME" = "" ]; then
81 if [ "$USER" != "" ]; then
88 # Find out the name of the originator of this PR.
89 if [ -n "$NAME" ]; then
91 elif [ -f $HOME/.fullname ]; then
92 ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
94 PTEMP=`mktemp -t p` || exit 1
95 # Must use temp file due to incompatibilities in quoting behavior
96 # and to protect shell metacharacters in the expansion of $LOGNAME
97 $PW usershow $LOGNAME | awk -F: '{ print $8 }' | sed -e 's/,.*//' > $PTEMP
98 ORIGINATOR="`cat $PTEMP`"
102 FROM="$ORIGINATOR <$LOGNAME>"
103 REPLY_TO="$ORIGINATOR <${REPLY_TO:-${REPLYTO:-$LOGNAME}}>"
105 if [ -n "$ORGANIZATION" ]; then
106 if [ -f "$ORGANIZATION" ]; then
107 ORGANIZATION="`cat $ORGANIZATION`"
110 if [ -n "$DEFAULT_ORGANIZATION" ]; then
111 ORGANIZATION="$DEFAULT_ORGANIZATION"
112 elif [ -f $HOME/.organization ]; then
113 ORGANIZATION="`cat $HOME/.organization`"
117 # If they don't have a preferred editor set, then use
118 if [ -z "$VISUAL" ]; then
119 if [ -z "$EDITOR" ]; then
128 # Find out some information.
129 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
130 ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
131 ARCH=`[ -f /bin/arch ] && /bin/arch`
132 MACHINE=`[ -f /bin/machine ] && /bin/machine`
134 COMMAND=`echo $0 | sed -e 's,.*/,,'`
135 USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [-s severity]
136 [-c address] [-a file] [--version]"
142 while [ $# -gt 0 ]; do
144 -r) ;; # Ignore for backward compat.
145 -t | --to) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
146 shift ; GNATS_ADDR="$1"
147 EXPLICIT_GNATS_ADDR=true
149 -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
151 if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
152 echo "$COMMAND: cannot read $IN_FILE"
156 -b | --batch) BATCH=true ;;
157 -c | --cc) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
160 -s | --severity) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
161 shift ; SEVERITY_C="$1"
163 -p | -P | --print) PRINT=true ;;
164 -L | --list) FORMAT=norm ;;
165 -l | -CL | --lisp) FORMAT=lisp ;;
166 -h | --help) echo "$USAGE"; exit 0 ;;
167 -V | --version) echo "$VERSION"; exit 0 ;;
168 -a | --attach) if [ -z "$2" ]; then
169 echo "$USAGE" ; exit 1;
171 if [ -e "$2" -a ! -d "$2" ]; then
172 PRETTY_NAME=`basename $2`
173 if file $2 | grep "text" >/dev/null 2>/dev/null ; then
174 ATTACHED_FILES="$ATTACHED_FILES
175 --- $PRETTY_NAME begins here ---
177 --- $PRETTY_NAME ends here ---
180 ATTACHED_FILES="$ATTACHED_FILES
181 `uuencode \"$PRETTY_NAME\" < \"$2\"`
187 -*) echo "$USAGE" ; exit 1 ;;
188 *) if [ -z "$USER_GNATS_SITE" ]; then
189 if [ ! -r "$DATADIR/gnats/$1" ]; then
190 echo "$COMMAND: the GNATS site $1 does not have a categories list."
193 # The site name is the alias they'll have to have created.
197 echo "$USAGE" ; exit 1
204 if [ -n "$USER_GNATS_SITE" ] && [ "$USER_GNATS_SITE" != "$GNATS_SITE" ]; then
205 GNATS_SITE=$USER_GNATS_SITE
206 GNATS_ADDR=$USER_GNATS_SITE-gnats
209 if [ "$SUBMITTER" = "unknown" -a -z "$IN_FILE" ]; then
210 SUBMITTER="current-users"
213 if [ -r "$DATADIR/gnats/$GNATS_SITE" ]; then
214 CATEGORIES=`grep -v '^#' $DATADIR/gnats/$GNATS_SITE | sort`
216 echo "$COMMAND: could not read $DATADIR/gnats/$GNATS_SITE for categories list."
220 if [ -z "$CATEGORIES" ]; then
221 echo "$COMMAND: the categories list for $GNATS_SITE was empty!"
226 lisp) echo "$CATEGORIES" | \
227 awk 'BEGIN {printf "( "} {printf "(\"%s\") ",$0} END {printf ")\n"}'
230 norm) l=`echo "$CATEGORIES" | \
231 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
232 END {print max + 1;}'`
234 if [ $c -eq 0 ]; then c=1; fi
235 echo "$CATEGORIES" | \
236 awk 'BEGIN {print "Known categories:"; i = 0 }
237 { printf ("%-'$l'.'$l's", $0); if ((++i % '$c') == 0) { print "" } }
243 ORIGINATOR_C='<name of the PR author (one line)>'
244 ORGANIZATION_C='<organization of PR author (multiple lines)>'
245 CONFIDENTIAL_C='no <FreeBSD PRs are public data>'
246 SYNOPSIS_C='<synopsis of the problem (one line)>'
247 if [ -z "$SEVERITY_C" ]; then
248 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
250 PRIORITY_C='<[ low | medium | high ] (one line)>'
251 CATEGORY_C='<choose from the list of categories above (one line)>'
252 CLASS_C='<[ sw-bug | doc-bug | change-request | update | maintainer-update ] (one line)>'
253 RELEASE_C='<release number or tag (one line)>'
254 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
255 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
256 HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
257 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
259 # Create temporary files, safely
260 REF=`mktemp -t pf` || exit 1
261 TEMP=`mktemp -t pf` || exit 1
262 # Catch some signals. ($xs kludge needed by Sun /bin/sh)
264 trap 'rm -f $REF $TEMP; exit $xs' 0
265 trap 'SAV=`mktemp -t pr`;echo "$COMMAND: Aborting ... saving unfinished PR into $SAV"; rm -f $REF ; mv $TEMP $SAV; xs=1; exit' 1 2 3 13 15
267 # If they told us to use a specific file, then do so.
268 if [ -n "$IN_FILE" ]; then
269 if [ "$IN_FILE" = "-" ]; then
270 # The PR is coming from the standard input.
271 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
272 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" > $TEMP
277 # Use the file they named.
278 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
279 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" $IN_FILE > $TEMP
286 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
287 # If their PR_FORM points to a bogus entry, then bail.
288 if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
289 echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
291 PRINT_INTERN=bad_prform
295 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
297 ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
298 [ -n "$ATTACHED_FILES" ] && echo "$ATTACHED_FILES" >> $TEMP
300 for file in $TEMP $REF ; do
301 cat > $file << '__EOF__'
302 SEND-PR: -*- send-pr -*-
303 SEND-PR: vim: syntax=sendpr
305 SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
306 SEND-PR: will all comments (text enclosed in `<' and `>').
308 SEND-PR: Please consult the following URL if you are not sure how to
309 SEND-PR: fill out a problem report:
310 SEND-PR: http://www.freebsd.org/doc/en/articles/problem-reports/
312 SEND-PR: Note that the Synopsis field is mandatory.
314 SEND-PR: Please note that (unless you state otherwise) if your report
315 SEND-PR: includes a patch then it will be taken under the same license as
316 SEND-PR: the one on the file(s) you want to change.
318 SEND-PR: BE ADVISED THAT FREEBSD PROBLEM REPORTS ARE PUBLIC INFORMATION AND
319 SEND-PR: WILL BE PUBLISHED AS-IS ON THE PROJECT'S MAILING LISTS AND WEB SITES.
320 SEND-PR: DO NOT SUBMIT ANY INFORMATION YOU DO NOT WANT MADE PUBLIC.
322 SEND-PR: If you wish to submit a problem report confidentially, then contact
323 SEND-PR: the FreeBSD bugmaster (bugmaster@FreeBSD.org) to arrange for a
324 SEND-PR: relevant developer to be contacted.
326 SEND-PR: For sensitive security issues, consider contacting the FreeBSD
327 SEND-PR: security officer team (security-officer@freebsd.org) directly.
329 SEND-PR: Choose from the following categories:
333 # Format the categories so they fit onto lines.
334 l=`echo "$CATEGORIES" | \
335 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
336 END {print max + 1;}'`
338 if [ $c -eq 0 ]; then c=1; fi
339 echo "$CATEGORIES" | \
340 awk 'BEGIN {printf "SEND-PR: "; i = 0 }
341 { printf ("%-'$l'.'$l's", $0);
342 if ((++i % '$c') == 0) { printf "\nSEND-PR: " } }
343 END { printf "\nSEND-PR:\n"; }' >> $file
345 cat >> $file << __EOF__
350 X-send-pr-version: $VERSION
354 >Submitter-Id: $SUBMITTER
355 >Originator: $ORIGINATOR
356 >Organization: ${ORGANIZATION-$ORGANIZATION_C}
357 >Confidential: $CONFIDENTIAL_C
358 >Synopsis: $SYNOPSIS_C
359 >Severity: $SEVERITY_C
360 >Priority: $PRIORITY_C
361 >Category: $CATEGORY_C
363 >Release: ${DEFAULT_RELEASE-$RELEASE_C}
365 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
366 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
367 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
383 if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
391 if cmp -s $REF $TEMP ; then
392 echo "$COMMAND: problem report not filled out, therefore not sent"
398 # Check the enumeration fields
400 # This is a "sed-subroutine" with one keyword parameter
401 # (with workaround for Sun sed bug)
418 PATTERN=">Confidential:"
419 CONFIDENTIAL=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
420 case "$CONFIDENTIAL" in
421 ""|no) CNT=`expr $CNT + 1` ;;
422 *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
428 SEVERITY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
430 ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
431 *) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
437 PRIORITY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
439 ""|low|medium|high) CNT=`expr $CNT + 1` ;;
440 *) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
446 CATEGORY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
450 if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
452 if [ -n "$FOUND" ]; then
455 if [ -z "$CATEGORY" ]; then
456 echo "$COMMAND: you must include a Category: field in your report."
458 echo "$COMMAND: \`$CATEGORY' is not a known category."
465 CLASS=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
467 ""|sw-bug|doc-bug|change-request|update|maintainer-update) CNT=`expr $CNT + 1` ;;
468 *) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
471 # 6) Check that synopsis is not empty
473 if grep "^>Synopsis:[ ]*${SYNOPSIS_C}\$" $TEMP > /dev/null
475 echo "$COMMAND: Synopsis must not be empty."
480 [ $CNT -lt 6 -a -z "$BATCH" ] &&
481 echo "Errors were found with the problem report."
484 if [ -z "$BATCH" ]; then
485 $ECHON1 "s)end, e)dit or a)bort? $ECHON2"
488 if [ $CNT -eq 6 ]; then
496 if [ -z "$BATCH" ]; then
498 echo "$COMMAND: the problem report remains in $BAD and is not sent."
501 echo "$COMMAND: the problem report is not sent."
510 if [ $CNT -lt 6 ]; then
511 if [ -z "$BATCH" ]; then
512 echo "But there are still errors in the problem report!"
515 echo "Errors found in PR"
526 # Remove the subject field if one is already there. There's no reason
527 # for it to be any different than the synopsis.
529 if grep '^Subject:' $TEMP > /dev/null
531 ed -s $TEMP << __EOF__
539 # Add the subject field with the value of $SYNOPSIS. We use the To:
540 # field as an anchor, which had better be there.
542 SYNOPSIS=`grep '^>Synopsis:' $TEMP | sed -e 's/^>Synopsis:[ ]*//' |
543 sed -e "s;$SYNOPSIS_C;;"`
544 ed -s $TEMP << __EOF__
553 # Remove comments and send the problem report
554 # (we have to use patterns, where the comment contains regex chars)
556 # /^>Originator:/s;$ORIGINATOR;;
559 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
560 /^>Confidential:/s;<.*>;;
561 /^>Synopsis:/s;$SYNOPSIS_C;;
562 /^>Severity:/s;<.*>;;
563 /^>Priority:/s;<.*>;;
564 /^>Category:/s;$CATEGORY_C;;
566 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
567 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
568 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
569 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
570 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
573 if $MAIL_AGENT < $REF; then
574 echo "$COMMAND: problem report sent"
577 echo "$COMMAND: mysterious mail failure."
578 if [ -z "$BATCH" ]; then
580 echo "$COMMAND: the problem report remains in $BAD and is not sent."
583 echo "$COMMAND: the problem report is not sent."