]> git.ipfire.org Git - thirdparty/bash.git/blame - support/bashbug.sh
Imported from ../bash-2.05.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
6# with status `alpha' or `beta' mail bug reports to chet@po.cwru.edu.
cce855bc 7# Other versions send mail to bug-bash@gnu.org.
726f6388
JA
8#
9# configuration section:
10# these variables are filled in by the make target in cpp-Makefile
11#
ccc6cda3
JA
12MACHINE="!MACHINE!"
13OS="!OS!"
14CC="!CC!"
15CFLAGS="!CFLAGS!"
16RELEASE="!RELEASE!"
17PATCHLEVEL="!PATCHLEVEL!"
18RELSTATUS="!RELSTATUS!"
19MACHTYPE="!MACHTYPE!"
20
21PATH=/bin:/usr/bin:/usr/local/bin:$PATH
726f6388
JA
22export PATH
23
28ef6c31
JA
24# If the OS supplies a program to make temp files with semi-random names,
25# use it.
d166f048 26TEMP=/tmp/bbug.$$
28ef6c31
JA
27for d in /bin /usr/bin /usr/local/bin ; do
28 if [ -x $d/mktemp ]; then
29 TEMP=`$d/mktemp -t bbug ` ; break;
30 elif [ -x $d/tempfile ]; then
31 TEMP=` $d/tempfile --prefix bbug --mode 600 `; break
32 fi
33done
34
bb70624e
JA
35USAGE="Usage: $0 [--help] [--version] [bug-report-email-address]"
36VERSTR="GNU bashbug, version ${RELEASE}.${PATCHLEVEL}-${RELSTATUS}"
37
38do_help= do_version=
39
40while [ $# -gt 0 ]; do
41 case "$1" in
42 --help) shift ; do_help=y ;;
43 --version) shift ; do_version=y ;;
44 --) shift ; break ;;
45 -*) echo "bashbug: ${1}: invalid option" >&2
46 echo "$USAGE" >& 2
47 exit 2 ;;
48 *) break ;;
49 esac
50done
51
52if [ -n "$do_version" ]; then
53 echo "${VERSTR}"
54 exit 0
55fi
56
57if [ -n "$do_help" ]; then
58 echo "${VERSTR}"
59 echo "${USAGE}"
60 echo
61 cat << HERE_EOF
62Bashbug is used to send mail to the Bash maintainers
63for when Bash doesn't behave like you'd like, or expect.
64
65Bashbug will start up your editor (as defined by the shell's
66EDITOR environment variable) with a preformatted bug report
67template for you to fill in. The report will be mailed to the
68bash maintainers by default. See the manual for details.
69
70If you invoke bashbug by accident, just quit your editor without
71saving any changes to the template, and no bug report will be sent.
72HERE_EOF
73 exit 0
74fi
d166f048
JA
75
76# Figure out how to echo a string without a trailing newline
77N=`echo 'hi there\c'`
78case "$N" in
79*c) n=-n c= ;;
80*) n= c='\c' ;;
81esac
82
83BASHTESTERS="bash-testers@po.cwru.edu"
726f6388 84
ccc6cda3 85case "$RELSTATUS" in
bb70624e
JA
86alpha*|beta*|devel*) BUGBASH=chet@po.cwru.edu ;;
87*) BUGBASH=bug-bash@gnu.org ;;
ccc6cda3
JA
88esac
89
d166f048 90case "$RELSTATUS" in
bb70624e
JA
91alpha*|beta*|devel*)
92 echo "$0: This is a testing release. Would you like your bug report"
d166f048
JA
93 echo "$0: to be sent to the bash-testers mailing list?"
94 echo $n "$0: Send to bash-testers? $c"
95 read ans
96 case "$ans" in
97 y*|Y*) BUGBASH="${BUGBASH},${BASHTESTERS}" ;;
98 esac ;;
99esac
100
101BUGADDR="${1-$BUGBASH}"
726f6388 102
bb70624e 103if [ -z "$DEFEDITOR" ] && [ -z "$EDITOR" ]; then
28ef6c31
JA
104 if [ -x /usr/bin/editor ]; then
105 DEFEDITOR=editor
106 elif [ -x /usr/local/bin/ce ]; then
bb70624e
JA
107 DEFEDITOR=ce
108 elif [ -x /usr/local/bin/emacs ]; then
109 DEFEDITOR=emacs
110 elif [ -x /usr/contrib/bin/emacs ]; then
111 DEFEDITOR=emacs
112 elif [ -x /usr/bin/emacs ]; then
113 DEFEDITOR=emacs
114 elif [ -x /usr/bin/xemacs ]; then
115 DEFEDITOR=xemacs
116 elif [ -x /usr/contrib/bin/jove ]; then
117 DEFEDITOR=jove
118 elif [ -x /usr/local/bin/jove ]; then
119 DEFEDITOR=jove
120 elif [ -x /usr/bin/vi ]; then
121 DEFEDITOR=vi
122 else
123 echo "$0: No default editor found: attempting to use vi" >&2
124 DEFEDITOR=vi
125 fi
126fi
127
128
129: ${EDITOR=$DEFEDITOR}
726f6388 130
ccc6cda3
JA
131: ${USER=${LOGNAME-`whoami`}}
132
726f6388
JA
133trap 'rm -f $TEMP $TEMP.x; exit 1' 1 2 3 13 15
134trap 'rm -f $TEMP $TEMP.x' 0
135
136UN=
137if (uname) >/dev/null 2>&1; then
138 UN=`uname -a`
139fi
140
141if [ -f /usr/lib/sendmail ] ; then
142 RMAIL="/usr/lib/sendmail"
bb70624e 143 SMARGS="-i -t"
726f6388
JA
144elif [ -f /usr/sbin/sendmail ] ; then
145 RMAIL="/usr/sbin/sendmail"
bb70624e 146 SMARGS="-i -t"
726f6388
JA
147else
148 RMAIL=rmail
bb70624e 149 SMARGS="$BUGADDR"
726f6388
JA
150fi
151
cce855bc
JA
152# this is raceable
153rm -f $TEMP
154
726f6388
JA
155cat > $TEMP <<EOF
156From: ${USER}
157To: ${BUGADDR}
158Subject: [50 character or so descriptive subject here (for reference)]
159
160Configuration Information [Automatically generated, do not change]:
161Machine: $MACHINE
162OS: $OS
163Compiler: $CC
164Compilation CFLAGS: $CFLAGS
165uname output: $UN
ccc6cda3 166Machine Type: $MACHTYPE
726f6388
JA
167
168Bash Version: $RELEASE
169Patch Level: $PATCHLEVEL
ccc6cda3 170Release Status: $RELSTATUS
726f6388
JA
171
172Description:
ccc6cda3 173 [Detailed description of the problem, suggestion, or complaint.]
726f6388
JA
174
175Repeat-By:
ccc6cda3
JA
176 [Describe the sequence of events that causes the problem
177 to occur.]
726f6388
JA
178
179Fix:
ccc6cda3
JA
180 [Description of how to fix the problem. If you don't know a
181 fix for the problem, don't include this section.]
726f6388
JA
182EOF
183
cce855bc
JA
184# this is still raceable
185rm -f $TEMP.x
726f6388 186cp $TEMP $TEMP.x
cce855bc 187chmod u+w $TEMP
726f6388 188
ccc6cda3
JA
189trap '' 2 # ignore interrupts while in editor
190
191until $EDITOR $TEMP; do
192 echo "$0: editor \`$EDITOR' exited with nonzero status."
193 echo "$0: Perhaps it was interrupted."
d166f048
JA
194 echo "$0: Type \`y' to give up, and lose your bug report;"
195 echo "$0: type \`n' to re-enter the editor."
ccc6cda3
JA
196 echo $n "$0: Do you want to give up? $c"
197
198 read ans
199 case "$ans" in
d166f048 200 [Yy]*) exit 1 ;;
ccc6cda3
JA
201 esac
202done
203
204trap 'rm -f $TEMP $TEMP.x; exit 1' 2 # restore trap on SIGINT
205
206if cmp -s $TEMP $TEMP.x
726f6388 207then
ccc6cda3
JA
208 echo "File not changed, no bug report submitted."
209 exit
726f6388
JA
210fi
211
d166f048
JA
212echo $n "Send bug report? [y/n] $c"
213read ans
214case "$ans" in
215[Nn]*) exit 0 ;;
216esac
217
bb70624e 218${RMAIL} $SMARGS < $TEMP || {
ccc6cda3
JA
219 cat $TEMP >> $HOME/dead.bashbug
220 echo "$0: mail failed: report saved in $HOME/dead.bashbug" >&2
221}
222
726f6388 223exit 0