Correct handling of separators after last non-separator.
[glibc.git] / glibcbug.in
blob8183d195dfa2e23b436a855a4627057017522824
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.org"
10 ADDONS="@subdirs@"
11 HOST="@host@"
12 CC='@CC@'
13 CFLAGS="@CFLAGS@"
14 BUILD_SHARED="@shared@"
15 BUILD_PROFILE="@profile@"
16 BUILD_OMITFP="@omitfp@"
17 STDIO="@stdio@"
19 PATH=/bin:/usr/bin:/usr/local/bin:$PATH
20 export PATH
22 TEMP=/tmp/glibcbug.$$
24 BUGADDR=${1-$BUGGLIBC}
25 ENVIRONMENT=`uname -a`
27 : ${EDITOR=emacs}
29 : ${USER=${LOGNAME-`whoami`}}
31 trap 'rm -f $TEMP $TEMP.x; exit 1' 1 2 3 13 15
32 trap 'rm -f $TEMP $TEMP.x' 0
35 # How to read the passwd database.
36 PASSWD="cat /etc/passwd"
38 if [ -f /usr/lib/sendmail ] ; then
39 MAIL_AGENT="/usr/lib/sendmail -oi -t"
40 elif [ -f /usr/sbin/sendmail ] ; then
41 MAIL_AGENT="/usr/sbin/sendmail -oi -t"
42 else
43 MAIL_AGENT=rmail
46 # Figure out how to echo a string without a trailing newline
47 N=`echo 'hi there\c'`
48 case "$N" in
49 *c) ECHON1='echo -n' ECHON2= ;;
50 *) ECHON1=echo ECHON2='\c' ;;
51 esac
53 # Find out the name of the originator of this PR.
54 if [ -n "$NAME" ]; then
55 ORIGINATOR="$NAME"
56 elif [ -f $HOME/.fullname ]; then
57 ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
58 else
59 # Must use temp file due to incompatibilities in quoting behavior
60 # and to protect shell metacharacters in the expansion of $LOGNAME
61 $PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP
62 ORIGINATOR="`cat $TEMP`"
63 rm -f $TEMP
66 if [ -n "$ORGANIZATION" ]; then
67 if [ -f "$ORGANIZATION" ]; then
68 ORGANIZATION="`cat $ORGANIZATION`"
70 else
71 if [ -f $HOME/.organization ]; then
72 ORGANIZATION="`cat $HOME/.organization`"
73 elif [ -f $HOME/.signature ]; then
74 ORGANIZATION=`sed -e "s/^/ /" $HOME/.signature; echo ">"`
78 # If they don't have a preferred editor set, then use
79 if [ -z "$VISUAL" ]; then
80 if [ -z "$EDITOR" ]; then
81 EDIT=vi
82 else
83 EDIT="$EDITOR"
85 else
86 EDIT="$VISUAL"
89 # Find out some information.
90 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
91 ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
92 ARCH=`[ -f /bin/arch ] && /bin/arch`
93 MACHINE=`[ -f /bin/machine ] && /bin/machine`
95 ORGANIZATION_C='<organization of PR author (multiple lines)>'
96 SYNOPSIS_C='<synopsis of the problem (one line)>'
97 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
98 PRIORITY_C='<[ low | medium | high ] (one line)>'
99 CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
100 RELEASE_C='<release number or tag (one line)>'
101 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
102 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
103 HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
104 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
107 cat > $TEMP <<EOF
108 SEND-PR: -*- send-pr -*-
109 SEND-PR: Lines starting with \`SEND-PR' will be removed automatically, as
110 SEND-PR: will all comments (text enclosed in \`<' and \`>').
111 SEND-PR:
112 From: ${USER}
113 To: ${BUGADDR}
114 Subject: [50 character or so descriptive subject here (for reference)]
116 >Submitter-Id: net
117 >Originator: ${ORIGINATOR}
118 >Organization:
119 ${ORGANIZATION- $ORGANIZATION_C}
120 >Confidential: no
121 >Synopsis: $SYNOPSIS_C
122 >Severity: $SEVERITY_C
123 >Priority: $PRIORITY_C
124 >Category: libc
125 >Class: $CLASS_C
126 >Release: libc-${VERSION}
127 >Environment:
128 $ENVIRONMENT_C
129 `[ -n "$HOST" ] && echo Host type: $HOST`
130 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
131 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
132 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
133 `[ -n "$ADDONS" ] && echo Addons: $ADDONS`
134 `[ -n "$CFLAGS" ] && echo Build CFLAGS: $CFLAGS`
135 `[ -n "$CC" ] && echo Build CC: $CC`
136 `[ -n "$BUILD_SHARED" ] && echo Build shared: $BUILD_SHARED`
137 `[ -n "$BUILD_PROFILE" ] && echo Build profile: $BUILD_PROFILE`
138 `[ -n "$BUILD_OMITFP" ] && echo Build omitfp: $BUILD_OMITFP`
139 `[ -n "$STDIO" ] && echo Stdio: $STDIO`
141 >Description:
142 $DESCRIPTION_C
143 >How-To-Repeat:
144 $HOW_TO_REPEAT_C
145 >Fix:
146 $FIX_C
149 chmod u+w $TEMP
150 cp $TEMP $TEMP.x
152 eval $EDIT $TEMP
154 if cmp -s $TEMP $TEMP.x; then
155 echo "File not changed, no bug report submitted."
156 exit 1
160 # Check the enumeration fields
162 # This is a "sed-subroutine" with one keyword parameter
163 # (with workaround for Sun sed bug)
165 SED_CMD='
166 /$PATTERN/{
167 s|||
168 s|<.*>||
169 s|^[ ]*||
170 s|[ ]*$||
176 while :; do
177 CNT=0
180 # 1) Severity
182 PATTERN=">Severity:"
183 SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
184 case "$SEVERITY" in
185 ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
186 *) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
187 esac
189 # 2) Priority
191 PATTERN=">Priority:"
192 PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
193 case "$PRIORITY" in
194 ""|low|medium|high) CNT=`expr $CNT + 1` ;;
195 *) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
196 esac
198 # 3) Class
200 PATTERN=">Class:"
201 CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
202 case "$CLASS" in
203 ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
204 *) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
205 esac
207 [ $CNT -lt 3 ] &&
208 echo "Errors were found with the problem report."
210 while :; do
211 $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
212 read input
213 case "$input" in
215 echo "$COMMAND: problem report saved in $HOME/dead.glibcbug."
216 cat $TEMP >> $HOME/dead.glibcbug
217 xs=1; exit
220 eval $EDIT $TEMP
221 continue 2
224 break 2
226 esac
227 done
228 done
230 # Remove comments and send the problem report
231 # (we have to use patterns, where the comment contains regex chars)
233 # /^>Originator:/s;$ORIGINATOR;;
234 sed -e "
235 /^SEND-PR:/d
236 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
237 /^>Confidential:/s;<.*>;;
238 /^>Synopsis:/s;$SYNOPSIS_C;;
239 /^>Severity:/s;<.*>;;
240 /^>Priority:/s;<.*>;;
241 /^>Class:/s;<.*>;;
242 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
243 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
244 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
245 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
246 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
247 " $TEMP > $TEMP.x
249 if $MAIL_AGENT < $TEMP.x; then
250 echo "$COMMAND: problem report sent"
251 xs=0; exit
252 else
253 echo "$COMMAND: mysterious mail failure, report not sent."
254 echo "$COMMAND: problem report saved in $HOME/dead.glibcbug."
255 cat $TEMP >> $HOME/dead.glibcbug
258 exit 0