]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - gnu/usr.bin/send-pr/send-pr.sh
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / gnu / usr.bin / send-pr / send-pr.sh
1 #!/bin/sh
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).
6 #
7 # This file is part of GNU GNATS.
8 #
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)
12 # any later version.
13 #
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.
18 #
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.
22 #
23 # $FreeBSD$
24
25 # The version of this send-pr.
26 VERSION=3.114
27
28 # The submitter-id for your site.
29 # "current-users" is the only allowable value for FreeBSD.
30 SUBMITTER="current-users"
31
32 # Where the GNATS directory lives, if at all.
33 [ -z "$GNATS_ROOT" ] && 
34 GNATS_ROOT=
35
36 # The default mail address for PR submissions. 
37 GNATS_ADDR=FreeBSD-gnats-submit@freebsd.org
38
39 # Where the gnats category tree lives.
40 DATADIR=@DATADIR@
41
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"
44
45 # The default release for this host.
46 DEFAULT_RELEASE="@DEFAULT_RELEASE@"
47
48 # The default organization.
49 DEFAULT_ORGANIZATION=
50
51 # The default site to look for.
52 GNATS_SITE=freefall
53
54 # Newer config information?
55 [ -f ${GNATS_ROOT}/gnats-adm/config ] && . ${GNATS_ROOT}/gnats-adm/config
56
57 # What mailer to use.  This must come after the config file, since it is
58 # host-dependent.
59 MAIL_AGENT="${MAIL_AGENT:-/usr/sbin/sendmail -oi -t}"
60
61 # Path to pw(8)
62 PW="/usr/sbin/pw"
63
64 ECHON=bsd
65
66 if [ $ECHON = bsd ] ; then
67   ECHON1="echo -n"
68   ECHON2=
69 elif [ $ECHON = sysv ] ; then
70   ECHON1=echo
71   ECHON2='\c'
72 else
73   ECHON1=echo
74   ECHON2=
75 fi
76
77 #\f
78
79 # find a user name
80 if [ "$LOGNAME" = "" ]; then
81         if [ "$USER" != "" ]; then
82                 LOGNAME="$USER"
83         else
84                 LOGNAME="UNKNOWN"
85         fi
86 fi
87
88 # Find out the name of the originator of this PR.
89 if [ -n "$NAME" ]; then
90   ORIGINATOR="$NAME"
91 elif [ -f $HOME/.fullname ]; then
92   ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
93 else
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"
105 fi
106
107 FROM="$ORIGINATOR <$LOGNAME>"
108 REPLY_TO="$ORIGINATOR <${REPLY_TO:-${REPLYTO:-$LOGNAME}}>"
109
110 if [ -n "$ORGANIZATION" ]; then
111   if [ -f "$ORGANIZATION" ]; then
112     ORGANIZATION="`cat $ORGANIZATION`"
113   fi
114 else
115   if [ -n "$DEFAULT_ORGANIZATION" ]; then
116     ORGANIZATION="$DEFAULT_ORGANIZATION"
117   elif [ -f $HOME/.organization ]; then
118     ORGANIZATION="`cat $HOME/.organization`"
119   fi
120 fi
121
122 # If they don't have a preferred editor set, then use
123 if [ -z "$VISUAL" ]; then
124   if [ -z "$EDITOR" ]; then
125     EDIT=vi
126   else
127     EDIT="$EDITOR"
128   fi
129 else
130   EDIT="$VISUAL"
131 fi
132
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`
138
139 COMMAND=`echo $0 | sed -e 's,.*/,,'`
140 USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [-s severity]
141        [-c address] [-a file] [--version]"
142 REMOVE=
143 BATCH=
144 CC=
145 SEVERITY_C=
146
147 while [ $# -gt 0 ]; do
148   case "$1" in
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
153         ;;
154     -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
155         shift ; IN_FILE="$1"
156         if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
157           echo "$COMMAND: cannot read $IN_FILE"
158           exit 1
159         fi
160         ;;
161     -b | --batch) BATCH=true ;;
162     -c | --cc) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
163         shift ; CC="$1"
164         ;;
165     -s | --severity) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
166         shift ; SEVERITY_C="$1"
167         ;;
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; 
175         fi
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 ---
181 `cat \"$2\"`
182 --- $PRETTY_NAME ends here ---
183 "
184           else
185             ATTACHED_FILES="$ATTACHED_FILES
186 `uuencode \"$PRETTY_NAME\" < \"$2\"`
187 "
188           fi
189           shift;
190         fi;
191         ;;
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."
196            exit 1
197          else
198            # The site name is the alias they'll have to have created.
199            USER_GNATS_SITE=$1
200          fi
201        else
202          echo "$USAGE" ; exit 1
203        fi
204        ;;
205  esac
206  shift
207 done
208
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
212 fi
213
214 if [ "$SUBMITTER" = "unknown" -a -z "$IN_FILE" ]; then
215   SUBMITTER="current-users"
216 fi
217
218 if [ -r "$DATADIR/gnats/$GNATS_SITE" ]; then
219   CATEGORIES=`grep -v '^#' $DATADIR/gnats/$GNATS_SITE | sort`
220 else
221   echo "$COMMAND: could not read $DATADIR/gnats/$GNATS_SITE for categories list."
222   exit 1
223 fi
224
225 if [ -z "$CATEGORIES" ]; then
226   echo "$COMMAND: the categories list for $GNATS_SITE was empty!"
227   exit 1
228 fi
229
230 case "$FORMAT" in
231   lisp) echo "$CATEGORIES" | \
232         awk 'BEGIN {printf "( "} {printf "(\"%s\") ",$0} END {printf ")\n"}'
233         exit 0
234         ;;
235   norm) l=`echo "$CATEGORIES" | \
236         awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
237              END {print max + 1;}'`
238         c=`expr 70 / $l`
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 "" } }
243             END { print ""; }'
244         exit 0
245         ;;
246 esac
247
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)>'
254 fi
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)>'
263
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)
268 xs=0
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
271
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
278     else
279       cat > $TEMP
280     fi
281   else
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
285     else
286       cat $IN_FILE > $TEMP
287     fi
288   fi
289 else
290
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"
295       sleep 1
296       PRINT_INTERN=bad_prform
297     fi
298   fi
299
300   if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
301     cp $PR_FORM $TEMP || 
302       ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
303     [ -n "$ATTACHED_FILES" ] && echo "$ATTACHED_FILES" >> $TEMP
304   else
305     for file in $TEMP $REF ; do
306       cat  > $file << '__EOF__'
307 SEND-PR: -*- send-pr -*-
308 SEND-PR: vim: syntax=sendpr
309 SEND-PR:
310 SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
311 SEND-PR: will all comments (text enclosed in `<' and `>').
312 SEND-PR:
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/
316 SEND-PR:
317 SEND-PR: Note that the Synopsis field is mandatory.
318 SEND-PR:
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.
322 SEND-PR:
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.
326 SEND-PR:
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.
330 SEND-PR:
331 SEND-PR: For sensitive security issues, consider contacting the FreeBSD
332 SEND-PR: security officer team (security-officer@freebsd.org) directly.
333 SEND-PR:
334 SEND-PR: Choose from the following categories:
335 SEND-PR:
336 __EOF__
337
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;}'`
342         c=`expr 61 / $l`
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
349
350       cat >> $file << __EOF__
351 To: $GNATS_ADDR
352 From: $FROM
353 Reply-To: $REPLY_TO
354 Cc: $CC
355 X-send-pr-version: $VERSION
356 X-GNATS-Notify: 
357
358
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
367 >Class:         $CLASS_C
368 >Release:       ${DEFAULT_RELEASE-$RELEASE_C}
369 >Environment:
370 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
371 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
372 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
373         $ENVIRONMENT_C
374 >Description:
375         $DESCRIPTION_C
376 >How-To-Repeat:
377         $HOW_TO_REPEAT_C
378 >Fix:
379
380         $FIX_C
381 $ATTACHED_FILES
382
383 __EOF__
384
385     done
386   fi
387
388   if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
389     cat $TEMP
390     xs=0; exit
391   fi
392
393   chmod u+w $TEMP
394   eval $EDIT $TEMP
395
396   if cmp -s $REF $TEMP ; then
397     echo "$COMMAND: problem report not filled out, therefore not sent"
398     xs=1; exit
399   fi
400 fi
401
402 #\f
403 #       Check the enumeration fields
404
405 # This is a "sed-subroutine" with one keyword parameter 
406 # (with workaround for Sun sed bug)
407 #
408 SED_CMD='{
409 s|||
410 s|<.*>||
411 s|^[    ]*||
412 s|[     ]*$||
413 p
414 q
415 }'
416
417
418 while true; do
419   CNT=0
420
421   # 1) Confidential
422   #
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'." ;;
428   esac
429   #
430   # 2) Severity
431   #
432   PATTERN=">Severity:"
433   SEVERITY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
434   case "$SEVERITY" in
435     ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
436     *)  echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
437   esac
438   #
439   # 3) Priority
440   #
441   PATTERN=">Priority:"
442   PRIORITY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
443   case "$PRIORITY" in
444     ""|low|medium|high) CNT=`expr $CNT + 1` ;;
445     *)  echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
446   esac
447   #
448   # 4) Category
449   #
450   PATTERN=">Category:"
451   CATEGORY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
452   FOUND=
453   for C in $CATEGORIES
454   do
455     if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
456   done
457   if [ -n "$FOUND" ]; then
458     CNT=`expr $CNT + 1` 
459   else
460     if [ -z "$CATEGORY" ]; then
461       echo "$COMMAND: you must include a Category: field in your report."
462     else
463       echo "$COMMAND: \`$CATEGORY' is not a known category."
464     fi
465   fi
466   #
467   # 5) Class
468   #
469   PATTERN=">Class:"
470   CLASS=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
471   case "$CLASS" in
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'."
474   esac
475   #
476   # 6) Check that synopsis is not empty
477   #
478   if grep "^>Synopsis:[         ]*${SYNOPSIS_C}\$" $TEMP > /dev/null
479   then
480     echo "$COMMAND: Synopsis must not be empty."
481   else
482     CNT=`expr $CNT + 1`
483   fi
484
485   [ $CNT -lt 6 -a -z "$BATCH" ] && 
486     echo "Errors were found with the problem report."
487
488   while true; do
489     if [ -z "$BATCH" ]; then
490       $ECHON1 "s)end, e)dit or a)bort? $ECHON2"
491       read input
492     else
493       if [ $CNT -eq 6 ]; then
494         input=s
495       else
496         input=a
497       fi
498     fi
499     case "$input" in
500       a*)
501         if [ -z "$BATCH" ]; then
502           BAD=`mktemp -t pbad`
503           echo "$COMMAND: the problem report remains in $BAD and is not sent."
504           mv $TEMP $BAD
505         else
506           echo "$COMMAND: the problem report is not sent."
507         fi
508         xs=1; exit
509         ;;
510       e*)
511         eval $EDIT $TEMP
512         continue 2
513         ;;
514       s*)
515         if [ $CNT -lt 6 ]; then
516           if [ -z "$BATCH" ]; then
517             echo "But there are still errors in the problem report!"
518             continue 2
519           else
520             echo "Errors found in PR"
521             exit 1
522           fi
523         fi
524         break 2
525         ;;
526     esac
527   done
528 done
529
530 #
531 # Remove the subject field if one is already there.  There's no reason
532 # for it to be any different than the synopsis.
533 #
534 if grep '^Subject:' $TEMP > /dev/null
535 then
536   ed -s $TEMP << __EOF__
537 /^Subject:/d
538 w
539 q
540 __EOF__
541 fi
542
543 #
544 # Add the subject field with the value of $SYNOPSIS.  We use the To:
545 # field as an anchor, which had better be there.
546 #
547 SYNOPSIS=`grep '^>Synopsis:' $TEMP | sed -e 's/^>Synopsis:[     ]*//' |
548     sed -e "s;$SYNOPSIS_C;;"`
549 ed -s $TEMP << __EOF__
550 /^To:/a
551 Subject: $SYNOPSIS
552 .
553 w
554 q
555 __EOF__
556
557 #
558 #       Remove comments and send the problem report
559 #       (we have to use patterns, where the comment contains regex chars)
560 #
561 # /^>Originator:/s;$ORIGINATOR;;
562 sed  -e "
563 /^SEND-PR:/d
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;;
570 /^>Class:/s;<.*>;;
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;;
576 " $TEMP > $REF
577
578 if $MAIL_AGENT < $REF; then
579   echo "$COMMAND: problem report sent"
580   xs=0; exit
581 else
582   echo "$COMMAND: mysterious mail failure."
583   if [ -z "$BATCH" ]; then
584     BAD=`mktemp -t pbad`
585     echo "$COMMAND: the problem report remains in $BAD and is not sent."
586     mv $TEMP $BAD
587   else
588     echo "$COMMAND: the problem report is not sent."
589   fi
590   xs=1; exit
591 fi