Expand PMF_FN_* macros.
[netbsd-mini2440.git] / gnu / usr.bin / send-pr / send-pr.sh
blob659bfed2f99165278c9a909bcbb0849db8e91da0
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).
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)
12 # any later version.
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 # The version of this send-pr.
24 VERSION=xVERSIONx
26 # The submitter-id for your site.
27 SUBMITTER=xSUBMITTERx
29 # Where the GNATS directory lives, if at all.
30 [ -z "$GNATS_ROOT" ] &&
31 GNATS_ROOT=xGNATS_ROOTx
33 # The default mail address for PR submissions.
34 GNATS_ADDR=xGNATS_ADDRx
36 # Where the gnats category tree lives.
37 DATADIR=xDATADIRx
39 # If we've been moved around, try using GCC_EXEC_PREFIX.
40 [ ! -d $DATADIR/gnats -a -d "$GCC_EXEC_PREFIX" ] &&
41 DATADIR=${GCC_EXEC_PREFIX}../../../lib
43 # The default release for this host.
44 DEFAULT_RELEASE="xDEFAULT_RELEASEx"
46 # The default organization.
47 DEFAULT_ORGANIZATION="xDEFAULT_ORGANIZATIONx"
49 # The default site to look for.
50 GNATS_SITE=xGNATS_SITEx
52 # Newer config information?
53 [ -f ${GNATS_ROOT}/gnats-adm/config ] && . ${GNATS_ROOT}/gnats-adm/config
55 # What mailer to use. This must come after the config file, since it is
56 # host-dependent.
57 MAIL_AGENT="xMAIL_AGENTx"
59 # How to read the passwd database.
60 PASSWD="xPASSWDx"
62 ECHON=xECHONx
64 if [ $ECHON = bsd ] ; then
65 ECHON1="echo -n"
66 ECHON2=
67 elif [ $ECHON = sysv ] ; then
68 ECHON1=echo
69 ECHON2='\c'
70 else
71 ECHON1=echo
72 ECHON2=
75 #\f
77 if [ -z "$TMPDIR" ]; then
78 TMPDIR=/tmp
79 else
80 if [ "`echo $TMPDIR | grep '/$'`" != "" ]; then
81 TMPDIR="`echo $TMPDIR | sed -e 's,/$,,'`"
85 TEMP=`mktemp -t p` || exit 1
86 BAD=`mktemp -t pbad` || exit 1
87 REF=`mktemp -t pf` || exit 1
89 # find a user name
90 if [ "$LOGNAME" = "" ]; then
91 if [ "$USER" != "" ]; then
92 LOGNAME="$USER"
93 else
94 LOGNAME="UNKNOWN"
98 FROM="$LOGNAME"
99 if [ -z "$REPLYTO" ]; then
100 REPLYTO="$LOGNAME"
103 # Find out the name of the originator of this PR.
104 if [ -n "$NAME" ]; then
105 ORIGINATOR="$NAME"
106 elif [ -f $HOME/.fullname ]; then
107 ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
108 else
109 ORIGINATOR=`$PASSWD | sed -e /"^${LOGNAME}:"/'{s/^[^:]*:[^:]*:[^:]*:[^:]*:\([^,:;]*\).*$/\1/' -e q -e } -e d`
110 case "$ORIGINATOR" in
111 *'&'*)
112 AMP=`echo $LOGNAME | tr '[a-z]' '[A-Z]'`
113 AMP=`echo $AMP $LOGNAME | sed 's/^\(.\)[^ ]* ./\1/'`
114 ORIGINATOR=`echo "$ORIGINATOR" | sed "s/&/$AMP/"`
116 esac
119 if [ -n "$ORGANIZATION" ]; then
120 if [ -f "$ORGANIZATION" ]; then
121 ORGANIZATION="`cat $ORGANIZATION`"
123 else
124 if [ -n "$DEFAULT_ORGANIZATION" ]; then
125 ORGANIZATION="$DEFAULT_ORGANIZATION"
126 elif [ -f $HOME/.organization ]; then
127 ORGANIZATION="`cat $HOME/.organization`"
128 elif [ -f $HOME/.signature ]; then
129 ORGANIZATION="`cat $HOME/.signature`"
133 # If they don't have a preferred editor set, then use
134 if [ -z "$VISUAL" ]; then
135 if [ -z "$EDITOR" ]; then
136 EDIT=vi
137 else
138 EDIT="$EDITOR"
140 else
141 EDIT="$VISUAL"
144 # Find out some information.
145 if [ -f /bin/uname ]; then
146 UNAME="/bin/uname"
147 elif [ -f /usr/bin/uname ]; then
148 UNAME="/usr/bin/uname"
149 else
150 UNAME="echo"
152 SYSTEM=`$UNAME -a`
153 ARCH=`$UNAME -p`
154 if [ -z "$ARCH" -a -f /bin/arch ]; then
155 ARCH=`/bin/arch`
157 MACHINE=`$UNAME -m`
158 if [ -z "$ARCH" -a -f /bin/machine ]; then
159 ARCH=`/bin/arch`
162 COMMAND=`echo $0 | sed -e 's,.*/,,'`
163 USAGE="Usage: $COMMAND [-PVL] [-t address] [-f filename] [--request-id]
164 [--version]"
165 REMOVE=
166 BATCH=
168 while [ $# -gt 0 ]; do
169 case "$1" in
170 -r) ;; # Ignore for backward compat.
171 -t | --to) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
172 shift ; GNATS_ADDR="$1"
173 EXPLICIT_GNATS_ADDR=true
175 -f | --file) if [ $# -eq 1 ]; then echo "$USAGE"; exit 1; fi
176 shift ; IN_FILE="$1"
177 if [ "$IN_FILE" != "-" -a ! -r "$IN_FILE" ]; then
178 echo "$COMMAND: cannot read $IN_FILE"
179 exit 1
182 -b | --batch) BATCH=true ;;
183 -p | -P | --print) PRINT=true ;;
184 -L | --list) FORMAT=norm ;;
185 -l | -CL | --lisp) FORMAT=lisp ;;
186 --request-id) REQUEST_ID=true ;;
187 -h | --help) echo "$USAGE"; exit 0 ;;
188 -V | --version) echo "$VERSION"; exit 0 ;;
189 -*) echo "$USAGE" ; exit 1 ;;
190 *) if [ -z "$USER_GNATS_SITE" ]; then
191 if [ ! -r "$DATADIR/gnats/$1" ]; then
192 echo "$COMMAND: the GNATS site $1 does not have a categories list."
193 exit 1
194 else
195 # The site name is the alias they'll have to have created.
196 USER_GNATS_SITE=$1
198 else
199 echo "$USAGE" ; exit 1
202 esac
203 shift
204 done
206 if [ -n "$USER_GNATS_SITE" ] && [ "$USER_GNATS_SITE" != "$GNATS_SITE" ]; then
207 GNATS_SITE=$USER_GNATS_SITE
208 GNATS_ADDR=$USER_GNATS_SITE-gnats
211 if [ "$SUBMITTER" = "unknown" -a -z "$REQUEST_ID" -a -z "$IN_FILE" ]; then
212 cat << '__EOF__'
213 It seems that send-pr is not installed with your unique submitter-id.
214 You need to run
216 install-sid YOUR-SID
218 where YOUR-SID is the identification code you received with `send-pr'.
219 `send-pr' will automatically insert this value into the template field
220 `>Submitter-Id'. If you've downloaded `send-pr' from the Net, use `net'
221 for this value. If you do not know your id, run `send-pr --request-id' to
222 get one from your support site.
223 __EOF__
224 exit 1
227 if [ -r "$DATADIR/gnats/$GNATS_SITE" ]; then
228 CATEGORIES=`grep -v '^#' $DATADIR/gnats/$GNATS_SITE | sort`
229 else
230 echo "$COMMAND: could not read $DATADIR/gnats/$GNATS_SITE for categories list."
231 exit 1
234 if [ -z "$CATEGORIES" ]; then
235 echo "$COMMAND: the categories list for $GNATS_SITE was empty!"
236 exit 1
239 case "$FORMAT" in
240 lisp) echo "$CATEGORIES" | \
241 awk 'BEGIN {printf "( "} {printf "(\"%s\") ",$0} END {printf ")\n"}'
242 exit 0
244 norm) l=`echo "$CATEGORIES" | \
245 awk 'BEGIN {max = 0; } { if (length($0) > max) { max = length($0); } }
246 END {print max + 1;}'`
247 c=`expr 70 / $l`
248 if [ $c -eq 0 ]; then c=1; fi
249 echo "$CATEGORIES" | \
250 awk 'BEGIN {print "Known categories:"; i = 0 }
251 { printf ("%-'$l'.'$l's", $0); if ((++i % '$c') == 0) { print "" } }
252 END { print ""; }'
253 exit 0
255 esac
257 ORIGINATOR_C='<name of the PR author (one line)>'
258 ORGANIZATION_C='<organization of PR author (multiple lines)>'
259 CONFIDENTIAL_C='<[ no | yes ] (one line)>'
260 SYNOPSIS_C='<synopsis of the problem (one line)>'
261 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
262 PRIORITY_C='<[ low | medium | high ] (one line)>'
263 CATEGORY_C='<problem report category - see top for list (one line)>'
264 CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
265 RELEASE_C_1='<Please check that the above is correct for the bug being reported,>'
266 RELEASE_C_2='<and append source date of snapshot, if applicable (one line).>'
267 ENVIRONMENT_C_1='<The following information is extracted from your kernel. Please>'
268 ENVIRONMENT_C_2='<append output of "ldd", "ident" where relevant (multiple lines).>'
269 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
270 HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
271 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
273 # Catch some signals. ($xs kludge needed by Sun /bin/sh)
274 xs=0
275 TRAP_EXIT_ACTION='rm -f $REF $TEMP; exit $xs'
276 TRAP_IGNORE_ACTION=''
277 TRAP_ABORT_ACTION='echo "$COMMAND: Aborting ..."; rm -f $REF $TEMP; xs=1; exit'
278 TRAP_ABORTSAVE_ACTION='
279 echo "$COMMAND: Aborting ...";
280 if cmp -s $REF $TEMP ; then
281 rm $REF
282 else
283 echo "$COMMAND: the problem report remains in $BAD and is not sent."
284 mv $REF $BAD
286 rm -f $TEMP; xs=1; exit'
287 trap "$TRAP_EXIT_ACTION" 0
288 trap "$TRAP_ABORT_ACTION" 1 2 3 13 15
290 # If they told us to use a specific file, then do so.
291 if [ -n "$IN_FILE" ]; then
292 if [ "$IN_FILE" = "-" ]; then
293 # The PR is coming from the standard input.
294 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
295 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" > $TEMP
296 else
297 cat > $TEMP
299 else
300 # Use the file they named.
301 if [ -n "$EXPLICIT_GNATS_ADDR" ]; then
302 sed -e "s;^[Tt][Oo]:.*;To: $GNATS_ADDR;" $IN_FILE > $TEMP
303 else
304 cat $IN_FILE > $TEMP
307 else
309 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
310 # If their PR_FORM points to a bogus entry, then bail.
311 if [ ! -f "$PR_FORM" -o ! -r "$PR_FORM" -o ! -s "$PR_FORM" ]; then
312 echo "$COMMAND: can't seem to read your template file (\`$PR_FORM'), ignoring PR_FORM"
313 sleep 1
314 PRINT_INTERN=bad_prform
318 if [ -n "$PR_FORM" -a -z "$PRINT_INTERN" ]; then
319 cp $PR_FORM $TEMP ||
320 ( echo "$COMMAND: could not copy $PR_FORM" ; xs=1; exit )
321 else
322 for file in $TEMP $REF ; do
323 cat > $file << '__EOF__'
324 SEND-PR: -*- send-pr -*-
325 SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as
326 SEND-PR: will all comments (text enclosed in `<' and `>').
327 SEND-PR:
328 SEND-PR: Please consult the send-pr man page `send-pr(1)' or the Texinfo
329 SEND-PR: manual if you are not sure how to fill out a problem report.
330 SEND-PR:
331 SEND-PR: NOTE: If you include a patch that corrects the problem, the
332 SEND-PR: issue will probably be handled much more quickly.
333 SEND-PR:
334 SEND-PR: Choose from the following categories:
335 SEND-PR:
336 __EOF__
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
350 cat >> $file << __EOF__
351 To: $GNATS_ADDR
352 Subject:
353 From: $FROM
354 Reply-To: $REPLYTO
355 X-send-pr-version: $VERSION
358 >Submitter-Id: $SUBMITTER
359 >Originator: $ORIGINATOR
360 >Organization:
361 ${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:-"unreleased"}
369 $RELEASE_C_1
370 $RELEASE_C_2
371 >Environment:
372 $ENVIRONMENT_C_1
373 $ENVIRONMENT_C_2
374 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
375 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
376 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
377 >Description:
378 $DESCRIPTION_C
379 >How-To-Repeat:
380 $HOW_TO_REPEAT_C
381 >Fix:
382 $FIX_C
383 __EOF__
384 done
387 if [ "$PRINT" = true -o "$PRINT_INTERN" = true ]; then
388 cat $TEMP
389 xs=0; exit
392 chmod u+w $TEMP
393 if [ -z "$REQUEST_ID" ]; then
394 trap "$TRAP_IGNORE_ACTION" 2 3
395 eval $EDIT $TEMP
396 trap "$TRAP_ABORTSAVE_ACTION" 2 3
397 else
398 ed -s $TEMP << '__EOF__'
399 /^Subject/s/^Subject:.*/Subject: request for a customer id/
400 /^>Category/s/^>Category:.*/>Category: send-pr/
403 __EOF__
406 if cmp -s $REF $TEMP ; then
407 echo "$COMMAND: problem report not filled out, therefore not sent"
408 xs=1; exit
413 # Check the enumeration fields
415 # This is a "sed-subroutine" with one keyword parameter
416 # (with workaround for Sun sed bug)
418 SED_CMD='
419 /$PATTERN/{
420 s|||
421 s|<.*>||
422 s|^[ ]*||
423 s|[ ]*$||
429 while [ -z "$REQUEST_ID" ]; do
430 CNT=0
432 # 1) Confidential
434 PATTERN=">Confidential:"
435 CONFIDENTIAL=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
436 case "$CONFIDENTIAL" in
437 ""|yes|no) CNT=`expr $CNT + 1` ;;
438 *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
439 esac
441 # 2) Severity
443 PATTERN=">Severity:"
444 SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
445 case "$SEVERITY" in
446 ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
447 *) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
448 esac
450 # 3) Priority
452 PATTERN=">Priority:"
453 PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
454 case "$PRIORITY" in
455 ""|low|medium|high) CNT=`expr $CNT + 1` ;;
456 *) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
457 esac
459 # 4) Category
461 PATTERN=">Category:"
462 CATEGORY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
463 FOUND=
464 for C in $CATEGORIES
466 if [ "$C" = "$CATEGORY" ]; then FOUND=true ; break ; fi
467 done
468 if [ -n "$FOUND" ]; then
469 CNT=`expr $CNT + 1`
470 else
471 if [ -z "$CATEGORY" ]; then
472 echo "$COMMAND: you must include a Category: field in your report."
473 else
474 echo "$COMMAND: \`$CATEGORY' is not a known category."
478 # 5) Class
480 PATTERN=">Class:"
481 CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
482 case "$CLASS" in
483 ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
484 *) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
485 esac
487 # 6) Release
489 PATTERN=">Release:"
490 RELEASE=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
491 if [ -z "$RELEASE" ]; then
492 echo "$COMMAND: you must include a Release: field in your report."
493 else
494 CNT=`expr $CNT + 1`
497 [ $CNT -lt 6 -a -z "$BATCH" ] &&
498 echo "Errors were found with the problem report."
500 while true; do
501 if [ -z "$BATCH" ]; then
502 $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
503 read input
504 else
505 if [ $CNT -eq 6 ]; then
506 input=s
507 else
508 input=a
511 case "$input" in
513 if [ -z "$BATCH" ]; then
514 echo "$COMMAND: the problem report remains in $BAD and is not sent."
515 mv $TEMP $BAD
516 else
517 echo "$COMMAND: the problem report is not sent."
519 xs=1; exit
522 trap "$TRAP_IGNORE_ACTION" 2 3
523 eval $EDIT $TEMP
524 trap "$TRAP_ABORTSAVE_ACTION" 2 3
525 continue 2
528 break 2
530 esac
531 done
532 done
534 # Remove comments and send the problem report
535 # (we have to use patterns, where the comment contains regex chars)
537 # /^>Originator:/s;$ORIGINATOR;;
538 sed -e "
539 /^SEND-PR:/d
540 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
541 /^>Confidential:/s;<.*>;;
542 /^>Synopsis:/s;$SYNOPSIS_C;;
543 /^>Severity:/s;<.*>;;
544 /^>Priority:/s;<.*>;;
545 /^>Category:/s;$CATEGORY_C;;
546 /^>Class:/s;<.*>;;
547 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C_1;;
548 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C_2;;
549 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C_1;;
550 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C_2;;
551 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
552 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
553 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
554 " $TEMP > $REF
556 if $MAIL_AGENT < $REF; then
557 echo "$COMMAND: problem report sent"
558 xs=0; exit
559 else
560 echo "$COMMAND: mysterious mail failure."
561 if [ -z "$BATCH" ]; then
562 echo "$COMMAND: the problem report remains in $BAD and is not sent."
563 mv $REF $BAD
564 else
565 echo "$COMMAND: the problem report is not sent."
567 xs=1; exit