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 # $FreeBSD: src/gnu/usr.bin/send-pr/send-pr.sh,v 1.13.2.11 2002/03/19 00:33:35 des Exp $
24 # $DragonFly: src/gnu/usr.bin/send-pr/Attic/send-pr.sh,v 1.2 2003/06/17 04:25:48 dillon Exp $
26 # The version of this send-pr.
29 # The submitter-id for your site.
30 # "current-users" is the only allowable value for FreeBSD.
31 SUBMITTER="current-users"
33 # Where the GNATS directory lives, if at all.
34 [ -z "$GNATS_ROOT" ] &&
37 # The default mail address for PR submissions.
38 GNATS_ADDR=FreeBSD-gnats-submit@freebsd.org
40 # Where the gnats category tree lives.
43 # If we've been moved around, try using GCC_EXEC_PREFIX.
44 [ ! -d $DATADIR/gnats -a -d "$GCC_EXEC_PREFIX" ] && DATADIR="$GCC_EXEC_PREFIX"
46 # The default release for this host.
47 DEFAULT_RELEASE="@DEFAULT_RELEASE@"
49 # The default organization.
52 # The default site to look for.
55 # Newer config information?
56 [ -f ${GNATS_ROOT}/gnats-adm/config ] && . ${GNATS_ROOT}/gnats-adm/config
58 # What mailer to use. This must come after the config file, since it is
60 MAIL_AGENT="${MAIL_AGENT:-/usr/sbin/sendmail -oi -t}"
67 if [ $ECHON = bsd ] ; then
70 elif [ $ECHON = sysv ] ; then
81 if [ "$LOGNAME" = "" ]; then
82 if [ "$USER" != "" ]; then
89 # Find out the name of the originator of this PR.
90 if [ -n "$NAME" ]; then
92 elif [ -f $HOME/.fullname ]; then
93 ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
95 PTEMP=`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 $PW usershow $LOGNAME | awk -F: '{ print $8 }' | sed -e 's/,.*//' > $PTEMP
99 ORIGINATOR="`cat $PTEMP`"
103 FROM="$ORIGINATOR <$LOGNAME>"
104 REPLY_TO="$ORIGINATOR <${REPLY_TO:-${REPLYTO:-$LOGNAME}}>"
106 if [ -n "$ORGANIZATION" ]; then
107 if [ -f "$ORGANIZATION" ]; then
108 ORGANIZATION="`cat $ORGANIZATION`"
111 if [ -n "$DEFAULT_ORGANIZATION" ]; then
112 ORGANIZATION="$DEFAULT_ORGANIZATION"
113 elif [ -f $HOME/.organization ]; then
114 ORGANIZATION="`cat $HOME/.organization`"
118 # If they don't have a preferred editor set, then use
119 if [ -z "$VISUAL" ]; then
120 if [ -z "$EDITOR" ]; then
129 # Find out some information.
130 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
131 ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
132 ARCH=`[ -f /bin/arch ] && /bin/arch`
133 MACHINE=`[ -f /bin/machine ] && /bin/machine`
135 COMMAND=`echo $0 | sed -e 's,.*/,,'`
136 USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [-s severity]
137 [-c address] [-a file] [--version]"
143 while [ $# -gt 0 ]; do
145 -r) ;; # Ignore for backward compat.
146 -t | --to) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
147 shift ; GNATS_ADDR="$1"
148 EXPLICIT_GNATS_ADDR=true
150 -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
152 if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
153 echo "$COMMAND: cannot read $IN_FILE"
157 -b | --batch) BATCH=true ;;
158 -c | --cc) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
161 -s | --severity) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
162 shift ; SEVERITY_C="$1"
164 -p | -P | --print) PRINT=true ;;
165 -L | --list) FORMAT=norm ;;
166 -l | -CL | --lisp) FORMAT=lisp ;;
167 -h | --help) echo "$USAGE"; exit 0 ;;
168 -V | --version) echo "$VERSION"; exit 0 ;;
169 -a | --attach) if [ -z "$2" ]; then
170 echo "$USAGE" ; exit 1;
172 if [ -e "$2" -a ! -d "$2" ]; then
173 PRETTY_NAME=`basename $2`
174 if file $2 | grep "text" >/dev/null 2>/dev/null ; then
175 ATTACHED_FILES="$ATTACHED_FILES
176 --- $PRETTY_NAME begins here ---
178 --- $PRETTY_NAME ends here ---
181 ATTACHED_FILES="$ATTACHED_FILES
182 `uuencode \"$PRETTY_NAME\" < \"$2\"`
188 -*) echo "$USAGE" ; exit 1 ;;
189 *) if [ -z "$USER_GNATS_SITE" ]; then
190 if [ ! -r "$DATADIR/gnats/$1" ]; then
191 echo "$COMMAND: the GNATS site $1 does not have a categories list."
194 # The site name is the alias they'll have to have created.
198 echo "$USAGE" ; exit 1
205 if [ -n "$USER_GNATS_SITE" ] && [ "$USER_GNATS_SITE" != "$GNATS_SITE" ]; then
206 GNATS_SITE=$USER_GNATS_SITE
207 GNATS_ADDR=$USER_GNATS_SITE-gnats
210 if [ "$SUBMITTER" = "unknown" -a -z "$IN_FILE" ]; then
211 SUBMITTER="current-users"
214 if [ -r "$DATADIR/gnats/$GNATS_SITE" ]; then
215 CATEGORIES=`grep -v '^#' $DATADIR/gnats/$GNATS_SITE | sort`
217 echo "$COMMAND: could not read $DATADIR/gnats/$GNATS_SITE for categories list."
221 if [ -z "$CATEGORIES" ]; then
222 echo "$COMMAND: the categories list for $GNATS_SITE was empty!"
227 lisp) echo "$CATEGORIES" | \
228 awk 'BEGIN {printf "( "} {printf "(\"%s\") ",$0} END {printf ")\n"}'
231 norm) l=`echo "$CATEGORIES" | \
232 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
233 END {print max + 1;}'`
235 if [ $c -eq 0 ]; then c=1; fi
236 echo "$CATEGORIES" | \
237 awk 'BEGIN {print "Known categories:"; i = 0 }
238 { printf ("%-'$l'.'$l's", $0); if ((++i % '$c') == 0) { print "" } }
244 ORIGINATOR_C='<name of the PR author (one line)>'
245 ORGANIZATION_C='<organization of PR author (multiple lines)>'
246 CONFIDENTIAL_C='no <FreeBSD PRs are public data>'
247 SYNOPSIS_C='<synopsis of the problem (one line)>'
248 if [ -z "$SEVERITY_C" ]; then
249 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
251 PRIORITY_C='<[ low | medium | high ] (one line)>'
252 CATEGORY_C='<choose from the list of categories above (one line)>'
253 CLASS_C='<[ sw-bug | doc-bug | change-request | update | maintainer-update ] (one line)>'
254 RELEASE_C='<release number or tag (one line)>'
255 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
256 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
257 HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
258 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
260 # Create temporary files, safely
261 REF=`mktemp -t pf` || exit 1
262 TEMP=`mktemp -t pf` || exit 1
263 # Catch some signals. ($xs kludge needed by Sun /bin/sh)
265 trap 'rm -f $REF $TEMP; exit $xs' 0
266 trap 'echo "$COMMAND: Aborting ..."; rm -f $REF $TEMP; xs=1; exit' 1 2 3 13 15
268 # If they told us to use a specific file, then do so.
269 if [ -n "$IN_FILE" ]; then
270 if [ "$IN_FILE" = "-" ]; then
271 # The PR is coming from the standard input.
272 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
273 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" > $TEMP
278 # Use the file they named.
279 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
280 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" $IN_FILE > $TEMP
287 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
288 # If their PR_FORM points to a bogus entry, then bail.
289 if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
290 echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
292 PRINT_INTERN=bad_prform
296 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
298 ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
299 [ -n "$ATTACHED_FILES" ] && echo "$ATTACHED_FILES" >> $TEMP
301 for file in $TEMP $REF ; do
302 cat > $file << '__EOF__'
303 SEND-PR: -*- send-pr -*-
304 SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
305 SEND-PR: will all comments (text enclosed in `<' and `>').
307 SEND-PR: Please consult the following URL if you are not sure how to
308 SEND-PR: fill out a problem report:
309 SEND-PR: http://www.freebsd.org/doc/en/articles/problem-reports/article.html
311 SEND-PR: Note that the Synopsis field is mandatory.
313 SEND-PR: Please note that (unless you state otherwise) if your report
314 SEND-PR: includes a patch then it will be taken under the same license as
315 SEND-PR: the one on the file(s) you want to change.
317 SEND-PR: BE ADVISED THAT FREEBSD PROBLEM REPORTS ARE PUBLIC INFORMATION AND
318 SEND-PR: WILL BE PUBLISHED AS-IS ON THE PROJECT'S MAILING LISTS AND WEB SITES.
319 SEND-PR: DO NOT SUBMIT ANY INFORMATION YOU DO NOT WANT MADE PUBLIC.
321 SEND-PR: For sensitive security issues, consider contacting the FreeBSD
322 SEND-PR: security officer team (security-officer@freebsd.org) directly.
324 SEND-PR: Choose from the following categories:
328 # Format the categories so they fit onto lines.
329 l=`echo "$CATEGORIES" | \
330 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
331 END {print max + 1;}'`
333 if [ $c -eq 0 ]; then c=1; fi
334 echo "$CATEGORIES" | \
335 awk 'BEGIN {printf "SEND-PR: "; i = 0 }
336 { printf ("%-'$l'.'$l's", $0);
337 if ((++i % '$c') == 0) { printf "\nSEND-PR: " } }
338 END { printf "\nSEND-PR:\n"; }' >> $file
340 cat >> $file << __EOF__
345 X-send-pr-version: $VERSION
349 >Submitter-Id: $SUBMITTER
350 >Originator: $ORIGINATOR
351 >Organization: ${ORGANIZATION-$ORGANIZATION_C}
352 >Confidential: $CONFIDENTIAL_C
353 >Synopsis: $SYNOPSIS_C
354 >Severity: $SEVERITY_C
355 >Priority: $PRIORITY_C
356 >Category: $CATEGORY_C
358 >Release: ${DEFAULT_RELEASE-$RELEASE_C}
360 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
361 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
362 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
378 if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
386 if cmp -s $REF $TEMP ; then
387 echo "$COMMAND: problem report not filled out, therefore not sent"
393 # Check the enumeration fields
395 # This is a "sed-subroutine" with one keyword parameter
396 # (with workaround for Sun sed bug)
413 PATTERN=">Confidential:"
414 CONFIDENTIAL=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
415 case "$CONFIDENTIAL" in
416 ""|no) CNT=`expr $CNT + 1` ;;
417 *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
423 SEVERITY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
425 ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
426 *) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
432 PRIORITY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
434 ""|low|medium|high) CNT=`expr $CNT + 1` ;;
435 *) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
441 CATEGORY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
445 if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
447 if [ -n "$FOUND" ]; then
450 if [ -z "$CATEGORY" ]; then
451 echo "$COMMAND: you must include a Category: field in your report."
453 echo "$COMMAND: \`$CATEGORY' is not a known category."
460 CLASS=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
462 ""|sw-bug|doc-bug|change-request|update|maintainer-update) CNT=`expr $CNT + 1` ;;
463 *) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
466 # 6) Check that synopsis is not empty
468 if grep "^>Synopsis:[ ]*${SYNOPSIS_C}\$" $TEMP > /dev/null
470 echo "$COMMAND: Synopsis must not be empty."
475 [ $CNT -lt 6 -a -z "$BATCH" ] &&
476 echo "Errors were found with the problem report."
479 if [ -z "$BATCH" ]; then
480 $ECHON1 "s)end, e)dit or a)bort? $ECHON2"
483 if [ $CNT -eq 6 ]; then
491 if [ -z "$BATCH" ]; then
493 echo "$COMMAND: the problem report remains in $BAD and is not sent."
496 echo "$COMMAND: the problem report is not sent."
512 # Remove the subject field if one is already there. There's no reason
513 # for it to be any different than the synopsis.
515 if grep '^Subject:' $TEMP > /dev/null
517 ed -s $TEMP << __EOF__
525 # Add the subject field with the value of $SYNOPSIS. We use the To:
526 # field as an anchor, which had better be there.
528 SYNOPSIS=`grep '^>Synopsis:' $TEMP | sed -e 's/^>Synopsis:[ ]*//' |
529 sed -e "s;$SYNOPSIS_C;;"`
530 ed -s $TEMP << __EOF__
539 # Remove comments and send the problem report
540 # (we have to use patterns, where the comment contains regex chars)
542 # /^>Originator:/s;$ORIGINATOR;;
545 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
546 /^>Confidential:/s;<.*>;;
547 /^>Synopsis:/s;$SYNOPSIS_C;;
548 /^>Severity:/s;<.*>;;
549 /^>Priority:/s;<.*>;;
550 /^>Category:/s;$CATEGORY_C;;
552 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
553 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
554 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
555 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
556 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
559 if $MAIL_AGENT < $REF; then
560 echo "$COMMAND: problem report sent"
563 echo "$COMMAND: mysterious mail failure."
564 if [ -z "$BATCH" ]; then
566 echo "$COMMAND: the problem report remains in $BAD and is not sent."
569 echo "$COMMAND: the problem report is not sent."