Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.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: 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 $
25
26 # The version of this send-pr.
27 VERSION=3.113
28
29 # The submitter-id for your site.
30 # "current-users" is the only allowable value for FreeBSD.
31 SUBMITTER="current-users"
32
33 # Where the GNATS directory lives, if at all.
34 [ -z "$GNATS_ROOT" ] && 
35 GNATS_ROOT=
36
37 # The default mail address for PR submissions. 
38 GNATS_ADDR=FreeBSD-gnats-submit@freebsd.org
39
40 # Where the gnats category tree lives.
41 DATADIR=@DATADIR@
42
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"
45
46 # The default release for this host.
47 DEFAULT_RELEASE="@DEFAULT_RELEASE@"
48
49 # The default organization.
50 DEFAULT_ORGANIZATION=
51
52 # The default site to look for.
53 GNATS_SITE=freefall
54
55 # Newer config information?
56 [ -f ${GNATS_ROOT}/gnats-adm/config ] && . ${GNATS_ROOT}/gnats-adm/config
57
58 # What mailer to use.  This must come after the config file, since it is
59 # host-dependent.
60 MAIL_AGENT="${MAIL_AGENT:-/usr/sbin/sendmail -oi -t}"
61
62 # Path to pw(8)
63 PW="/usr/sbin/pw"
64
65 ECHON=bsd
66
67 if [ $ECHON = bsd ] ; then
68   ECHON1="echo -n"
69   ECHON2=
70 elif [ $ECHON = sysv ] ; then
71   ECHON1=echo
72   ECHON2='\c'
73 else
74   ECHON1=echo
75   ECHON2=
76 fi
77
78 #\f
79
80 # find a user name
81 if [ "$LOGNAME" = "" ]; then
82         if [ "$USER" != "" ]; then
83                 LOGNAME="$USER"
84         else
85                 LOGNAME="UNKNOWN"
86         fi
87 fi
88
89 # Find out the name of the originator of this PR.
90 if [ -n "$NAME" ]; then
91   ORIGINATOR="$NAME"
92 elif [ -f $HOME/.fullname ]; then
93   ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
94 else
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`"
100   rm -f $PTEMP
101 fi
102
103 FROM="$ORIGINATOR <$LOGNAME>"
104 REPLY_TO="$ORIGINATOR <${REPLY_TO:-${REPLYTO:-$LOGNAME}}>"
105
106 if [ -n "$ORGANIZATION" ]; then
107   if [ -f "$ORGANIZATION" ]; then
108     ORGANIZATION="`cat $ORGANIZATION`"
109   fi
110 else
111   if [ -n "$DEFAULT_ORGANIZATION" ]; then
112     ORGANIZATION="$DEFAULT_ORGANIZATION"
113   elif [ -f $HOME/.organization ]; then
114     ORGANIZATION="`cat $HOME/.organization`"
115   fi
116 fi
117
118 # If they don't have a preferred editor set, then use
119 if [ -z "$VISUAL" ]; then
120   if [ -z "$EDITOR" ]; then
121     EDIT=vi
122   else
123     EDIT="$EDITOR"
124   fi
125 else
126   EDIT="$VISUAL"
127 fi
128
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`
134
135 COMMAND=`echo $0 | sed -e 's,.*/,,'`
136 USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [-s severity]
137        [-c address] [-a file] [--version]"
138 REMOVE=
139 BATCH=
140 CC=
141 SEVERITY_C=
142
143 while [ $# -gt 0 ]; do
144   case "$1" in
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
149         ;;
150     -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
151         shift ; IN_FILE="$1"
152         if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
153           echo "$COMMAND: cannot read $IN_FILE"
154           exit 1
155         fi
156         ;;
157     -b | --batch) BATCH=true ;;
158     -c | --cc) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
159         shift ; CC="$1"
160         ;;
161     -s | --severity) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
162         shift ; SEVERITY_C="$1"
163         ;;
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; 
171         fi
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 ---
177 `cat \"$2\"`
178 --- $PRETTY_NAME ends here ---
179 "
180           else
181             ATTACHED_FILES="$ATTACHED_FILES
182 `uuencode \"$PRETTY_NAME\" < \"$2\"`
183 "
184           fi
185           shift;
186         fi;
187         ;;
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."
192            exit 1
193          else
194            # The site name is the alias they'll have to have created.
195            USER_GNATS_SITE=$1
196          fi
197        else
198          echo "$USAGE" ; exit 1
199        fi
200        ;;
201  esac
202  shift
203 done
204
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
208 fi
209
210 if [ "$SUBMITTER" = "unknown" -a -z "$IN_FILE" ]; then
211   SUBMITTER="current-users"
212 fi
213
214 if [ -r "$DATADIR/gnats/$GNATS_SITE" ]; then
215   CATEGORIES=`grep -v '^#' $DATADIR/gnats/$GNATS_SITE | sort`
216 else
217   echo "$COMMAND: could not read $DATADIR/gnats/$GNATS_SITE for categories list."
218   exit 1
219 fi
220
221 if [ -z "$CATEGORIES" ]; then
222   echo "$COMMAND: the categories list for $GNATS_SITE was empty!"
223   exit 1
224 fi
225
226 case "$FORMAT" in
227   lisp) echo "$CATEGORIES" | \
228         awk 'BEGIN {printf "( "} {printf "(\"%s\") ",$0} END {printf ")\n"}'
229         exit 0
230         ;;
231   norm) l=`echo "$CATEGORIES" | \
232         awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
233              END {print max + 1;}'`
234         c=`expr 70 / $l`
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 "" } }
239             END { print ""; }'
240         exit 0
241         ;;
242 esac
243
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)>'
250 fi
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)>'
259
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)
264 xs=0
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
267
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
274     else
275       cat > $TEMP
276     fi
277   else
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
281     else
282       cat $IN_FILE > $TEMP
283     fi
284   fi
285 else
286
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"
291       sleep 1
292       PRINT_INTERN=bad_prform
293     fi
294   fi
295
296   if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
297     cp $PR_FORM $TEMP || 
298       ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
299     [ -n "$ATTACHED_FILES" ] && echo "$ATTACHED_FILES" >> $TEMP
300   else
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 `>').
306 SEND-PR:
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
310 SEND-PR:
311 SEND-PR: Note that the Synopsis field is mandatory.
312 SEND-PR:
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.
316 SEND-PR:
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.
320 SEND-PR:
321 SEND-PR: For sensitive security issues, consider contacting the FreeBSD
322 SEND-PR: security officer team (security-officer@freebsd.org) directly.
323 SEND-PR:
324 SEND-PR: Choose from the following categories:
325 SEND-PR:
326 __EOF__
327
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;}'`
332         c=`expr 61 / $l`
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
339
340       cat >> $file << __EOF__
341 To: $GNATS_ADDR
342 From: $FROM
343 Reply-To: $REPLY_TO
344 Cc: $CC
345 X-send-pr-version: $VERSION
346 X-GNATS-Notify: 
347
348
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
357 >Class:         $CLASS_C
358 >Release:       ${DEFAULT_RELEASE-$RELEASE_C}
359 >Environment:
360 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
361 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
362 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
363         $ENVIRONMENT_C
364 >Description:
365         $DESCRIPTION_C
366 >How-To-Repeat:
367         $HOW_TO_REPEAT_C
368 >Fix:
369
370         $FIX_C
371 $ATTACHED_FILES
372
373 __EOF__
374
375     done
376   fi
377
378   if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
379     cat $TEMP
380     xs=0; exit
381   fi
382
383   chmod u+w $TEMP
384   eval $EDIT $TEMP
385
386   if cmp -s $REF $TEMP ; then
387     echo "$COMMAND: problem report not filled out, therefore not sent"
388     xs=1; exit
389   fi
390 fi
391
392 #\f
393 #       Check the enumeration fields
394
395 # This is a "sed-subroutine" with one keyword parameter 
396 # (with workaround for Sun sed bug)
397 #
398 SED_CMD='{
399 s|||
400 s|<.*>||
401 s|^[    ]*||
402 s|[     ]*$||
403 p
404 q
405 }'
406
407
408 while true; do
409   CNT=0
410
411   # 1) Confidential
412   #
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'." ;;
418   esac
419   #
420   # 2) Severity
421   #
422   PATTERN=">Severity:"
423   SEVERITY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
424   case "$SEVERITY" in
425     ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
426     *)  echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
427   esac
428   #
429   # 3) Priority
430   #
431   PATTERN=">Priority:"
432   PRIORITY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
433   case "$PRIORITY" in
434     ""|low|medium|high) CNT=`expr $CNT + 1` ;;
435     *)  echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
436   esac
437   #
438   # 4) Category
439   #
440   PATTERN=">Category:"
441   CATEGORY=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
442   FOUND=
443   for C in $CATEGORIES
444   do
445     if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
446   done
447   if [ -n "$FOUND" ]; then
448     CNT=`expr $CNT + 1` 
449   else
450     if [ -z "$CATEGORY" ]; then
451       echo "$COMMAND: you must include a Category: field in your report."
452     else
453       echo "$COMMAND: \`$CATEGORY' is not a known category."
454     fi
455   fi
456   #
457   # 5) Class
458   #
459   PATTERN=">Class:"
460   CLASS=`eval sed -n -e "\"/$PATTERN/$SED_CMD\"" $TEMP`
461   case "$CLASS" in
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'."
464   esac
465   #
466   # 6) Check that synopsis is not empty
467   #
468   if grep "^>Synopsis:[         ]*${SYNOPSIS_C}\$" $TEMP > /dev/null
469   then
470     echo "$COMMAND: Synopsis must not be empty."
471   else
472     CNT=`expr $CNT + 1`
473   fi
474
475   [ $CNT -lt 6 -a -z "$BATCH" ] && 
476     echo "Errors were found with the problem report."
477
478   while true; do
479     if [ -z "$BATCH" ]; then
480       $ECHON1 "s)end, e)dit or a)bort? $ECHON2"
481       read input
482     else
483       if [ $CNT -eq 6 ]; then
484         input=s
485       else
486         input=a
487       fi
488     fi
489     case "$input" in
490       a*)
491         if [ -z "$BATCH" ]; then
492           BAD=`mktemp -t pbad`
493           echo "$COMMAND: the problem report remains in $BAD and is not sent."
494           mv $TEMP $BAD
495         else
496           echo "$COMMAND: the problem report is not sent."
497         fi
498         xs=1; exit
499         ;;
500       e*)
501         eval $EDIT $TEMP
502         continue 2
503         ;;
504       s*)
505         break 2
506         ;;
507     esac
508   done
509 done
510
511 #
512 # Remove the subject field if one is already there.  There's no reason
513 # for it to be any different than the synopsis.
514 #
515 if grep '^Subject:' $TEMP > /dev/null
516 then
517   ed -s $TEMP << __EOF__
518 /^Subject:/d
519 w
520 q
521 __EOF__
522 fi
523
524 #
525 # Add the subject field with the value of $SYNOPSIS.  We use the To:
526 # field as an anchor, which had better be there.
527 #
528 SYNOPSIS=`grep '^>Synopsis:' $TEMP | sed -e 's/^>Synopsis:[     ]*//' |
529     sed -e "s;$SYNOPSIS_C;;"`
530 ed -s $TEMP << __EOF__
531 /^To:/a
532 Subject: $SYNOPSIS
533 .
534 w
535 q
536 __EOF__
537
538 #
539 #       Remove comments and send the problem report
540 #       (we have to use patterns, where the comment contains regex chars)
541 #
542 # /^>Originator:/s;$ORIGINATOR;;
543 sed  -e "
544 /^SEND-PR:/d
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;;
551 /^>Class:/s;<.*>;;
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;;
557 " $TEMP > $REF
558
559 if $MAIL_AGENT < $REF; then
560   echo "$COMMAND: problem report sent"
561   xs=0; exit
562 else
563   echo "$COMMAND: mysterious mail failure."
564   if [ -z "$BATCH" ]; then
565     BAD=`mktemp -t pbad`
566     echo "$COMMAND: the problem report remains in $BAD and is not sent."
567     mv $REF $BAD
568   else
569     echo "$COMMAND: the problem report is not sent."
570   fi
571   xs=1; exit
572 fi