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 PTEMP2=`mktemp -t p` || exit 1
96 # Must use temp file due to incompatibilities in quoting behavior
97 # and to protect shell metacharacters in the expansion of $LOGNAME
98 $ECHON1 $LOGNAME | awk '{print toupper(substr($1,1,1))substr($1,2)}' > $PTEMP2
99 ICLOGNAME="`cat $PTEMP2`"
100 $PW usershow $LOGNAME | awk -F: '{ print $8 }' \
101 | sed -e "s/\&/$ICLOGNAME/" \
102 | sed -e 's/,.*//' > $PTEMP
103 ORIGINATOR="`cat $PTEMP`"
104 rm -f "$PTEMP" "$PTEMP2"
107 FROM="$ORIGINATOR <$LOGNAME>"
108 REPLY_TO="$ORIGINATOR <${REPLY_TO:-${REPLYTO:-$LOGNAME}}>"
110 if [ -n "$ORGANIZATION" ]; then
111 if [ -f "$ORGANIZATION" ]; then
112 ORGANIZATION="`cat $ORGANIZATION`"
115 if [ -n "$DEFAULT_ORGANIZATION" ]; then
116 ORGANIZATION="$DEFAULT_ORGANIZATION"
117 elif [ -f $HOME/.organization ]; then
118 ORGANIZATION="`cat $HOME/.organization`"
122 # If they don't have a preferred editor set, then use
123 if [ -z "$VISUAL" ]; then
124 if [ -z "$EDITOR" ]; then
133 # Find out some information.
134 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
135 ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
136 ARCH=`[ -f /bin/arch ] && /bin/arch`
137 MACHINE=`[ -f /bin/machine ] && /bin/machine`
139 COMMAND=`echo $0 | sed -e 's,.*/,,'`
140 USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [-s severity]
141 [-c address] [-a file] [--version]"
147 while [ $# -gt 0 ]; do
149 -r) ;; # Ignore for backward compat.
150 -t | --to) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
151 shift ; GNATS_ADDR="$1"
152 EXPLICIT_GNATS_ADDR=true
154 -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
156 if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
157 echo "$COMMAND: cannot read $IN_FILE"
161 -b | --batch) BATCH=true ;;
162 -c | --cc) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
165 -s | --severity) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
166 shift ; SEVERITY_C="$1"
168 -p | -P | --print) PRINT=true ;;
169 -L | --list) FORMAT=norm ;;
170 -l | -CL | --lisp) FORMAT=lisp ;;
171 -h | --help) echo "$USAGE"; exit 0 ;;
172 -V | --version) echo "$VERSION"; exit 0 ;;
173 -a | --attach) if [ -z "$2" ]; then
174 echo "$USAGE" ; exit 1;
176 if [ -e "$2" -a ! -d "$2" ]; then
177 PRETTY_NAME=`basename $2`
178 if file $2 | grep "text" >/dev/null 2>/dev/null ; then
179 ATTACHED_FILES="$ATTACHED_FILES
180 --- $PRETTY_NAME begins here ---
182 --- $PRETTY_NAME ends here ---
185 ATTACHED_FILES="$ATTACHED_FILES
186 `uuencode \"$PRETTY_NAME\" < \"$2\"`
192 -*) echo "$USAGE" ; exit 1 ;;
193 *) if [ -z "$USER_GNATS_SITE" ]; then
194 if [ ! -r "$DATADIR/gnats/$1" ]; then
195 echo "$COMMAND: the GNATS site $1 does not have a categories list."
198 # The site name is the alias they'll have to have created.
202 echo "$USAGE" ; exit 1
209 if [ -n "$USER_GNATS_SITE" ] && [ "$USER_GNATS_SITE" != "$GNATS_SITE" ]; then
210 GNATS_SITE=$USER_GNATS_SITE
211 GNATS_ADDR=$USER_GNATS_SITE-gnats
214 if [ "$SUBMITTER" = "unknown" -a -z "$IN_FILE" ]; then
215 SUBMITTER="current-users"
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."
225 if [ -z "$CATEGORIES" ]; then
226 echo "$COMMAND: the categories list for $GNATS_SITE was empty!"
231 lisp) echo "$CATEGORIES" | \
232 awk 'BEGIN {printf "( "} {printf "(\"%s\") ",$0} END {printf ")\n"}'
235 norm) l=`echo "$CATEGORIES" | \
236 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
237 END {print max + 1;}'`
239 if [ $c -eq 0 ]; then c=1; fi
240 echo "$CATEGORIES" | \
241 awk 'BEGIN {print "Known categories:"; i = 0 }
242 { printf ("%-'$l'.'$l's", $0); if ((++i % '$c') == 0) { print "" } }
248 ORIGINATOR_C='<name of the PR author (one line)>'
249 ORGANIZATION_C='<organization of PR author (multiple lines)>'
250 CONFIDENTIAL_C='no <FreeBSD PRs are public data>'
251 SYNOPSIS_C='<synopsis of the problem (one line)>'
252 if [ -z "$SEVERITY_C" ]; then
253 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
255 PRIORITY_C='<[ low | medium | high ] (one line)>'
256 CATEGORY_C='<choose from the list of categories above (one line)>'
257 CLASS_C='<[ sw-bug | doc-bug | change-request | update | maintainer-update ] (one line)>'
258 RELEASE_C='<release number or tag (one line)>'
259 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
260 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
261 HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
262 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
264 # Create temporary files, safely
265 REF=`mktemp -t pf` || exit 1
266 TEMP=`mktemp -t pf` || exit 1
267 # Catch some signals. ($xs kludge needed by Sun /bin/sh)
269 trap 'rm -f $REF $TEMP; exit $xs' 0
270 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
272 # If they told us to use a specific file, then do so.
273 if [ -n "$IN_FILE" ]; then
274 if [ "$IN_FILE" = "-" ]; then
275 # The PR is coming from the standard input.
276 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
277 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" > $TEMP
282 # Use the file they named.
283 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
284 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" $IN_FILE > $TEMP
291 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
292 # If their PR_FORM points to a bogus entry, then bail.
293 if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
294 echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
296 PRINT_INTERN=bad_prform
300 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
302 ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
303 [ -n "$ATTACHED_FILES" ] && echo "$ATTACHED_FILES" >> $TEMP
305 for file in $TEMP $REF ; do
306 cat > $file << '__EOF__'
307 SEND-PR: -*- send-pr -*-
308 SEND-PR: vim: syntax=sendpr
310 SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
311 SEND-PR: will all comments (text enclosed in `<' and `>').
313 SEND-PR: Please consult the following URL if you are not sure how to
314 SEND-PR: fill out a problem report:
315 SEND-PR: http://www.freebsd.org/doc/en/articles/problem-reports/
317 SEND-PR: Note that the Synopsis field is mandatory.
319 SEND-PR: Please note that (unless you state otherwise) if your report
320 SEND-PR: includes a patch then it will be taken under the same license as
321 SEND-PR: the one on the file(s) you want to change.
323 SEND-PR: BE ADVISED THAT FREEBSD PROBLEM REPORTS ARE PUBLIC INFORMATION AND
324 SEND-PR: WILL BE PUBLISHED AS-IS ON THE PROJECT'S MAILING LISTS AND WEB SITES.
325 SEND-PR: DO NOT SUBMIT ANY INFORMATION YOU DO NOT WANT MADE PUBLIC.
327 SEND-PR: If you wish to submit a problem report confidentially, then contact
328 SEND-PR: the FreeBSD bugmaster (bugmaster@FreeBSD.org) to arrange for a
329 SEND-PR: relevant developer to be contacted.
331 SEND-PR: For sensitive security issues, consider contacting the FreeBSD
332 SEND-PR: security officer team (security-officer@freebsd.org) directly.
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
359 >Submitter-Id: $SUBMITTER
360 >Originator: $ORIGINATOR
361 >Organization: ${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-$RELEASE_C}
370 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
371 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
372 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
388 if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
396 if cmp -s $REF $TEMP ; then
397 echo "$COMMAND: problem report not filled out, therefore not sent"
403 # Check the enumeration fields
405 # This is a "sed-subroutine" with one keyword parameter
406 # (with workaround for Sun sed bug)
423 PATTERN=">Confidential:"
424 CONFIDENTIAL=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
425 case "$CONFIDENTIAL" in
426 ""|no) CNT=`expr $CNT + 1` ;;
427 *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
433 SEVERITY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
435 ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
436 *) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
442 PRIORITY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
444 ""|low|medium|high) CNT=`expr $CNT + 1` ;;
445 *) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
451 CATEGORY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
455 if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
457 if [ -n "$FOUND" ]; then
460 if [ -z "$CATEGORY" ]; then
461 echo "$COMMAND: you must include a Category: field in your report."
463 echo "$COMMAND: \`$CATEGORY' is not a known category."
470 CLASS=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
472 ""|sw-bug|doc-bug|change-request|update|maintainer-update) CNT=`expr $CNT + 1` ;;
473 *) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
476 # 6) Check that synopsis is not empty
478 if grep "^>Synopsis:[ ]*${SYNOPSIS_C}\$" $TEMP > /dev/null
480 echo "$COMMAND: Synopsis must not be empty."
485 [ $CNT -lt 6 -a -z "$BATCH" ] &&
486 echo "Errors were found with the problem report."
489 if [ -z "$BATCH" ]; then
490 $ECHON1 "s)end, e)dit or a)bort? $ECHON2"
493 if [ $CNT -eq 6 ]; then
501 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."
515 if [ $CNT -lt 6 ]; then
516 if [ -z "$BATCH" ]; then
517 echo "But there are still errors in the problem report!"
520 echo "Errors found in PR"
531 # Remove the subject field if one is already there. There's no reason
532 # for it to be any different than the synopsis.
534 if grep '^Subject:' $TEMP > /dev/null
536 ed -s $TEMP << __EOF__
544 # Add the subject field with the value of $SYNOPSIS. We use the To:
545 # field as an anchor, which had better be there.
547 SYNOPSIS=`grep '^>Synopsis:' $TEMP | sed -e 's/^>Synopsis:[ ]*//' |
548 sed -e "s;$SYNOPSIS_C;;"`
549 ed -s $TEMP << __EOF__
558 # Remove comments and send the problem report
559 # (we have to use patterns, where the comment contains regex chars)
561 # /^>Originator:/s;$ORIGINATOR;;
564 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
565 /^>Confidential:/s;<.*>;;
566 /^>Synopsis:/s;$SYNOPSIS_C;;
567 /^>Severity:/s;<.*>;;
568 /^>Priority:/s;<.*>;;
569 /^>Category:/s;$CATEGORY_C;;
571 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
572 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
573 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
574 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
575 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
578 if $MAIL_AGENT < $REF; then
579 echo "$COMMAND: problem report sent"
582 echo "$COMMAND: mysterious mail failure."
583 if [ -z "$BATCH" ]; then
585 echo "$COMMAND: the problem report remains in $BAD and is not sent."
588 echo "$COMMAND: the problem report is not sent."