blob: 01e9f01470008212985aa3a96f8bf424b01b3017 [file] [log] [blame]
Jari Aalto726f6381996-08-26 18:22:31 +00001#!/bin/sh -
2#
Jari Aaltoccc6cda1996-12-23 17:02:34 +00003# 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
Jari Aaltof73dda02001-11-13 17:56:06 +00006# with status `devel', `alpha', `beta', or `rc' mail bug reports to
Jari Aaltob80f6442004-07-27 13:29:18 +00007# chet@cwru.edu and, optionally, to bash-testers@cwru.edu.
Jari Aaltocce855b1998-04-17 19:52:44 +00008# Other versions send mail to bug-bash@gnu.org.
Jari Aalto726f6381996-08-26 18:22:31 +00009#
Chet Ramey8868eda2020-12-06 15:51:17 -050010# Copyright (C) 1996-2020 Free Software Foundation, Inc.
Jari Aalto7117c2d2002-07-17 14:10:11 +000011#
Jari Aalto31859422009-01-12 13:36:28 +000012# 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 3 of the License, or
15# (at your option) any later version.
Jari Aalto7117c2d2002-07-17 14:10:11 +000016#
Jari Aalto31859422009-01-12 13:36:28 +000017# 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.
Jari Aalto7117c2d2002-07-17 14:10:11 +000021#
Jari Aalto31859422009-01-12 13:36:28 +000022# You should have received a copy of the GNU General Public License
23# along with this program. If not, see <http://www.gnu.org/licenses/>.
Jari Aalto7117c2d2002-07-17 14:10:11 +000024
25#
Jari Aalto726f6381996-08-26 18:22:31 +000026# configuration section:
Jari Aaltof73dda02001-11-13 17:56:06 +000027# these variables are filled in by the make target in Makefile
Jari Aalto726f6381996-08-26 18:22:31 +000028#
Jari Aaltoccc6cda1996-12-23 17:02:34 +000029MACHINE="!MACHINE!"
30OS="!OS!"
31CC="!CC!"
32CFLAGS="!CFLAGS!"
33RELEASE="!RELEASE!"
34PATCHLEVEL="!PATCHLEVEL!"
35RELSTATUS="!RELSTATUS!"
36MACHTYPE="!MACHTYPE!"
Jari Aalto726f6381996-08-26 18:22:31 +000037
Jari Aaltoccc6cda1996-12-23 17:02:34 +000038PATH=/bin:/usr/bin:/usr/local/bin:$PATH
Jari Aalto726f6381996-08-26 18:22:31 +000039export PATH
40
Jari Aaltob80f6442004-07-27 13:29:18 +000041# Check if TMPDIR is set, default to /tmp
Jari Aaltof73dda02001-11-13 17:56:06 +000042: ${TMPDIR:=/tmp}
Jari Aaltof73dda02001-11-13 17:56:06 +000043
Jari Aaltob80f6442004-07-27 13:29:18 +000044#Securely create a temporary directory for the temporary files
45TEMPDIR=$TMPDIR/bbug.$$
Chet Ramey8868eda2020-12-06 15:51:17 -050046(umask 077 && mkdir "$TEMPDIR") || {
Jari Aaltob80f6442004-07-27 13:29:18 +000047 echo "$0: could not create temporary directory" >&2
48 exit 1
49}
Jari Aaltof73dda02001-11-13 17:56:06 +000050
Jari Aaltob80f6442004-07-27 13:29:18 +000051TEMPFILE1=$TEMPDIR/bbug1
52TEMPFILE2=$TEMPDIR/bbug2
53
Jari Aaltobb706242000-03-17 21:46:59 +000054USAGE="Usage: $0 [--help] [--version] [bug-report-email-address]"
55VERSTR="GNU bashbug, version ${RELEASE}.${PATCHLEVEL}-${RELSTATUS}"
56
57do_help= do_version=
58
59while [ $# -gt 0 ]; do
60 case "$1" in
61 --help) shift ; do_help=y ;;
62 --version) shift ; do_version=y ;;
63 --) shift ; break ;;
64 -*) echo "bashbug: ${1}: invalid option" >&2
Chet Rameya0c0a002016-09-15 16:59:08 -040065 echo "$USAGE" >&2
Jari Aaltobb706242000-03-17 21:46:59 +000066 exit 2 ;;
67 *) break ;;
68 esac
69done
70
71if [ -n "$do_version" ]; then
72 echo "${VERSTR}"
73 exit 0
74fi
75
76if [ -n "$do_help" ]; then
77 echo "${VERSTR}"
78 echo "${USAGE}"
79 echo
80 cat << HERE_EOF
81Bashbug is used to send mail to the Bash maintainers
82for when Bash doesn't behave like you'd like, or expect.
83
84Bashbug will start up your editor (as defined by the shell's
85EDITOR environment variable) with a preformatted bug report
86template for you to fill in. The report will be mailed to the
Chet Ramey00018032011-11-21 20:51:19 -050087bug-bash mailing list by default. See the manual for details.
Jari Aaltobb706242000-03-17 21:46:59 +000088
89If you invoke bashbug by accident, just quit your editor without
90saving any changes to the template, and no bug report will be sent.
91HERE_EOF
92 exit 0
93fi
Jari Aaltod166f041997-06-05 14:59:13 +000094
95# Figure out how to echo a string without a trailing newline
96N=`echo 'hi there\c'`
97case "$N" in
98*c) n=-n c= ;;
99*) n= c='\c' ;;
100esac
101
Jari Aaltob80f6442004-07-27 13:29:18 +0000102BASHTESTERS="bash-testers@cwru.edu"
Jari Aalto726f6381996-08-26 18:22:31 +0000103
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000104case "$RELSTATUS" in
Jari Aaltob80f6442004-07-27 13:29:18 +0000105alpha*|beta*|devel*|rc*) BUGBASH=chet@cwru.edu ;;
Jari Aaltof73dda02001-11-13 17:56:06 +0000106*) BUGBASH=bug-bash@gnu.org ;;
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000107esac
108
Jari Aaltod166f041997-06-05 14:59:13 +0000109case "$RELSTATUS" in
Jari Aaltof73dda02001-11-13 17:56:06 +0000110alpha*|beta*|devel*|rc*)
Jari Aaltobb706242000-03-17 21:46:59 +0000111 echo "$0: This is a testing release. Would you like your bug report"
Jari Aaltod166f041997-06-05 14:59:13 +0000112 echo "$0: to be sent to the bash-testers mailing list?"
113 echo $n "$0: Send to bash-testers? $c"
114 read ans
115 case "$ans" in
116 y*|Y*) BUGBASH="${BUGBASH},${BASHTESTERS}" ;;
117 esac ;;
118esac
119
120BUGADDR="${1-$BUGBASH}"
Jari Aalto726f6381996-08-26 18:22:31 +0000121
Jari Aaltobb706242000-03-17 21:46:59 +0000122if [ -z "$DEFEDITOR" ] && [ -z "$EDITOR" ]; then
Jari Aalto28ef6c32001-04-06 19:14:31 +0000123 if [ -x /usr/bin/editor ]; then
124 DEFEDITOR=editor
125 elif [ -x /usr/local/bin/ce ]; then
Jari Aaltobb706242000-03-17 21:46:59 +0000126 DEFEDITOR=ce
127 elif [ -x /usr/local/bin/emacs ]; then
128 DEFEDITOR=emacs
129 elif [ -x /usr/contrib/bin/emacs ]; then
130 DEFEDITOR=emacs
131 elif [ -x /usr/bin/emacs ]; then
132 DEFEDITOR=emacs
133 elif [ -x /usr/bin/xemacs ]; then
134 DEFEDITOR=xemacs
Chet Ramey8868eda2020-12-06 15:51:17 -0500135 elif [ -x /usr/bin/nano ]; then
136 DEFEDITOR=nano
Jari Aaltobb706242000-03-17 21:46:59 +0000137 elif [ -x /usr/contrib/bin/jove ]; then
138 DEFEDITOR=jove
139 elif [ -x /usr/local/bin/jove ]; then
140 DEFEDITOR=jove
141 elif [ -x /usr/bin/vi ]; then
142 DEFEDITOR=vi
143 else
144 echo "$0: No default editor found: attempting to use vi" >&2
145 DEFEDITOR=vi
146 fi
147fi
148
149
150: ${EDITOR=$DEFEDITOR}
Jari Aalto726f6381996-08-26 18:22:31 +0000151
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000152: ${USER=${LOGNAME-`whoami`}}
153
Jari Aaltob80f6442004-07-27 13:29:18 +0000154trap 'rm -rf "$TEMPDIR"; exit 1' 1 2 3 13 15
155trap 'rm -rf "$TEMPDIR"' 0
Jari Aalto726f6381996-08-26 18:22:31 +0000156
157UN=
158if (uname) >/dev/null 2>&1; then
159 UN=`uname -a`
160fi
161
162if [ -f /usr/lib/sendmail ] ; then
163 RMAIL="/usr/lib/sendmail"
Jari Aaltobb706242000-03-17 21:46:59 +0000164 SMARGS="-i -t"
Jari Aalto726f6381996-08-26 18:22:31 +0000165elif [ -f /usr/sbin/sendmail ] ; then
166 RMAIL="/usr/sbin/sendmail"
Jari Aaltobb706242000-03-17 21:46:59 +0000167 SMARGS="-i -t"
Jari Aalto726f6381996-08-26 18:22:31 +0000168else
169 RMAIL=rmail
Jari Aaltobb706242000-03-17 21:46:59 +0000170 SMARGS="$BUGADDR"
Jari Aalto726f6381996-08-26 18:22:31 +0000171fi
172
Jari Aaltof73dda02001-11-13 17:56:06 +0000173INITIAL_SUBJECT='[50 character or so descriptive subject here (for reference)]'
Jari Aaltocce855b1998-04-17 19:52:44 +0000174
Jari Aaltof73dda02001-11-13 17:56:06 +0000175cat > "$TEMPFILE1" <<EOF
Jari Aalto726f6381996-08-26 18:22:31 +0000176From: ${USER}
177To: ${BUGADDR}
Jari Aaltof73dda02001-11-13 17:56:06 +0000178Subject: ${INITIAL_SUBJECT}
Jari Aalto726f6381996-08-26 18:22:31 +0000179
180Configuration Information [Automatically generated, do not change]:
181Machine: $MACHINE
182OS: $OS
183Compiler: $CC
184Compilation CFLAGS: $CFLAGS
185uname output: $UN
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000186Machine Type: $MACHTYPE
Jari Aalto726f6381996-08-26 18:22:31 +0000187
188Bash Version: $RELEASE
189Patch Level: $PATCHLEVEL
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000190Release Status: $RELSTATUS
Jari Aalto726f6381996-08-26 18:22:31 +0000191
192Description:
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000193 [Detailed description of the problem, suggestion, or complaint.]
Jari Aalto726f6381996-08-26 18:22:31 +0000194
195Repeat-By:
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000196 [Describe the sequence of events that causes the problem
197 to occur.]
Jari Aalto726f6381996-08-26 18:22:31 +0000198
199Fix:
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000200 [Description of how to fix the problem. If you don't know a
201 fix for the problem, don't include this section.]
Jari Aalto726f6381996-08-26 18:22:31 +0000202EOF
203
Jari Aaltof73dda02001-11-13 17:56:06 +0000204cp "$TEMPFILE1" "$TEMPFILE2"
205chmod u+w "$TEMPFILE1"
Jari Aalto726f6381996-08-26 18:22:31 +0000206
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000207trap '' 2 # ignore interrupts while in editor
208
Jari Aaltof73dda02001-11-13 17:56:06 +0000209edstat=1
210while [ $edstat -ne 0 ]; do
211 $EDITOR "$TEMPFILE1"
212 edstat=$?
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000213
Jari Aaltof73dda02001-11-13 17:56:06 +0000214 if [ $edstat -ne 0 ]; then
215 echo "$0: editor \`$EDITOR' exited with nonzero status."
216 echo "$0: Perhaps it was interrupted."
217 echo "$0: Type \`y' to give up, and lose your bug report;"
218 echo "$0: type \`n' to re-enter the editor."
219 echo $n "$0: Do you want to give up? $c"
220
221 read ans
222 case "$ans" in
223 [Yy]*) exit 1 ;;
224 esac
225
226 continue
227 fi
228
229 # find the subject from the temp file and see if it's been changed
230 CURR_SUB=`grep '^Subject: ' "$TEMPFILE1" | sed 's|^Subject:[ ]*||' | sed 1q`
231
232 case "$CURR_SUB" in
233 "${INITIAL_SUBJECT}")
234 echo
235 echo "$0: You have not changed the subject from the default."
236 echo "$0: Please use a more descriptive subject header."
237 echo "$0: Type \`y' to give up, and lose your bug report;"
238 echo "$0: type \`n' to re-enter the editor."
239 echo $n "$0: Do you want to give up? $c"
240
241 read ans
242 case "$ans" in
243 [Yy]*) exit 1 ;;
244 esac
245
246 echo "$0: The editor will be restarted in five seconds."
247 sleep 5
248 edstat=1
249 ;;
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000250 esac
Jari Aaltof73dda02001-11-13 17:56:06 +0000251
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000252done
253
Jari Aaltob80f6442004-07-27 13:29:18 +0000254trap 'rm -rf "$TEMPDIR"; exit 1' 2 # restore trap on SIGINT
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000255
Jari Aaltof73dda02001-11-13 17:56:06 +0000256if cmp -s "$TEMPFILE1" "$TEMPFILE2"
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000257then
258 echo "File not changed, no bug report submitted."
259 exit
Jari Aalto726f6381996-08-26 18:22:31 +0000260fi
261
Chet Ramey00018032011-11-21 20:51:19 -0500262echo $n "Send bug report to ${BUGADDR}? [y/n] $c"
Jari Aaltod166f041997-06-05 14:59:13 +0000263read ans
264case "$ans" in
265[Nn]*) exit 0 ;;
266esac
267
Jari Aaltof73dda02001-11-13 17:56:06 +0000268${RMAIL} $SMARGS < "$TEMPFILE1" || {
269 cat "$TEMPFILE1" >> $HOME/dead.bashbug
Chet Rameya0c0a002016-09-15 16:59:08 -0400270 echo "$0: mail to ${BUGADDR} failed: report saved in $HOME/dead.bashbug" >&2
271 echo "$0: please send it manually to ${BUGADDR}" >&2
Jari Aaltoccc6cda1996-12-23 17:02:34 +0000272}
273
Jari Aalto726f6381996-08-26 18:22:31 +0000274exit 0