3 # bashbug - create a bug report and mail it to the bug address
5 # The bug address depends on the release status of the shell. Versions
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.
8 # Other versions send mail to bug-bash@gnu.org.
10 # Copyright (C) 1996-2002 Free Software Foundation, Inc.
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)
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.
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.
27 # configuration section:
28 # these variables are filled in by the make target in Makefile
35 PATCHLEVEL="!PATCHLEVEL!"
36 RELSTATUS="!RELSTATUS!"
39 PATH=/bin:/usr/bin:/usr/local/bin:$PATH
42 # If the OS supplies a program to make temp files with semi-random names,
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
54 { TEMPFILE1=`mktemp "$TMPDIR/bbug.XXXXXX" 2>/dev/null` ; } 2>/dev/null
55 if [ -z "$TEMPFILE1" ]; then
56 { TEMPFILE1=`tempfile --prefix bbug --mode 600 2>/dev/null`; } 2>/dev/null
58 if [ -z "$TEMPFILE1" ]; then
59 TEMPFILE1=$TMPDIR/bbug.$$
62 { TEMPFILE2=`mktemp "$TMPDIR/bbug.XXXXXX" 2>/dev/null`; } 2>/dev/null
63 if [ -z "$TEMPFILE2" ]; then
64 { TEMPFILE2=`tempfile --prefix bbug --mode 600 2>/dev/null`; } 2>/dev/null
66 if [ -z "$TEMPFILE2" ]; then
67 TEMPFILE2="$TMPDIR/bbug.$$.x"
71 USAGE="Usage: $0 [--help] [--version] [bug-report-email-address]"
72 VERSTR="GNU bashbug, version ${RELEASE}.${PATCHLEVEL}-${RELSTATUS}"
76 while [ $# -gt 0 ]; do
78 --help) shift ; do_help=y ;;
79 --version) shift ; do_version=y ;;
81 -*) echo "bashbug: ${1}: invalid option" >&2
88 if [ -n "$do_version" ]; then
93 if [ -n "$do_help" ]; then
98 Bashbug is used to send mail to the Bash maintainers
99 for when Bash doesn't behave like you'd like, or expect.
101 Bashbug will start up your editor (as defined by the shell's
102 EDITOR environment variable) with a preformatted bug report
103 template for you to fill in. The report will be mailed to the
104 bash maintainers by default. See the manual for details.
106 If you invoke bashbug by accident, just quit your editor without
107 saving any changes to the template, and no bug report will be sent.
112 # Figure out how to echo a string without a trailing newline
113 N=`echo 'hi there\c'`
119 BASHTESTERS="bash-testers@po.cwru.edu"
122 alpha*|beta*|devel*|rc*) BUGBASH=chet@po.cwru.edu ;;
123 *) BUGBASH=bug-bash@gnu.org ;;
127 alpha*|beta*|devel*|rc*)
128 echo "$0: This is a testing release. Would you like your bug report"
129 echo "$0: to be sent to the bash-testers mailing list?"
130 echo $n "$0: Send to bash-testers? $c"
133 y*|Y*) BUGBASH="${BUGBASH},${BASHTESTERS}" ;;
137 BUGADDR="${1-$BUGBASH}"
139 if [ -z "$DEFEDITOR" ] && [ -z "$EDITOR" ]; then
140 if [ -x /usr/bin/editor ]; then
142 elif [ -x /usr/local/bin/ce ]; then
144 elif [ -x /usr/local/bin/emacs ]; then
146 elif [ -x /usr/contrib/bin/emacs ]; then
148 elif [ -x /usr/bin/emacs ]; then
150 elif [ -x /usr/bin/xemacs ]; then
152 elif [ -x /usr/contrib/bin/jove ]; then
154 elif [ -x /usr/local/bin/jove ]; then
156 elif [ -x /usr/bin/vi ]; then
159 echo "$0: No default editor found: attempting to use vi" >&2
165 : ${EDITOR=$DEFEDITOR}
167 : ${USER=${LOGNAME-`whoami`}}
169 trap 'rm -f "$TEMPFILE1" "$TEMPFILE2"; exit 1' 1 2 3 13 15
170 trap 'rm -f "$TEMPFILE1" "$TEMPFILE2"' 0
173 if (uname) >/dev/null 2>&1; then
177 if [ -f /usr/lib/sendmail ] ; then
178 RMAIL="/usr/lib/sendmail"
180 elif [ -f /usr/sbin/sendmail ] ; then
181 RMAIL="/usr/sbin/sendmail"
188 INITIAL_SUBJECT='[50 character or so descriptive subject here (for reference)]'
190 # this is raceable unless (hopefully) we used mktemp(1) or tempfile(1)
191 $rm_tmp1 && rm -f "$TEMPFILE1"
193 cat > "$TEMPFILE1" <<EOF
196 Subject: ${INITIAL_SUBJECT}
198 Configuration Information [Automatically generated, do not change]:
202 Compilation CFLAGS: $CFLAGS
204 Machine Type: $MACHTYPE
206 Bash Version: $RELEASE
207 Patch Level: $PATCHLEVEL
208 Release Status: $RELSTATUS
211 [Detailed description of the problem, suggestion, or complaint.]
214 [Describe the sequence of events that causes the problem
218 [Description of how to fix the problem. If you don't know a
219 fix for the problem, don't include this section.]
222 # this is still raceable unless (hopefully) we used mktemp(1) or tempfile(1)
223 $rm_tmp2 && rm -f "$TEMPFILE2"
225 cp "$TEMPFILE1" "$TEMPFILE2"
226 chmod u+w "$TEMPFILE1"
228 trap '' 2 # ignore interrupts while in editor
231 while [ $edstat -ne 0 ]; do
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"
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`
254 "${INITIAL_SUBJECT}")
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"
267 echo "$0: The editor will be restarted in five seconds."
275 trap 'rm -f "$TEMPFILE1" "$TEMPFILE2"; exit 1' 2 # restore trap on SIGINT
277 if cmp -s "$TEMPFILE1" "$TEMPFILE2"
279 echo "File not changed, no bug report submitted."
283 echo $n "Send bug report? [y/n] $c"
289 ${RMAIL} $SMARGS < "$TEMPFILE1" || {
290 cat "$TEMPFILE1" >> $HOME/dead.bashbug
291 echo "$0: mail failed: report saved in $HOME/dead.bashbug" >&2