]> git.ipfire.org Git - thirdparty/bash.git/blame - support/bashbug.sh
Imported from ../bash-2.05b.tar.gz.
[thirdparty/bash.git] / support / bashbug.sh
CommitLineData
726f6388
JA
1#!/bin/sh -
2#
ccc6cda3
JA
3# bashbug - create a bug report and mail it to the bug address
4#
5# The bug address depends on the release status of the shell. Versions
f73dda09
JA
6# with status `devel', `alpha', `beta', or `rc' mail bug reports to
7# chet@po.cwru.edu and, optionally, to bash-testers@po.cwru.edu.
cce855bc 8# Other versions send mail to bug-bash@gnu.org.
7117c2d2
JA
9#
10# Copyright (C) 1996-2002 Free Software Foundation, Inc.
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2, or (at your option)
15# any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111 USA.
25
726f6388
JA
26#
27# configuration section:
f73dda09 28# these variables are filled in by the make target in Makefile
726f6388 29#
ccc6cda3
JA
30MACHINE="!MACHINE!"
31OS="!OS!"
32CC="!CC!"
33CFLAGS="!CFLAGS!"
34RELEASE="!RELEASE!"
35PATCHLEVEL="!PATCHLEVEL!"
36RELSTATUS="!RELSTATUS!"
37MACHTYPE="!MACHTYPE!"
38
39PATH=/bin:/usr/bin:/usr/local/bin:$PATH
726f6388
JA
40export PATH
41
28ef6c31
JA
42# If the OS supplies a program to make temp files with semi-random names,
43# use it.
f73dda09
JA
44: ${TMPDIR:=/tmp}
45rm_tmp1=false
46rm_tmp2=false
47
48# if we don't have mktemp or tempfile, we don't want to see error messages
49# like `mktemp: not found', so temporarily redirect stderr using {...} while
50# trying to run them. this may fail using old versions of the bourne shell
51# that run {...} blocks with redirections in subshells; in that case we're
52# no worse off than previous versions
53
54{ TEMPFILE1=`mktemp "$TMPDIR/bbug.XXXXXX" 2>/dev/null` ; } 2>/dev/null
55if [ -z "$TEMPFILE1" ]; then
56 { TEMPFILE1=`tempfile --prefix bbug --mode 600 2>/dev/null`; } 2>/dev/null
57fi
58if [ -z "$TEMPFILE1" ]; then
59 TEMPFILE1=$TMPDIR/bbug.$$
60 rm_tmp1=true
61fi
62{ TEMPFILE2=`mktemp "$TMPDIR/bbug.XXXXXX" 2>/dev/null`; } 2>/dev/null
63if [ -z "$TEMPFILE2" ]; then
64 { TEMPFILE2=`tempfile --prefix bbug --mode 600 2>/dev/null`; } 2>/dev/null
65fi
66if [ -z "$TEMPFILE2" ]; then
67 TEMPFILE2="$TMPDIR/bbug.$$.x"
68 rm_tmp2=true
69fi
28ef6c31 70
bb70624e
JA
71USAGE="Usage: $0 [--help] [--version] [bug-report-email-address]"
72VERSTR="GNU bashbug, version ${RELEASE}.${PATCHLEVEL}-${RELSTATUS}"
73
74do_help= do_version=
75
76while [ $# -gt 0 ]; do
77 case "$1" in
78 --help) shift ; do_help=y ;;
79 --version) shift ; do_version=y ;;
80 --) shift ; break ;;
81 -*) echo "bashbug: ${1}: invalid option" >&2
82 echo "$USAGE" >& 2
83 exit 2 ;;
84 *) break ;;
85 esac
86done
87
88if [ -n "$do_version" ]; then
89 echo "${VERSTR}"
90 exit 0
91fi
92
93if [ -n "$do_help" ]; then
94 echo "${VERSTR}"
95 echo "${USAGE}"
96 echo
97 cat << HERE_EOF
98Bashbug is used to send mail to the Bash maintainers
99for when Bash doesn't behave like you'd like, or expect.
100
101Bashbug will start up your editor (as defined by the shell's
102EDITOR environment variable) with a preformatted bug report
103template for you to fill in. The report will be mailed to the
104bash maintainers by default. See the manual for details.
105
106If you invoke bashbug by accident, just quit your editor without
107saving any changes to the template, and no bug report will be sent.
108HERE_EOF
109 exit 0
110fi
d166f048
JA
111
112# Figure out how to echo a string without a trailing newline
113N=`echo 'hi there\c'`
114case "$N" in
115*c) n=-n c= ;;
116*) n= c='\c' ;;
117esac
118
119BASHTESTERS="bash-testers@po.cwru.edu"
726f6388 120
ccc6cda3 121case "$RELSTATUS" in
f73dda09
JA
122alpha*|beta*|devel*|rc*) BUGBASH=chet@po.cwru.edu ;;
123*) BUGBASH=bug-bash@gnu.org ;;
ccc6cda3
JA
124esac
125
d166f048 126case "$RELSTATUS" in
f73dda09 127alpha*|beta*|devel*|rc*)
bb70624e 128 echo "$0: This is a testing release. Would you like your bug report"
d166f048
JA
129 echo "$0: to be sent to the bash-testers mailing list?"
130 echo $n "$0: Send to bash-testers? $c"
131 read ans
132 case "$ans" in
133 y*|Y*) BUGBASH="${BUGBASH},${BASHTESTERS}" ;;
134 esac ;;
135esac
136
137BUGADDR="${1-$BUGBASH}"
726f6388 138
bb70624e 139if [ -z "$DEFEDITOR" ] && [ -z "$EDITOR" ]; then
28ef6c31
JA
140 if [ -x /usr/bin/editor ]; then
141 DEFEDITOR=editor
142 elif [ -x /usr/local/bin/ce ]; then
bb70624e
JA
143 DEFEDITOR=ce
144 elif [ -x /usr/local/bin/emacs ]; then
145 DEFEDITOR=emacs
146 elif [ -x /usr/contrib/bin/emacs ]; then
147 DEFEDITOR=emacs
148 elif [ -x /usr/bin/emacs ]; then
149 DEFEDITOR=emacs
150 elif [ -x /usr/bin/xemacs ]; then
151 DEFEDITOR=xemacs
152 elif [ -x /usr/contrib/bin/jove ]; then
153 DEFEDITOR=jove
154 elif [ -x /usr/local/bin/jove ]; then
155 DEFEDITOR=jove
156 elif [ -x /usr/bin/vi ]; then
157 DEFEDITOR=vi
158 else
159 echo "$0: No default editor found: attempting to use vi" >&2
160 DEFEDITOR=vi
161 fi
162fi
163
164
165: ${EDITOR=$DEFEDITOR}
726f6388 166
ccc6cda3
JA
167: ${USER=${LOGNAME-`whoami`}}
168
f73dda09
JA
169trap 'rm -f "$TEMPFILE1" "$TEMPFILE2"; exit 1' 1 2 3 13 15
170trap 'rm -f "$TEMPFILE1" "$TEMPFILE2"' 0
726f6388
JA
171
172UN=
173if (uname) >/dev/null 2>&1; then
174 UN=`uname -a`
175fi
176
177if [ -f /usr/lib/sendmail ] ; then
178 RMAIL="/usr/lib/sendmail"
bb70624e 179 SMARGS="-i -t"
726f6388
JA
180elif [ -f /usr/sbin/sendmail ] ; then
181 RMAIL="/usr/sbin/sendmail"
bb70624e 182 SMARGS="-i -t"
726f6388
JA
183else
184 RMAIL=rmail
bb70624e 185 SMARGS="$BUGADDR"
726f6388
JA
186fi
187
f73dda09
JA
188INITIAL_SUBJECT='[50 character or so descriptive subject here (for reference)]'
189
190# this is raceable unless (hopefully) we used mktemp(1) or tempfile(1)
191$rm_tmp1 && rm -f "$TEMPFILE1"
cce855bc 192
f73dda09 193cat > "$TEMPFILE1" <<EOF
726f6388
JA
194From: ${USER}
195To: ${BUGADDR}
f73dda09 196Subject: ${INITIAL_SUBJECT}
726f6388
JA
197
198Configuration Information [Automatically generated, do not change]:
199Machine: $MACHINE
200OS: $OS
201Compiler: $CC
202Compilation CFLAGS: $CFLAGS
203uname output: $UN
ccc6cda3 204Machine Type: $MACHTYPE
726f6388
JA
205
206Bash Version: $RELEASE
207Patch Level: $PATCHLEVEL
ccc6cda3 208Release Status: $RELSTATUS
726f6388
JA
209
210Description:
ccc6cda3 211 [Detailed description of the problem, suggestion, or complaint.]
726f6388
JA
212
213Repeat-By:
ccc6cda3
JA
214 [Describe the sequence of events that causes the problem
215 to occur.]
726f6388
JA
216
217Fix:
ccc6cda3
JA
218 [Description of how to fix the problem. If you don't know a
219 fix for the problem, don't include this section.]
726f6388
JA
220EOF
221
f73dda09
JA
222# this is still raceable unless (hopefully) we used mktemp(1) or tempfile(1)
223$rm_tmp2 && rm -f "$TEMPFILE2"
224
225cp "$TEMPFILE1" "$TEMPFILE2"
226chmod u+w "$TEMPFILE1"
726f6388 227
ccc6cda3
JA
228trap '' 2 # ignore interrupts while in editor
229
f73dda09
JA
230edstat=1
231while [ $edstat -ne 0 ]; do
232 $EDITOR "$TEMPFILE1"
233 edstat=$?
234
235 if [ $edstat -ne 0 ]; then
236 echo "$0: editor \`$EDITOR' exited with nonzero status."
237 echo "$0: Perhaps it was interrupted."
238 echo "$0: Type \`y' to give up, and lose your bug report;"
239 echo "$0: type \`n' to re-enter the editor."
240 echo $n "$0: Do you want to give up? $c"
241
242 read ans
243 case "$ans" in
244 [Yy]*) exit 1 ;;
245 esac
246
247 continue
248 fi
249
250 # find the subject from the temp file and see if it's been changed
251 CURR_SUB=`grep '^Subject: ' "$TEMPFILE1" | sed 's|^Subject:[ ]*||' | sed 1q`
ccc6cda3 252
f73dda09
JA
253 case "$CURR_SUB" in
254 "${INITIAL_SUBJECT}")
255 echo
256 echo "$0: You have not changed the subject from the default."
257 echo "$0: Please use a more descriptive subject header."
258 echo "$0: Type \`y' to give up, and lose your bug report;"
259 echo "$0: type \`n' to re-enter the editor."
260 echo $n "$0: Do you want to give up? $c"
261
262 read ans
263 case "$ans" in
264 [Yy]*) exit 1 ;;
265 esac
266
267 echo "$0: The editor will be restarted in five seconds."
268 sleep 5
269 edstat=1
270 ;;
ccc6cda3 271 esac
f73dda09 272
ccc6cda3
JA
273done
274
f73dda09 275trap 'rm -f "$TEMPFILE1" "$TEMPFILE2"; exit 1' 2 # restore trap on SIGINT
ccc6cda3 276
f73dda09 277if cmp -s "$TEMPFILE1" "$TEMPFILE2"
726f6388 278then
ccc6cda3
JA
279 echo "File not changed, no bug report submitted."
280 exit
726f6388
JA
281fi
282
d166f048
JA
283echo $n "Send bug report? [y/n] $c"
284read ans
285case "$ans" in
286[Nn]*) exit 0 ;;
287esac
288
f73dda09
JA
289${RMAIL} $SMARGS < "$TEMPFILE1" || {
290 cat "$TEMPFILE1" >> $HOME/dead.bashbug
ccc6cda3
JA
291 echo "$0: mail failed: report saved in $HOME/dead.bashbug" >&2
292}
293
726f6388 294exit 0