update from main archive 960105
[glibc.git] / glibcbug.in
blobc23f32a9eaf0c65d6b8144afd2bc12aefc0af704
1 #! /bin/sh
3 # glibcbug - create a bug report and mail it to the bug address.
5 # configuration section:
6 # these variables are filled in by configure
8 VERSION="@VERSION@"
9 BUGGLIBC="bugs@gnu.ai.mit.edu"
10 ADDONS="@subdirs@"
12 PATH=/bin:/usr/bin:/usr/local/bin:$PATH
13 export PATH
15 TEMP=/tmp/glibcbug.$$
17 BUGADDR=${1-$BUGGLIBC}
18 ENVIRONMENT=`uname -a`
20 : ${EDITOR=emacs}
22 : ${USER=${LOGNAME-`whoami`}}
24 trap 'rm -f $TEMP $TEMP.x; exit 1' 1 2 3 13 15
25 trap 'rm -f $TEMP $TEMP.x' 0
28 # How to read the passwd database.
29 PASSWD="cat /etc/passwd"
31 if [ -f /usr/lib/sendmail ] ; then
32 RMAIL="/usr/lib/sendmail -oi -t"
33 elif [ -f /usr/sbin/sendmail ] ; then
34 RMAIL="/usr/sbin/sendmail -oi -t"
35 else
36 RMAIL=rmail
39 # Figure out how to echo a string without a trailing newline
40 N=`echo 'hi there\c'`
41 case "$N" in
42 *c) ECHON1='echo -n' ECHON2= ;;
43 *) ECHON1=echo ECHON2='\c' ;;
44 esac
46 # Find out the name of the originator of this PR.
47 if [ -n "$NAME" ]; then
48 ORIGINATOR="$NAME"
49 elif [ -f $HOME/.fullname ]; then
50 ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
51 else
52 # Must use temp file due to incompatibilities in quoting behavior
53 # and to protect shell metacharacters in the expansion of $LOGNAME
54 $PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP
55 ORIGINATOR="`cat $TEMP`"
56 rm -f $TEMP
59 if [ -n "$ORGANIZATION" ]; then
60 if [ -f "$ORGANIZATION" ]; then
61 ORGANIZATION="`cat $ORGANIZATION`"
63 else
64 if [ -f $HOME/.organization ]; then
65 ORGANIZATION="`cat $HOME/.organization`"
66 elif [ -f $HOME/.signature ]; then
67 ORGANIZATION=`sed -e "s/^/ /" $HOME/.signature; echo ">"`
71 # If they don't have a preferred editor set, then use
72 if [ -z "$VISUAL" ]; then
73 if [ -z "$EDITOR" ]; then
74 EDIT=vi
75 else
76 EDIT="$EDITOR"
78 else
79 EDIT="$VISUAL"
82 # Find out some information.
83 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
84 ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
85 ARCH=`[ -f /bin/arch ] && /bin/arch`
86 MACHINE=`[ -f /bin/machine ] && /bin/machine`
88 ORGANIZATION_C='<organization of PR author (multiple lines)>'
89 CONFIDENTIAL_C='<[ yes | no ] (one line)>'
90 SYNOPSIS_C='<synopsis of the problem (one line)>'
91 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
92 PRIORITY_C='<[ low | medium | high ] (one line)>'
93 CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
94 RELEASE_C='<release number or tag (one line)>'
95 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
96 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
97 HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
98 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
101 cat > $TEMP <<EOF
102 SEND-PR: -*- send-pr -*-
103 SEND-PR: Lines starting with \`SEND-PR' will be removed automatically, as
104 SEND-PR: will all comments (text enclosed in \`<' and \`>').
105 SEND-PR:
106 From: ${USER}
107 To: ${BUGADDR}
108 Subject: [50 character or so descriptive subject here (for reference)]
110 >Submitter-Id: <submitter ID>
111 >Originator: ${ORIGINATOR}
112 >Organization:
113 ${ORGANIZATION- $ORGANIZATION_C}
114 >Confidential: $CONFIDENTIAL_C
115 >Synopsis: $SYNOPSIS_C
116 >Severity: $SEVERITY_C
117 >Priority: $PRIORITY_C
118 >Category: libc
119 >Class: $CLASS_C
120 >Release: libc-${VERSION}
121 >Environment:
122 <machine, os, target, libraries (multiple lines)>
123 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
124 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
125 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
126 `[ -n "$ADDONS" ] && echo Addons: $ADDONS`
128 >Description:
129 $DESCRIPTION_C
130 >How-To-Repeat:
131 $HOW_TO_REPEAT_C
132 >Fix:
133 $FIX_C
136 chmod u+w $TEMP
137 cp $TEMP $TEMP.x
139 eval $EDIT $TEMP
141 if cmp -s $TEMP $TEMP.x; then
142 echo "File not changed, no bug report submitted."
143 exit 1
147 # Check the enumeration fields
149 # This is a "sed-subroutine" with one keyword parameter
150 # (with workaround for Sun sed bug)
152 SED_CMD='
153 /$PATTERN/{
154 s|||
155 s|<.*>||
156 s|^[ ]*||
157 s|[ ]*$||
163 while :; do
164 CNT=0
166 # 1) Confidential
168 PATTERN=">Confidential:"
169 CONFIDENTIAL=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
170 case "$CONFIDENTIAL" in
171 ""|yes|no) CNT=`expr $CNT + 1` ;;
172 *) echo "$COMMAND: \`$CONFIDENTIAL' is not a valid value for \`Confidential'." ;;
173 esac
175 # 2) Severity
177 PATTERN=">Severity:"
178 SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
179 case "$SEVERITY" in
180 ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
181 *) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
182 esac
184 # 3) Priority
186 PATTERN=">Priority:"
187 PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
188 case "$PRIORITY" in
189 ""|low|medium|high) CNT=`expr $CNT + 1` ;;
190 *) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
191 esac
193 # 4) Class
195 PATTERN=">Class:"
196 CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
197 case "$CLASS" in
198 ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
199 *) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
200 esac
202 [ $CNT -lt 5 ] &&
203 echo "Errors were found with the problem report."
205 while :; do
206 $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
207 read input
208 case "$input" in
210 echo "$COMMAND: problem report saved in $HOME/dead.glibcbug."
211 cat $TEMP >> $HOME/dead.glibcbug
212 xs=1; exit
215 eval $EDIT $TEMP
216 continue 2
219 break 2
221 esac
222 done
223 done
225 # Remove comments and send the problem report
226 # (we have to use patterns, where the comment contains regex chars)
228 # /^>Originator:/s;$ORIGINATOR;;
229 sed -e "
230 /^SEND-PR:/d
231 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
232 /^>Confidential:/s;<.*>;;
233 /^>Synopsis:/s;$SYNOPSIS_C;;
234 /^>Severity:/s;<.*>;;
235 /^>Priority:/s;<.*>;;
236 /^>Class:/s;<.*>;;
237 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
238 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
239 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
240 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
241 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
242 " $TEMP > $REF
244 if $MAIL_AGENT < $REF; then
245 echo "$COMMAND: problem report sent"
246 xs=0; exit
247 else
248 echo "$COMMAND: mysterious mail failure, report not sent."
249 echo "$COMMAND: problem report saved in $HOME/dead.glibcbug."
250 cat $TEMP >> $HOME/dead.glibcbug
253 exit 0