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