| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 1 | #!/bin/sh - |
| 2 | # |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 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 |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 6 | # with status `devel', `alpha', `beta', or `rc' mail bug reports to |
| Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 7 | # chet@cwru.edu and, optionally, to bash-testers@cwru.edu. |
| Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 8 | # Other versions send mail to bug-bash@gnu.org. |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 9 | # |
| Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 10 | # Copyright (C) 1996-2004 Free Software Foundation, Inc. |
| Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 11 | # |
| Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 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 3 of the License, or |
| 15 | # (at your option) any later version. |
| Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 16 | # |
| Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 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. |
| Jari Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 21 | # |
| Jari Aalto | 3185942 | 2009-01-12 13:36:28 +0000 | [diff] [blame] | 22 | # 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 Aalto | 7117c2d | 2002-07-17 14:10:11 +0000 | [diff] [blame] | 24 | |
| 25 | # |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 26 | # configuration section: |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 27 | # these variables are filled in by the make target in Makefile |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 28 | # |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 29 | MACHINE="!MACHINE!" |
| 30 | OS="!OS!" |
| 31 | CC="!CC!" |
| 32 | CFLAGS="!CFLAGS!" |
| 33 | RELEASE="!RELEASE!" |
| 34 | PATCHLEVEL="!PATCHLEVEL!" |
| 35 | RELSTATUS="!RELSTATUS!" |
| 36 | MACHTYPE="!MACHTYPE!" |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 37 | |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 38 | PATH=/bin:/usr/bin:/usr/local/bin:$PATH |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 39 | export PATH |
| 40 | |
| Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 41 | # Check if TMPDIR is set, default to /tmp |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 42 | : ${TMPDIR:=/tmp} |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 43 | |
| Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 44 | #Securely create a temporary directory for the temporary files |
| 45 | TEMPDIR=$TMPDIR/bbug.$$ |
| 46 | (umask 077 && mkdir $TEMPDIR) || { |
| 47 | echo "$0: could not create temporary directory" >&2 |
| 48 | exit 1 |
| 49 | } |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 50 | |
| Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 51 | TEMPFILE1=$TEMPDIR/bbug1 |
| 52 | TEMPFILE2=$TEMPDIR/bbug2 |
| 53 | |
| Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 54 | USAGE="Usage: $0 [--help] [--version] [bug-report-email-address]" |
| 55 | VERSTR="GNU bashbug, version ${RELEASE}.${PATCHLEVEL}-${RELSTATUS}" |
| 56 | |
| 57 | do_help= do_version= |
| 58 | |
| 59 | while [ $# -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 |
| 65 | echo "$USAGE" >& 2 |
| 66 | exit 2 ;; |
| 67 | *) break ;; |
| 68 | esac |
| 69 | done |
| 70 | |
| 71 | if [ -n "$do_version" ]; then |
| 72 | echo "${VERSTR}" |
| 73 | exit 0 |
| 74 | fi |
| 75 | |
| 76 | if [ -n "$do_help" ]; then |
| 77 | echo "${VERSTR}" |
| 78 | echo "${USAGE}" |
| 79 | echo |
| 80 | cat << HERE_EOF |
| 81 | Bashbug is used to send mail to the Bash maintainers |
| 82 | for when Bash doesn't behave like you'd like, or expect. |
| 83 | |
| 84 | Bashbug will start up your editor (as defined by the shell's |
| 85 | EDITOR environment variable) with a preformatted bug report |
| 86 | template for you to fill in. The report will be mailed to the |
| Chet Ramey | 0001803 | 2011-11-21 20:51:19 -0500 | [diff] [blame^] | 87 | bug-bash mailing list by default. See the manual for details. |
| Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 88 | |
| 89 | If you invoke bashbug by accident, just quit your editor without |
| 90 | saving any changes to the template, and no bug report will be sent. |
| 91 | HERE_EOF |
| 92 | exit 0 |
| 93 | fi |
| Jari Aalto | d166f04 | 1997-06-05 14:59:13 +0000 | [diff] [blame] | 94 | |
| 95 | # Figure out how to echo a string without a trailing newline |
| 96 | N=`echo 'hi there\c'` |
| 97 | case "$N" in |
| 98 | *c) n=-n c= ;; |
| 99 | *) n= c='\c' ;; |
| 100 | esac |
| 101 | |
| Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 102 | BASHTESTERS="bash-testers@cwru.edu" |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 103 | |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 104 | case "$RELSTATUS" in |
| Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 105 | alpha*|beta*|devel*|rc*) BUGBASH=chet@cwru.edu ;; |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 106 | *) BUGBASH=bug-bash@gnu.org ;; |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 107 | esac |
| 108 | |
| Jari Aalto | d166f04 | 1997-06-05 14:59:13 +0000 | [diff] [blame] | 109 | case "$RELSTATUS" in |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 110 | alpha*|beta*|devel*|rc*) |
| Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 111 | echo "$0: This is a testing release. Would you like your bug report" |
| Jari Aalto | d166f04 | 1997-06-05 14:59:13 +0000 | [diff] [blame] | 112 | 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 ;; |
| 118 | esac |
| 119 | |
| 120 | BUGADDR="${1-$BUGBASH}" |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 121 | |
| Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 122 | if [ -z "$DEFEDITOR" ] && [ -z "$EDITOR" ]; then |
| Jari Aalto | 28ef6c3 | 2001-04-06 19:14:31 +0000 | [diff] [blame] | 123 | if [ -x /usr/bin/editor ]; then |
| 124 | DEFEDITOR=editor |
| 125 | elif [ -x /usr/local/bin/ce ]; then |
| Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 126 | 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 |
| 135 | elif [ -x /usr/contrib/bin/jove ]; then |
| 136 | DEFEDITOR=jove |
| 137 | elif [ -x /usr/local/bin/jove ]; then |
| 138 | DEFEDITOR=jove |
| 139 | elif [ -x /usr/bin/vi ]; then |
| 140 | DEFEDITOR=vi |
| 141 | else |
| 142 | echo "$0: No default editor found: attempting to use vi" >&2 |
| 143 | DEFEDITOR=vi |
| 144 | fi |
| 145 | fi |
| 146 | |
| 147 | |
| 148 | : ${EDITOR=$DEFEDITOR} |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 149 | |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 150 | : ${USER=${LOGNAME-`whoami`}} |
| 151 | |
| Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 152 | trap 'rm -rf "$TEMPDIR"; exit 1' 1 2 3 13 15 |
| 153 | trap 'rm -rf "$TEMPDIR"' 0 |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 154 | |
| 155 | UN= |
| 156 | if (uname) >/dev/null 2>&1; then |
| 157 | UN=`uname -a` |
| 158 | fi |
| 159 | |
| 160 | if [ -f /usr/lib/sendmail ] ; then |
| 161 | RMAIL="/usr/lib/sendmail" |
| Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 162 | SMARGS="-i -t" |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 163 | elif [ -f /usr/sbin/sendmail ] ; then |
| 164 | RMAIL="/usr/sbin/sendmail" |
| Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 165 | SMARGS="-i -t" |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 166 | else |
| 167 | RMAIL=rmail |
| Jari Aalto | bb70624 | 2000-03-17 21:46:59 +0000 | [diff] [blame] | 168 | SMARGS="$BUGADDR" |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 169 | fi |
| 170 | |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 171 | INITIAL_SUBJECT='[50 character or so descriptive subject here (for reference)]' |
| Jari Aalto | cce855b | 1998-04-17 19:52:44 +0000 | [diff] [blame] | 172 | |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 173 | cat > "$TEMPFILE1" <<EOF |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 174 | From: ${USER} |
| 175 | To: ${BUGADDR} |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 176 | Subject: ${INITIAL_SUBJECT} |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 177 | |
| 178 | Configuration Information [Automatically generated, do not change]: |
| 179 | Machine: $MACHINE |
| 180 | OS: $OS |
| 181 | Compiler: $CC |
| 182 | Compilation CFLAGS: $CFLAGS |
| 183 | uname output: $UN |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 184 | Machine Type: $MACHTYPE |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 185 | |
| 186 | Bash Version: $RELEASE |
| 187 | Patch Level: $PATCHLEVEL |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 188 | Release Status: $RELSTATUS |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 189 | |
| 190 | Description: |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 191 | [Detailed description of the problem, suggestion, or complaint.] |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 192 | |
| 193 | Repeat-By: |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 194 | [Describe the sequence of events that causes the problem |
| 195 | to occur.] |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 196 | |
| 197 | Fix: |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 198 | [Description of how to fix the problem. If you don't know a |
| 199 | fix for the problem, don't include this section.] |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 200 | EOF |
| 201 | |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 202 | cp "$TEMPFILE1" "$TEMPFILE2" |
| 203 | chmod u+w "$TEMPFILE1" |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 204 | |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 205 | trap '' 2 # ignore interrupts while in editor |
| 206 | |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 207 | edstat=1 |
| 208 | while [ $edstat -ne 0 ]; do |
| 209 | $EDITOR "$TEMPFILE1" |
| 210 | edstat=$? |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 211 | |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 212 | if [ $edstat -ne 0 ]; then |
| 213 | echo "$0: editor \`$EDITOR' exited with nonzero status." |
| 214 | echo "$0: Perhaps it was interrupted." |
| 215 | echo "$0: Type \`y' to give up, and lose your bug report;" |
| 216 | echo "$0: type \`n' to re-enter the editor." |
| 217 | echo $n "$0: Do you want to give up? $c" |
| 218 | |
| 219 | read ans |
| 220 | case "$ans" in |
| 221 | [Yy]*) exit 1 ;; |
| 222 | esac |
| 223 | |
| 224 | continue |
| 225 | fi |
| 226 | |
| 227 | # find the subject from the temp file and see if it's been changed |
| 228 | CURR_SUB=`grep '^Subject: ' "$TEMPFILE1" | sed 's|^Subject:[ ]*||' | sed 1q` |
| 229 | |
| 230 | case "$CURR_SUB" in |
| 231 | "${INITIAL_SUBJECT}") |
| 232 | echo |
| 233 | echo "$0: You have not changed the subject from the default." |
| 234 | echo "$0: Please use a more descriptive subject header." |
| 235 | echo "$0: Type \`y' to give up, and lose your bug report;" |
| 236 | echo "$0: type \`n' to re-enter the editor." |
| 237 | echo $n "$0: Do you want to give up? $c" |
| 238 | |
| 239 | read ans |
| 240 | case "$ans" in |
| 241 | [Yy]*) exit 1 ;; |
| 242 | esac |
| 243 | |
| 244 | echo "$0: The editor will be restarted in five seconds." |
| 245 | sleep 5 |
| 246 | edstat=1 |
| 247 | ;; |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 248 | esac |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 249 | |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 250 | done |
| 251 | |
| Jari Aalto | b80f644 | 2004-07-27 13:29:18 +0000 | [diff] [blame] | 252 | trap 'rm -rf "$TEMPDIR"; exit 1' 2 # restore trap on SIGINT |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 253 | |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 254 | if cmp -s "$TEMPFILE1" "$TEMPFILE2" |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 255 | then |
| 256 | echo "File not changed, no bug report submitted." |
| 257 | exit |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 258 | fi |
| 259 | |
| Chet Ramey | 0001803 | 2011-11-21 20:51:19 -0500 | [diff] [blame^] | 260 | echo $n "Send bug report to ${BUGADDR}? [y/n] $c" |
| Jari Aalto | d166f04 | 1997-06-05 14:59:13 +0000 | [diff] [blame] | 261 | read ans |
| 262 | case "$ans" in |
| 263 | [Nn]*) exit 0 ;; |
| 264 | esac |
| 265 | |
| Jari Aalto | f73dda0 | 2001-11-13 17:56:06 +0000 | [diff] [blame] | 266 | ${RMAIL} $SMARGS < "$TEMPFILE1" || { |
| 267 | cat "$TEMPFILE1" >> $HOME/dead.bashbug |
| Jari Aalto | ccc6cda | 1996-12-23 17:02:34 +0000 | [diff] [blame] | 268 | echo "$0: mail failed: report saved in $HOME/dead.bashbug" >&2 |
| 269 | } |
| 270 | |
| Jari Aalto | 726f638 | 1996-08-26 18:22:31 +0000 | [diff] [blame] | 271 | exit 0 |