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