codekingpro/portable-devtools
115k
1#!/bin/sh -2#3# bashbug - create a bug report and mail it to the bug address4#5# The bug address depends on the release status of the shell. Versions6# with status `devel', `alpha', `beta', or `rc' mail bug reports to7# chet.ramey@case.edu and, optionally, to bash-testers@cwru.edu.8# Other versions send mail to bug-bash@gnu.org.9#10# Copyright (C) 1996-2021 Free Software Foundation, Inc.11#12# This program is free software: you can redistribute it and/or modify13# it under the terms of the GNU General Public License as published by14# the Free Software Foundation, either version 3 of the License, or15# (at your option) any later version.16#17# This program is distributed in the hope that it will be useful,18# but WITHOUT ANY WARRANTY; without even the implied warranty of19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the20# GNU General Public License for more details.21#22# You should have received a copy of the GNU General Public License23# along with this program. If not, see <http://www.gnu.org/licenses/>.24 25#26# configuration section:27# these variables are filled in by the make target in Makefile28#29MACHINE="x86_64"30OS="cygwin"31CC="gcc"32CFLAGS="-march=nocona -msahf -mtune=generic -O2 -pipe -D_STATIC_BUILD"33RELEASE="5.3"34PATCHLEVEL="9"35RELSTATUS="release"36MACHTYPE="x86_64-pc-cygwin"37 38PATH=/bin:/usr/bin:/usr/local/bin:$PATH39export PATH40 41# Check if TMPDIR is set, default to /tmp42: ${TMPDIR:=/tmp}43 44#Securely create a temporary directory for the temporary files45TEMPDIR=$TMPDIR/bbug.$$46(umask 077 && mkdir "$TEMPDIR") || {47 echo "$0: could not create temporary directory" >&248 exit 149}50 51TEMPFILE1=$TEMPDIR/bbug152TEMPFILE2=$TEMPDIR/bbug253 54USAGE="Usage: $0 [--help] [--version] [bug-report-email-address]"55VERSTR="GNU bashbug, version ${RELEASE}.${PATCHLEVEL}-${RELSTATUS}"56 57do_help= do_version=58 59while [ $# -gt 0 ]; do60 case "$1" in61 --help) shift ; do_help=y ;;62 --version) shift ; do_version=y ;;63 --) shift ; break ;;64 -*) echo "bashbug: ${1}: invalid option" >&265 echo "$USAGE" >&266 exit 2 ;;67 *) break ;;68 esac69done70 71if [ -n "$do_version" ]; then72 echo "${VERSTR}"73 exit 074fi75 76if [ -n "$do_help" ]; then77 echo "${VERSTR}"78 echo "${USAGE}"79 echo80 cat << HERE_EOF81Bashbug is used to send mail to the Bash maintainers82for when Bash doesn't behave like you'd like, or expect.83 84Bashbug will start up your editor (as defined by the shell's85EDITOR environment variable) with a preformatted bug report86template for you to fill in. The report will be mailed to the87bug-bash mailing list by default. See the manual for details.88 89If you invoke bashbug by accident, just quit your editor without90saving any changes to the template, and no bug report will be sent.91HERE_EOF92 exit 093fi94 95# Figure out how to echo a string without a trailing newline96N=`echo 'hi there\c'`97case "$N" in98*c) n=-n c= ;;99*) n= c='\c' ;;100esac101 102BASHTESTERS="bash-testers@cwru.edu"103 104case "$RELSTATUS" in105alpha*|beta*|devel*|rc*) BUGBASH=chet.ramey@case.edu ;;106*) BUGBASH=bug-bash@gnu.org ;;107esac108 109case "$RELSTATUS" in110alpha*|beta*|devel*|rc*)111 echo "$0: This is a testing release. Would you like your bug report"112 echo "$0: to be sent to the bash-testers mailing list?"113 echo $n "$0: Send to bash-testers? $c"114 read ans115 case "$ans" in116 y*|Y*) BUGBASH="${BUGBASH},${BASHTESTERS}" ;;117 esac ;;118esac119 120BUGADDR="${1-$BUGBASH}"121 122if [ -z "$DEFEDITOR" ] && [ -z "$EDITOR" ]; then123 if [ -x /usr/bin/editor ]; then124 DEFEDITOR=editor125 elif [ -x /usr/local/bin/ce ]; then126 DEFEDITOR=ce127 elif [ -x /usr/local/bin/emacs ]; then128 DEFEDITOR=emacs129 elif [ -x /usr/contrib/bin/emacs ]; then130 DEFEDITOR=emacs131 elif [ -x /usr/bin/emacs ]; then132 DEFEDITOR=emacs133 elif [ -x /usr/bin/xemacs ]; then134 DEFEDITOR=xemacs135 elif [ -x /usr/bin/vim ]; then136 DEFEDITOR=vim137 elif [ -x /usr/bin/gvim ]; then138 DEFEDITOR=gvim139 elif [ -x /usr/bin/nano ]; then140 DEFEDITOR=nano141 elif [ -x /usr/contrib/bin/jove ]; then142 DEFEDITOR=jove143 elif [ -x /usr/local/bin/jove ]; then144 DEFEDITOR=jove145 elif [ -x /usr/bin/vi ]; then146 DEFEDITOR=vi147 else148 echo "$0: No default editor found: attempting to use vi" >&2149 DEFEDITOR=vi150 fi151fi152 153 154: ${EDITOR=$DEFEDITOR}155 156: ${USER=${LOGNAME-`whoami`}}157 158trap 'rm -rf "$TEMPDIR"; exit 1' 1 2 3 13 15159trap 'rm -rf "$TEMPDIR"' 0160 161UN=162if (uname) >/dev/null 2>&1; then163 UN=`uname -a`164fi165 166if [ -f /usr/lib/sendmail ] ; then167 RMAIL="/usr/lib/sendmail"168 SMARGS="-i -t"169elif [ -f /usr/sbin/sendmail ] ; then170 RMAIL="/usr/sbin/sendmail"171 SMARGS="-i -t"172else173 RMAIL=rmail174 SMARGS="$BUGADDR"175fi176 177INITIAL_SUBJECT='[50 character or so descriptive subject here (for reference)]'178 179cat > "$TEMPFILE1" <<EOF180From: ${USER}181To: ${BUGADDR}182Subject: ${INITIAL_SUBJECT}183 184Configuration Information [Automatically generated, do not change]:185Machine: $MACHINE186OS: $OS187Compiler: $CC188Compilation CFLAGS: $CFLAGS189uname output: $UN190Machine Type: $MACHTYPE191 192Bash Version: $RELEASE193Patch Level: $PATCHLEVEL194Release Status: $RELSTATUS195 196Description:197 [Detailed description of the problem, suggestion, or complaint.]198 199Repeat-By:200 [Describe the sequence of events that causes the problem201 to occur.]202 203Fix:204 [Description of how to fix the problem. If you don't know a205 fix for the problem, don't include this section.]206EOF207 208cp "$TEMPFILE1" "$TEMPFILE2"209chmod u+w "$TEMPFILE1"210 211trap '' 2 # ignore interrupts while in editor212 213edstat=1214while [ $edstat -ne 0 ]; do215 $EDITOR "$TEMPFILE1"216 edstat=$?217 218 if [ $edstat -ne 0 ]; then219 echo "$0: editor \`$EDITOR' exited with nonzero status."220 echo "$0: Perhaps it was interrupted."221 echo "$0: Type \`y' to give up, and lose your bug report;"222 echo "$0: type \`n' to re-enter the editor."223 echo $n "$0: Do you want to give up? $c"224 225 read ans226 case "$ans" in227 [Yy]*) exit 1 ;;228 esac229 230 continue231 fi232 233 # find the subject from the temp file and see if it's been changed234 CURR_SUB=`grep '^Subject: ' "$TEMPFILE1" | sed 's|^Subject:[ ]*||' | sed 1q`235 236 case "$CURR_SUB" in237 "${INITIAL_SUBJECT}")238 echo239 echo "$0: You have not changed the subject from the default."240 echo "$0: Please use a more descriptive subject header."241 echo "$0: Type \`y' to give up, and lose your bug report;"242 echo "$0: type \`n' to re-enter the editor."243 echo $n "$0: Do you want to give up? $c"244 245 read ans246 case "$ans" in247 [Yy]*) exit 1 ;;248 esac249 250 echo "$0: The editor will be restarted in five seconds."251 sleep 5252 edstat=1253 ;;254 esac255 256done257 258trap 'rm -rf "$TEMPDIR"; exit 1' 2 # restore trap on SIGINT259 260if cmp -s "$TEMPFILE1" "$TEMPFILE2"261then262 echo "File not changed, no bug report submitted."263 exit264fi265 266echo $n "Send bug report to ${BUGADDR}? [y/n] $c"267read ans268case "$ans" in269[Nn]*) exit 0 ;;270esac271 272${RMAIL} $SMARGS < "$TEMPFILE1" || {273 cat "$TEMPFILE1" >> $HOME/dead.bashbug274 echo "$0: mail to ${BUGADDR} failed: report saved in $HOME/dead.bashbug" >&2275 echo "$0: please send it manually to ${BUGADDR}" >&2276}277 278exit 0279 