[$(subdir)=misc] (sysdep_headers):
[glibc/history.git] / glibcbug.in
blob69496b6e1ab1f0752a30004511ef5b1b71f4193f
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@"
13 PATH=/bin:/usr/bin:/usr/local/bin:$PATH
14 export PATH
16 TEMP=/tmp/glibcbug.$$
18 BUGADDR=${1-$BUGGLIBC}
19 ENVIRONMENT=`uname -a`
21 : ${EDITOR=emacs}
23 : ${USER=${LOGNAME-`whoami`}}
25 trap 'rm -f $TEMP $TEMP.x; exit 1' 1 2 3 13 15
26 trap 'rm -f $TEMP $TEMP.x' 0
29 # How to read the passwd database.
30 PASSWD="cat /etc/passwd"
32 if [ -f /usr/lib/sendmail ] ; then
33 MAIL_AGENT="/usr/lib/sendmail -oi -t"
34 elif [ -f /usr/sbin/sendmail ] ; then
35 MAIL_AGENT="/usr/sbin/sendmail -oi -t"
36 else
37 MAIL_AGENT=rmail
40 # Figure out how to echo a string without a trailing newline
41 N=`echo 'hi there\c'`
42 case "$N" in
43 *c) ECHON1='echo -n' ECHON2= ;;
44 *) ECHON1=echo ECHON2='\c' ;;
45 esac
47 # Find out the name of the originator of this PR.
48 if [ -n "$NAME" ]; then
49 ORIGINATOR="$NAME"
50 elif [ -f $HOME/.fullname ]; then
51 ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
52 else
53 # Must use temp file due to incompatibilities in quoting behavior
54 # and to protect shell metacharacters in the expansion of $LOGNAME
55 $PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP
56 ORIGINATOR="`cat $TEMP`"
57 rm -f $TEMP
60 if [ -n "$ORGANIZATION" ]; then
61 if [ -f "$ORGANIZATION" ]; then
62 ORGANIZATION="`cat $ORGANIZATION`"
64 else
65 if [ -f $HOME/.organization ]; then
66 ORGANIZATION="`cat $HOME/.organization`"
67 elif [ -f $HOME/.signature ]; then
68 ORGANIZATION=`sed -e "s/^/ /" $HOME/.signature; echo ">"`
72 # If they don't have a preferred editor set, then use
73 if [ -z "$VISUAL" ]; then
74 if [ -z "$EDITOR" ]; then
75 EDIT=vi
76 else
77 EDIT="$EDITOR"
79 else
80 EDIT="$VISUAL"
83 # Find out some information.
84 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
85 ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
86 ARCH=`[ -f /bin/arch ] && /bin/arch`
87 MACHINE=`[ -f /bin/machine ] && /bin/machine`
89 ORGANIZATION_C='<organization of PR author (multiple lines)>'
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: net
111 >Originator: ${ORIGINATOR}
112 >Organization:
113 ${ORGANIZATION- $ORGANIZATION_C}
114 >Confidential: no
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 $ENVIRONMENT_C
123 `[ -n "$HOST" ] && echo Host type: $HOST`
124 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
125 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
126 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
127 `[ -n "$ADDONS" ] && echo Addons: $ADDONS`
129 >Description:
130 $DESCRIPTION_C
131 >How-To-Repeat:
132 $HOW_TO_REPEAT_C
133 >Fix:
134 $FIX_C
137 chmod u+w $TEMP
138 cp $TEMP $TEMP.x
140 eval $EDIT $TEMP
142 if cmp -s $TEMP $TEMP.x; then
143 echo "File not changed, no bug report submitted."
144 exit 1
148 # Check the enumeration fields
150 # This is a "sed-subroutine" with one keyword parameter
151 # (with workaround for Sun sed bug)
153 SED_CMD='
154 /$PATTERN/{
155 s|||
156 s|<.*>||
157 s|^[ ]*||
158 s|[ ]*$||
164 while :; do
165 CNT=0
168 # 1) Severity
170 PATTERN=">Severity:"
171 SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
172 case "$SEVERITY" in
173 ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
174 *) echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
175 esac
177 # 2) Priority
179 PATTERN=">Priority:"
180 PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
181 case "$PRIORITY" in
182 ""|low|medium|high) CNT=`expr $CNT + 1` ;;
183 *) echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
184 esac
186 # 3) Class
188 PATTERN=">Class:"
189 CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
190 case "$CLASS" in
191 ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
192 *) echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
193 esac
195 [ $CNT -lt 3 ] &&
196 echo "Errors were found with the problem report."
198 while :; do
199 $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
200 read input
201 case "$input" in
203 echo "$COMMAND: problem report saved in $HOME/dead.glibcbug."
204 cat $TEMP >> $HOME/dead.glibcbug
205 xs=1; exit
208 eval $EDIT $TEMP
209 continue 2
212 break 2
214 esac
215 done
216 done
218 # Remove comments and send the problem report
219 # (we have to use patterns, where the comment contains regex chars)
221 # /^>Originator:/s;$ORIGINATOR;;
222 sed -e "
223 /^SEND-PR:/d
224 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
225 /^>Confidential:/s;<.*>;;
226 /^>Synopsis:/s;$SYNOPSIS_C;;
227 /^>Severity:/s;<.*>;;
228 /^>Priority:/s;<.*>;;
229 /^>Class:/s;<.*>;;
230 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
231 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
232 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
233 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
234 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
235 " $TEMP > $TEMP.x
237 if $MAIL_AGENT < $TEMP.x; then
238 echo "$COMMAND: problem report sent"
239 xs=0; exit
240 else
241 echo "$COMMAND: mysterious mail failure, report not sent."
242 echo "$COMMAND: problem report saved in $HOME/dead.glibcbug."
243 cat $TEMP >> $HOME/dead.glibcbug
246 exit 0