Initial bulk commit for "Git on MSys"
[msysgit/historical-msysgit.git] / bin / cvsbug
blob51226d842625895c1dfc34ae873c89f55f191982
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@ide.com).
7 # This file is part of GNU GNATS.
8 # Modified by Berliner for CVS.
10 # GNU GNATS is free software; you can redistribute it and/or modify
11 # it under the terms of the GNU General Public License as published by
12 # the Free Software Foundation; either version 2, or (at your option)
13 # any later version.
15 # GNU GNATS is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 # GNU General Public License for more details.
20 # The version of this send-pr.
21 VERSION=3.2
23 # The submitter-id for your site.
24 SUBMITTER=net
26 ## # Where the GNATS directory lives, if at all.
27 ## [ -z "$GNATS_ROOT" ] &&
28 ## GNATS_ROOT=/usr/local/lib/gnats/gnats-db
30 # The default mail address for PR submissions.
31 GNATS_ADDR=bug-cvs@gnu.org
33 ## # Where the gnats category tree lives.
34 ## DATADIR=/usr/local/lib
36 ## # If we've been moved around, try using GCC_EXEC_PREFIX.
37 ## [ ! -d $DATADIR/gnats -a -d "$GCC_EXEC_PREFIX" ] && DATADIR=${GCC_EXEC_PREFIX}..
39 # The default release for this host.
40 DEFAULT_RELEASE="cvs-1.11"
42 # The default organization.
43 DEFAULT_ORGANIZATION="net"
45 ## # The default site to look for.
46 ## GNATS_SITE=unknown
48 ## # Newer config information?
49 ## [ -f ${GNATS_ROOT}/gnats-adm/config ] && . ${GNATS_ROOT}/gnats-adm/config
51 # What mailer to use. This must come after the config file, since it is
52 # host-dependent.
53 if [ -f /usr/sbin/sendmail ]; then
54 MAIL_AGENT="/usr/sbin/sendmail -oi -t"
55 else
56 MAIL_AGENT="/usr/lib/sendmail -oi -t"
58 MAILER=`echo $MAIL_AGENT | sed -e 's, .*,,'`
59 if [ ! -f "$MAILER" ] ; then
60 echo "$COMMAND: Cannot file mail program \"$MAILER\"."
61 echo "$COMMAND: Please fix the MAIL_AGENT entry in the $COMMAND file."
62 exit 1
65 if test "`echo -n foo`" = foo ; then
66 ECHON=bsd
67 elif test "`echo 'foo\c'`" = foo ; then
68 ECHON=sysv
69 else
70 ECHON=none
73 if [ $ECHON = bsd ] ; then
74 ECHON1="echo -n"
75 ECHON2=
76 elif [ $ECHON = sysv ] ; then
77 ECHON1=echo
78 ECHON2='\c'
79 else
80 ECHON1=echo
81 ECHON2=
84 #\f
86 [ -z "$TMPDIR" ] && TMPDIR=/tmp
88 TEMP=$TMPDIR/p$$
89 BAD=$TMPDIR/pbad$$
90 REF=$TMPDIR/pf$$
92 if [ -z "$LOGNAME" -a -n "$USER" ]; then
93 LOGNAME=$USER
96 FROM="$LOGNAME"
97 REPLY_TO="$LOGNAME"
99 # Find out the name of the originator of this PR.
100 if [ -n "$NAME" ]; then
101 ORIGINATOR="$NAME"
102 elif [ -f $HOME/.fullname ]; then
103 ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
104 elif [ -f /bin/domainname ]; then
105 if [ "`/bin/domainname`" != "" -a -f /usr/bin/ypcat ]; then
106 # Must use temp file due to incompatibilities in quoting behavior
107 # and to protect shell metacharacters in the expansion of $LOGNAME
108 /usr/bin/ypcat passwd 2>/dev/null | cat - /etc/passwd | grep "^$LOGNAME:" |
109 cut -f5 -d':' | sed -e 's/,.*//' > $TEMP
110 ORIGINATOR="`cat $TEMP`"
111 rm -f $TEMP
115 if [ "$ORIGINATOR" = "" ]; then
116 grep "^$LOGNAME:" /etc/passwd | cut -f5 -d':' | sed -e 's/,.*//' > $TEMP
117 ORIGINATOR="`cat $TEMP`"
118 rm -f $TEMP
121 if [ -n "$ORGANIZATION" ]; then
122 if [ -f "$ORGANIZATION" ]; then
123 ORGANIZATION="`cat $ORGANIZATION`"
125 else
126 if [ -n "$DEFAULT_ORGANIZATION" ]; then
127 ORGANIZATION="$DEFAULT_ORGANIZATION"
128 elif [ -f $HOME/.organization ]; then
129 ORGANIZATION="`cat $HOME/.organization`"
130 elif [ -f $HOME/.signature ]; then
131 ORGANIZATION="`cat $HOME/.signature`"
135 # If they don't have a preferred editor set, then use
136 if [ -z "$VISUAL" ]; then
137 if [ -z "$EDITOR" ]; then
138 EDIT=vi
139 else
140 EDIT="$EDITOR"
142 else
143 EDIT="$VISUAL"
146 # Find out some information.
147 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
148 ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
149 ARCH=`[ -f /bin/arch ] && /bin/arch`
150 MACHINE=`[ -f /bin/machine ] && /bin/machine`
152 COMMAND=`echo $0 | sed -e 's,.*/,,'`
153 ## USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [--request-id]
154 USAGE="Usage: $COMMAND [-PVL]
155 [--version]"
156 REMOVE=
157 BATCH=
159 while [ $# -gt 0 ]; do
160 case "$1" in
161 -r) ;; # Ignore for backward compat.
162 ## -t | --to) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
163 ## shift ; GNATS_ADDR="$1"
164 ## EXPLICIT_GNATS_ADDR=true
165 ## ;;
166 ## -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
167 ## shift ; IN_FILE="$1"
168 ## if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
169 ## echo "$COMMAND: cannot read $IN_FILE"
170 ## exit 1
171 ## fi
172 ## ;;
173 -b | --batch) BATCH=true ;;
174 -p | -P | --print) PRINT=true ;;
175 -L | --list) FORMAT=norm ;;
176 -l | -CL | --lisp) FORMAT=lisp ;;
177 ## --request-id) REQUEST_ID=true ;;
178 -h | --help) echo "$USAGE"; exit 0 ;;
179 -V | --version) echo "$VERSION"; exit 0 ;;
180 -*) echo "$USAGE" ; exit 1 ;;
181 *) echo "$USAGE" ; exit 1
182 ## if [ -z "$USER_GNATS_SITE" ]; then
183 ## if [ ! -r "$DATADIR/gnats/$1" ]; then
184 ## echo "$COMMAND: the GNATS site $1 does not have a categories list."
185 ## exit 1
186 ## else
187 ## # The site name is the alias they'll have to have created.
188 ## USER_GNATS_SITE=$1
189 ## fi
190 ## else
191 ## echo "$USAGE" ; exit 1
192 ## fi
194 esac
195 shift
196 done
198 if [ -n "$USER_GNATS_SITE" ]; then
199 GNATS_SITE=$USER_GNATS_SITE
200 GNATS_ADDR=$USER_GNATS_SITE-gnats
203 if [ "$SUBMITTER" = "unknown" -a -z "$REQUEST_ID" -a -z "$IN_FILE" ]; then
204 cat << '__EOF__'
205 It seems that send-pr is not installed with your unique submitter-id.
206 You need to run
208 install-sid YOUR-SID
210 where YOUR-SID is the identification code you received with `send-pr'.
211 `send-pr' will automatically insert this value into the template field
212 `>Submitter-Id'. If you've downloaded `send-pr' from the Net, use `net'
213 for this value. If you do not know your id, run `send-pr --request-id' to
214 get one from your support site.
215 __EOF__
216 exit 1
219 ## if [ -r "$DATADIR/gnats/$GNATS_SITE" ]; then
220 ## CATEGORIES=`grep -v '^#' $DATADIR/gnats/$GNATS_SITE | sort`
221 ## else
222 ## echo "$COMMAND: could not read $DATADIR/gnats/$GNATS_SITE for categories list."
223 ## exit 1
224 ## fi
225 CATEGORIES="contrib cvs doc pcl-cvs portability"
227 if [ -z "$CATEGORIES" ]; then
228 echo "$COMMAND: the categories list for $GNATS_SITE was empty!"
229 exit 1
232 case "$FORMAT" in
233 lisp) echo "$CATEGORIES" | \
234 awk 'BEGIN {printf "( "}
235 {printf "(\"%s\") ",$0}
236 END {printf ")\n"}'
237 exit 0
239 norm) l=`echo "$CATEGORIES" | \
240 awk 'BEGIN {max = 0; }
241 { if (length($0) > max) { max = length($0); } }
242 END {print max + 1;}'`
243 c=`expr 70 / $l`
244 if [ $c -eq 0 ]; then c=1; fi
245 echo "$CATEGORIES" | \
246 awk 'BEGIN {print "Known categories:"; i = 0 }
247 { printf ("%-'$l'.'$l's", $0); if ((++i % '$c') == 0) { print "" } }
248 END { print ""; }'
249 exit 0
251 esac
253 ORIGINATOR_C='<name of the PR author (one line)>'
254 ORGANIZATION_C='<organization of PR author (multiple lines)>'
255 CONFIDENTIAL_C='<[ yes | no ] (one line)>'
256 SYNOPSIS_C='<synopsis of the problem (one line)>'
257 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
258 PRIORITY_C='<[ low | medium | high ] (one line)>'
259 CATEGORY_C='<name of the product (one line)>'
260 CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
261 RELEASE_C='<release number or tag (one line)>'
262 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
263 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
264 HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
265 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
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 'echo "$COMMAND: Aborting ..."; rm -f $REF $TEMP; 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
278 else
279 cat > $TEMP
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
289 else
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
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 else
304 for file in $TEMP $REF ; do
305 cat > $file << '__EOF__'
306 SEND-PR: -*- send-pr -*-
307 SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
308 SEND-PR: will all comments (text enclosed in `<' and `>').
309 SEND-PR:
310 SEND-PR: Choose from the following categories:
311 SEND-PR:
312 __EOF__
314 # Format the categories so they fit onto lines.
315 l=`echo "$CATEGORIES" | \
316 awk 'BEGIN {max = 0; }
317 { if (length($0) > max) { max = length($0); } }
318 END {print max + 1;}'`
319 c=`expr 61 / $l`
320 if [ $c -eq 0 ]; then c=1; fi
321 echo "$CATEGORIES" | \
322 awk 'BEGIN {printf "SEND-PR: "; i = 0 }
323 { printf ("%-'$l'.'$l's", $0);
324 if ((++i % '$c') == 0) { printf "\nSEND-PR: " } }
325 END { printf "\nSEND-PR:\n"; }' >> $file
327 cat >> $file << __EOF__
328 To: $GNATS_ADDR
329 Subject:
330 From: $FROM
331 Reply-To: $REPLY_TO
332 X-send-pr-version: $VERSION
335 >Submitter-Id: $SUBMITTER
336 >Originator: $ORIGINATOR
337 >Organization:
338 ${ORGANIZATION-$ORGANIZATION_C}
339 >Confidential: $CONFIDENTIAL_C
340 >Synopsis: $SYNOPSIS_C
341 >Severity: $SEVERITY_C
342 >Priority: $PRIORITY_C
343 >Category: $CATEGORY_C
344 >Class: $CLASS_C
345 >Release: ${DEFAULT_RELEASE-$RELEASE_C}
346 >Environment:
347 $ENVIRONMENT_C
348 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
349 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
350 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
351 >Description:
352 $DESCRIPTION_C
353 >How-To-Repeat:
354 $HOW_TO_REPEAT_C
355 >Fix:
356 $FIX_C
357 __EOF__
358 done
361 if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
362 cat $TEMP
363 xs=0; exit
366 chmod u+w $TEMP
367 if [ -z "$REQUEST_ID" ]; then
368 eval $EDIT $TEMP
369 else
370 ed -s $TEMP << '__EOF__'
371 /^Subject/s/^Subject:.*/Subject: request for a customer id/
372 /^>Category/s/^>Category:.*/>Category: send-pr/
375 __EOF__
378 if cmp -s $REF $TEMP ; then
379 echo "$COMMAND: problem report not filled out, therefore not sent"
380 xs=1; exit
385 # Check the enumeration fields
387 # This is a "sed-subroutine" with one keyword parameter
388 # (with workaround for Sun sed bug)
390 SED_CMD='
391 /$PATTERN/{
392 s|||
393 s|<.*>||
394 s|^[ ]*||
395 s|[ ]*$||
401 while [ -z "$REQUEST_ID" ]; do
402 CNT=0
404 # 1) Confidential
406 PATTERN=">Confidential:"
407 CONFIDENTIAL=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
408 case "$CONFIDENTIAL" in
409 ""|yes|no) CNT=`expr $CNT + 1` ;;
410 *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
411 esac
413 # 2) Severity
415 PATTERN=">Severity:"
416 SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
417 case "$SEVERITY" in
418 ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
419 *) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
420 esac
422 # 3) Priority
424 PATTERN=">Priority:"
425 PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
426 case "$PRIORITY" in
427 ""|low|medium|high) CNT=`expr $CNT + 1` ;;
428 *) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
429 esac
431 # 4) Category
433 PATTERN=">Category:"
434 CATEGORY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
435 FOUND=
436 for C in $CATEGORIES
438 if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
439 done
440 if [ -n "$FOUND" ]; then
441 CNT=`expr $CNT + 1`
442 else
443 if [ -z "$CATEGORY" ]; then
444 echo "$COMMAND: you must include a Category: field in your report."
445 else
446 echo "$COMMAND: \`$CATEGORY' is not a known category."
450 # 5) Class
452 PATTERN=">Class:"
453 CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
454 case "$CLASS" in
455 ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
456 *) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
457 esac
459 [ $CNT -lt 5 -a -z "$BATCH" ] &&
460 echo "Errors were found with the problem report."
462 while true; do
463 if [ -z "$BATCH" ]; then
464 $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
465 read input
466 else
467 if [ $CNT -eq 5 ]; then
468 input=s
469 else
470 input=a
473 case "$input" in
475 if [ -z "$BATCH" ]; then
476 echo "$COMMAND: the problem report remains in $BAD and is not sent."
477 mv $TEMP $BAD
478 else
479 echo "$COMMAND: the problem report is not sent."
481 xs=1; exit
484 eval $EDIT $TEMP
485 continue 2
488 break 2
490 esac
491 done
492 done
494 # Remove comments and send the problem report
495 # (we have to use patterns, where the comment contains regex chars)
497 # /^>Originator:/s;$ORIGINATOR;;
498 sed -e "
499 /^SEND-PR:/d
500 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
501 /^>Confidential:/s;<.*>;;
502 /^>Synopsis:/s;$SYNOPSIS_C;;
503 /^>Severity:/s;<.*>;;
504 /^>Priority:/s;<.*>;;
505 /^>Category:/s;$CATEGORY_C;;
506 /^>Class:/s;<.*>;;
507 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
508 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
509 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
510 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
511 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
512 " $TEMP > $REF
514 if $MAIL_AGENT < $REF; then
515 echo "$COMMAND: problem report sent"
516 xs=0; exit
517 else
518 echo "$COMMAND: mysterious mail failure."
519 if [ -z "$BATCH" ]; then
520 echo "$COMMAND: the problem report remains in $BAD and is not sent."
521 mv $REF $BAD
522 else
523 echo "$COMMAND: the problem report is not sent."
525 xs=1; exit