Don't set PATH. Fix typo.
[kopensolaris-gnu/glibc.git] / glibcbug.in
1 #! /bin/sh
2 #
3 # glibcbug - create a bug report and mail it to the bug address.
4 #
5 # configuration section:
6 #       these variables are filled in by configure
7 #
8 VERSION="@VERSION@"
9 BUGGLIBC="bugs@gnu.org"
10 ADDONS="@subdirs@"
11 HOST="@host@"
12 CC='@CC@'
13 CFLAGS="@CFLAGS@"
14 VERSIONING="@VERSIONING@"
15 BUILD_STATIC="@static@"
16 BUILD_SHARED="@shared@"
17 BUILD_PIC_DEFAULT="@pic_default@"
18 BUILD_PROFILE="@profile@"
19 BUILD_OMITFP="@omitfp@"
20 BUILD_BOUNDED="@bounded@"
21 BUILD_STATIC_NSS="@static_nss@"
22 STDIO="@stdio@"
23
24 TEMP=`mktemp -q /tmp/glibcbugXXXXXX 2>/dev/null`
25 if test $? -ne 0; then
26   TEMP=/tmp/glibcbug.$$
27   echo > $TEMP
28   chmod 600 $TEMP
29 fi
30 TEMPx=`mktemp -q /tmp/glibcbugXXXXXX 2>/dev/null`
31 if test $? -ne 0; then
32   TEMPx=/tmp/glibcbug.$$.x
33   echo > $TEMPx
34   chmod 600 $TEMPx
35 fi
36
37 BUGADDR=${1-$BUGGLIBC}
38
39 : ${EDITOR=emacs}
40
41 : ${USER=${LOGNAME-`whoami`}}
42
43 trap 'rm -f $TEMP $TEMPx; exit 1' 1 2 3 13 15
44 trap 'rm -f $TEMP $TEMPx' 0
45
46
47 # How to read the passwd database.
48 PASSWD="cat /etc/passwd"
49
50 if [ -f /usr/lib/sendmail ] ; then
51         MAIL_AGENT="/usr/lib/sendmail -oi -t"
52 elif [ -f /usr/sbin/sendmail ] ; then
53         MAIL_AGENT="/usr/sbin/sendmail -oi -t"
54 else
55         MAIL_AGENT=rmail
56 fi
57
58 # Figure out how to echo a string without a trailing newline
59 N=`echo 'hi there\c'`
60 case "$N" in
61 *c)     ECHON1='echo -n' ECHON2= ;;
62 *)      ECHON1=echo ECHON2='\c' ;;
63 esac
64
65 # Find out the name of the originator of this PR.
66 if [ -n "$NAME" ]; then
67   ORIGINATOR="$NAME"
68 elif [ -f $HOME/.fullname ]; then
69   ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
70 else
71   # Must use temp file due to incompatibilities in quoting behavior
72   # and to protect shell metacharacters in the expansion of $LOGNAME
73   $PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP
74   ORIGINATOR="`cat $TEMP`"
75 fi
76
77 if [ -n "$ORGANIZATION" ]; then
78   if [ -f "$ORGANIZATION" ]; then
79     ORGANIZATION="`cat $ORGANIZATION`"
80   fi
81 else
82   if [ -f $HOME/.organization ]; then
83     ORGANIZATION="`cat $HOME/.organization`"
84   elif [ -f $HOME/.signature ]; then
85     ORGANIZATION=`sed -e "s/^/  /" $HOME/.signature; echo ">"`
86   fi
87 fi
88
89 # If they don't have a preferred editor set, then use
90 if [ -z "$VISUAL" ]; then
91   if [ -z "$EDITOR" ]; then
92     EDIT=vi
93   else
94     EDIT="$EDITOR"
95   fi
96 else
97   EDIT="$VISUAL"
98 fi
99
100 # Find out some information.
101 SYSTEM=`( [ -f /bin/uname ] && /bin/uname -a ) || \
102         ( [ -f /usr/bin/uname ] && /usr/bin/uname -a ) || echo ""`
103 ARCH=`[ -f /bin/arch ] && /bin/arch`
104 MACHINE=`[ -f /bin/machine ] && /bin/machine`
105 CCVERSION=`$CC -v 2>&1 | sed -n 's/gcc version //p'`
106
107 case $HOST in *linux*)
108   KHDRS=`(echo '#include <linux/version.h>'
109           echo '! UTS_RELEASE' ) |
110          $CC -E - | sed -n '/!/s/[! "]//gp'`;;
111 esac
112
113 ORGANIZATION_C='<organization of PR author (multiple lines)>'
114 SYNOPSIS_C='<synopsis of the problem (one line)>'
115 SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
116 PRIORITY_C='<[ low | medium | high ] (one line)>'
117 CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
118 RELEASE_C='<release number or tag (one line)>'
119 ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
120 DESCRIPTION_C='<precise description of the problem (multiple lines)>'
121 HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
122 FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
123
124
125 cat > $TEMP <<EOF
126 SEND-PR: -*- send-pr -*-
127 SEND-PR: Lines starting with \`SEND-PR' will be removed automatically, as
128 SEND-PR: will all comments (text enclosed in \`<' and \`>').
129 SEND-PR:
130 From: ${USER}
131 To: ${BUGADDR}
132 Subject: [50 character or so descriptive subject here (for reference)]
133
134 >Submitter-Id:  net
135 >Originator:    ${ORIGINATOR}
136 >Organization:
137 ${ORGANIZATION- $ORGANIZATION_C}
138 >Confidential:  no
139 >Synopsis:      $SYNOPSIS_C
140 >Severity:      $SEVERITY_C
141 >Priority:      $PRIORITY_C
142 >Category:      libc
143 >Class:         $CLASS_C
144 >Release:       libc-${VERSION}
145 >Environment:
146         $ENVIRONMENT_C
147 `[ -n "$HOST" ] && echo Host type: $HOST`
148 `[ -n "$SYSTEM" ] && echo System: $SYSTEM`
149 `[ -n "$ARCH" ] && echo Architecture: $ARCH`
150 `[ -n "$MACHINE" ] && echo Machine: $MACHINE`
151 `[ -n "$ADDONS" ] && echo Addons: $ADDONS`
152 `[ -n "$CFLAGS" ] && echo Build CFLAGS: $CFLAGS`
153 `[ -n "$CC" ] && echo Build CC: $CC`
154 `[ -n "$CCVERSION" ] && echo Compiler version: $CCVERSION`
155 `[ -n "$KHDRS" ] && echo Kernel headers: $KHDRS`
156 `[ -n "$VERSIONING" ] && echo Symbol versioning: $VERSIONING`
157 `[ -n "$BUILD_STATIC" ] && echo Build static: $BUILD_STATIC`
158 `[ -n "$BUILD_SHARED" ] && echo Build shared: $BUILD_SHARED`
159 `[ -n "$BUILD_PIC_DEFAULT" ] && echo Build pic-default: $BUILD_PIC_DEFAULT`
160 `[ -n "$BUILD_PROFILE" ] && echo Build profile: $BUILD_PROFILE`
161 `[ -n "$BUILD_OMITFP" ] && echo Build omitfp: $BUILD_OMITFP`
162 `[ -n "$BUILD_BOUNDED" ] && echo Build bounded: $BUILD_BOUNDED`
163 `[ -n "$BUILD_STATIC_NSS" ] && echo Build static-nss: $BUILD_STATIC_NSS`
164 `[ -n "$STDIO" ] && echo Stdio: $STDIO`
165
166 >Description:
167         $DESCRIPTION_C
168 >How-To-Repeat:
169         $HOW_TO_REPEAT_C
170 >Fix:
171         $FIX_C
172 EOF
173
174 chmod u+w $TEMP
175 cp $TEMP $TEMPx
176
177 eval $EDIT $TEMP
178
179 if cmp -s $TEMP $TEMPx; then
180         echo "File not changed, no bug report submitted."
181         exit 1
182 fi
183
184 #\f
185 #       Check the enumeration fields
186
187 # This is a "sed-subroutine" with one keyword parameter
188 # (with workaround for Sun sed bug)
189 #
190 SED_CMD='
191 /$PATTERN/{
192 s|||
193 s|<.*>||
194 s|^[    ]*||
195 s|[     ]*$||
196 p
197 q
198 }'
199
200
201 while :; do
202   CNT=0
203
204   #
205   # 1) Severity
206   #
207   PATTERN=">Severity:"
208   SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
209   case "$SEVERITY" in
210     ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
211     *)  echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
212   esac
213   #
214   # 2) Priority
215   #
216   PATTERN=">Priority:"
217   PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
218   case "$PRIORITY" in
219     ""|low|medium|high) CNT=`expr $CNT + 1` ;;
220     *)  echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
221   esac
222   #
223   # 3) Class
224   #
225   PATTERN=">Class:"
226   CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
227   case "$CLASS" in
228     ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
229     *)  echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
230   esac
231
232   [ $CNT -lt 3 ] &&
233     echo "Errors were found with the problem report."
234
235   while :; do
236     $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
237     read input
238     case "$input" in
239       a*)
240         echo "$COMMAND: problem report saved in $HOME/dead.glibcbug."
241         cat $TEMP >> $HOME/dead.glibcbug
242         xs=1; exit
243         ;;
244       e*)
245         eval $EDIT $TEMP
246         continue 2
247         ;;
248       s*)
249         break 2
250         ;;
251     esac
252   done
253 done
254 #
255 #       Remove comments and send the problem report
256 #       (we have to use patterns, where the comment contains regex chars)
257 #
258 # /^>Originator:/s;$ORIGINATOR;;
259 sed  -e "
260 /^SEND-PR:/d
261 /^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
262 /^>Confidential:/s;<.*>;;
263 /^>Synopsis:/s;$SYNOPSIS_C;;
264 /^>Severity:/s;<.*>;;
265 /^>Priority:/s;<.*>;;
266 /^>Class:/s;<.*>;;
267 /^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
268 /^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
269 /^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
270 /^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
271 /^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
272 " $TEMP > $TEMPx
273
274 if $MAIL_AGENT < $TEMPx; then
275   echo "$COMMAND: problem report sent"
276   xs=0; exit
277 else
278   echo "$COMMAND: mysterious mail failure, report not sent."
279   echo "$COMMAND: problem report saved in $HOME/dead.glibcbug."
280   cat $TEMP >> $HOME/dead.glibcbug
281 fi
282
283 exit 0