|
| 1 | +#!/bin/sh - |
| 2 | +# |
| 3 | +# gawkbug - create a bug report and mail it to the bug address |
| 4 | +# |
| 5 | +# All mail defaults to [email protected]. Unlike the original bashbug |
| 6 | +# script, we don't differentiate on the release status. |
| 7 | +# |
| 8 | +# Copyright (C) 1996-2022 Free Software Foundation, Inc. |
| 9 | +# |
| 10 | +# This program is free software: you can redistribute it and/or modify |
| 11 | +# it under the terms of the GNU General Public License as published by |
| 12 | +# the Free Software Foundation, either version 3 of the License, or |
| 13 | +# (at your option) any later version. |
| 14 | +# |
| 15 | +# This program is distributed in the hope that it will be useful, |
| 16 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | +# GNU General Public License for more details. |
| 19 | +# |
| 20 | +# You should have received a copy of the GNU General Public License |
| 21 | +# along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 22 | + |
| 23 | +# |
| 24 | +# configuration section: |
| 25 | +# these variables are filled in by the make target in Makefile |
| 26 | +# |
| 27 | +MACHINE="i686" |
| 28 | +OS="msys" |
| 29 | +CC="gcc" |
| 30 | +CFLAGS="-march=pentium4 -mtune=generic -O2 -pipe -DNDEBUG" |
| 31 | +VERSION="5.3.1" |
| 32 | +MACHTYPE="i686-pc-msys" |
| 33 | + |
| 34 | +PATH=/bin:/usr/bin:/usr/local/bin:$PATH |
| 35 | +export PATH |
| 36 | + |
| 37 | +# Check if TMPDIR is set, default to /tmp |
| 38 | +: ${TMPDIR:=/tmp} |
| 39 | + |
| 40 | +#Securely create a temporary directory for the temporary files |
| 41 | +TEMPDIR=$TMPDIR/gbug.$$ |
| 42 | +(umask 077 && mkdir "$TEMPDIR") || { |
| 43 | + echo "$0: could not create temporary directory" >&2 |
| 44 | + exit 1 |
| 45 | +} |
| 46 | + |
| 47 | +TEMPFILE1=$TEMPDIR/gbug1 |
| 48 | +TEMPFILE2=$TEMPDIR/gbug2 |
| 49 | + |
| 50 | +USAGE="Usage: $0 [--help] [--version] [bug-report-email-address]" |
| 51 | +VERSTR="GNU gawkbug, version ${VERSION}" |
| 52 | + |
| 53 | +do_help= do_version= |
| 54 | + |
| 55 | +while [ $# -gt 0 ] |
| 56 | +do |
| 57 | + case "$1" in |
| 58 | + --help) shift ; do_help=y ;; |
| 59 | + --version) shift ; do_version=y ;; |
| 60 | + --) shift ; break ;; |
| 61 | + -*) echo "gawkbug: ${1}: invalid option" >&2 |
| 62 | + echo "$USAGE" >&2 |
| 63 | + exit 2 ;; |
| 64 | + *) break ;; |
| 65 | + esac |
| 66 | +done |
| 67 | + |
| 68 | +if [ -n "$do_version" ] |
| 69 | +then |
| 70 | + echo "${VERSTR}" |
| 71 | + exit 0 |
| 72 | +fi |
| 73 | + |
| 74 | +if [ -n "$do_help" ] |
| 75 | +then |
| 76 | + echo "${VERSTR}" |
| 77 | + echo "${USAGE}" |
| 78 | + echo |
| 79 | + cat << HERE_EOF |
| 80 | +Gawkbug is used to send mail to the Gawk maintainers |
| 81 | +for when Gawk doesn't behave like you'd like, or expect. |
| 82 | +
|
| 83 | +Gawkbug will start up your editor (as defined by the shell's |
| 84 | +EDITOR environment variable) with a preformatted bug report |
| 85 | +template for you to fill in. The report will be mailed to the |
| 86 | +bug-gawk mailing list by default. |
| 87 | +
|
| 88 | +Please see https://www.gnu.org/software/gawk/manual/html_node/Bugs.html |
| 89 | +for bug reporting instructions. Reading that information before |
| 90 | +repoting a bug will make everyones' lives easier. |
| 91 | +
|
| 92 | +If you invoke gawkbug by accident, just quit your editor without |
| 93 | +saving any changes to the template, and no bug report will be sent. |
| 94 | +HERE_EOF |
| 95 | + exit 0 |
| 96 | +fi |
| 97 | + |
| 98 | +# Figure out how to echo a string without a trailing newline |
| 99 | +N=`echo 'hi there\c'` |
| 100 | +case "$N" in |
| 101 | +*c) n=-n c= ;; |
| 102 | +*) n= c='\c' ;; |
| 103 | +esac |
| 104 | + |
| 105 | + |
| 106 | + |
| 107 | +BUGADDR="${1-$BUGGAWK}" |
| 108 | + |
| 109 | +if [ -z "$DEFEDITOR" ] && [ -z "$EDITOR" ] |
| 110 | +then |
| 111 | + if [ -x /usr/bin/editor ] |
| 112 | + then |
| 113 | + DEFEDITOR=editor |
| 114 | + elif [ -x /usr/bin/vim ] |
| 115 | + then |
| 116 | + DEFEDITOR=vim |
| 117 | + elif [ -x /usr/bin/gvim ] |
| 118 | + then |
| 119 | + DEFEDITOR=gvim |
| 120 | + elif [ -x /usr/local/bin/ce ] |
| 121 | + then |
| 122 | + DEFEDITOR=ce |
| 123 | + elif [ -x /usr/local/bin/emacs ] |
| 124 | + then |
| 125 | + DEFEDITOR=emacs |
| 126 | + elif [ -x /usr/contrib/bin/emacs ] |
| 127 | + then |
| 128 | + DEFEDITOR=emacs |
| 129 | + elif [ -x /usr/bin/emacs ] |
| 130 | + then |
| 131 | + DEFEDITOR=emacs |
| 132 | + elif [ -x /usr/bin/xemacs ] |
| 133 | + then |
| 134 | + DEFEDITOR=xemacs |
| 135 | + elif [ -x /usr/bin/nano ] |
| 136 | + then |
| 137 | + DEFEDITOR=nano |
| 138 | + elif [ -x /usr/contrib/bin/jove ] |
| 139 | + then |
| 140 | + DEFEDITOR=jove |
| 141 | + elif [ -x /usr/local/bin/jove ] |
| 142 | + then |
| 143 | + DEFEDITOR=jove |
| 144 | + elif [ -x /usr/bin/vi ] |
| 145 | + then |
| 146 | + DEFEDITOR=vi |
| 147 | + else |
| 148 | + echo "$0: No default editor found: attempting to use vi" >&2 |
| 149 | + DEFEDITOR=vi |
| 150 | + fi |
| 151 | +fi |
| 152 | + |
| 153 | + |
| 154 | +: ${EDITOR=$DEFEDITOR} |
| 155 | + |
| 156 | +: ${USER=${LOGNAME-`whoami`}} |
| 157 | + |
| 158 | +trap 'rm -rf "$TEMPDIR"; exit 1' 1 2 3 13 15 |
| 159 | +trap 'rm -rf "$TEMPDIR"' 0 |
| 160 | + |
| 161 | +UN= |
| 162 | +if (uname) >/dev/null 2>&1 |
| 163 | +then |
| 164 | + UN=`uname -a` |
| 165 | +fi |
| 166 | + |
| 167 | +if [ -f /usr/lib/sendmail ] |
| 168 | +then |
| 169 | + RMAIL="/usr/lib/sendmail" |
| 170 | + SMARGS="-i -t" |
| 171 | +elif [ -f /usr/sbin/sendmail ] |
| 172 | +then |
| 173 | + RMAIL="/usr/sbin/sendmail" |
| 174 | + SMARGS="-i -t" |
| 175 | +else |
| 176 | + RMAIL=rmail |
| 177 | + SMARGS="$BUGADDR" |
| 178 | +fi |
| 179 | + |
| 180 | +INITIAL_SUBJECT='[50 character or so descriptive subject here (for reference)]' |
| 181 | + |
| 182 | +cat > "$TEMPFILE1" <<EOF |
| 183 | +From: ${USER} |
| 184 | +To: ${BUGADDR} |
| 185 | +Subject: ${INITIAL_SUBJECT} |
| 186 | +
|
| 187 | +Configuration Information [Automatically generated, do not change]: |
| 188 | +Machine: $MACHINE |
| 189 | +OS: $OS |
| 190 | +Compiler: $CC |
| 191 | +Compilation CFLAGS: $CFLAGS |
| 192 | +uname output: $UN |
| 193 | +Machine Type: $MACHTYPE |
| 194 | +
|
| 195 | +Gawk Version: $VERSION |
| 196 | +
|
| 197 | +Attestation 1: |
| 198 | + I have read https://www.gnu.org/software/gawk/manual/html_node/Bugs.html. |
| 199 | + Yes / No [ Choose one. If "No", then why haven't you? ] |
| 200 | +
|
| 201 | +Attestation 2: |
| 202 | + I have not modified the sources before building gawk. |
| 203 | + True / False |
| 204 | + [ Choose one. If "False", then please explain what you did and why. ] |
| 205 | +
|
| 206 | +Description: |
| 207 | + [Detailed description of the problem, suggestion, or complaint.] |
| 208 | +
|
| 209 | +Repeat-By: |
| 210 | + [Describe the sequence of events that causes the problem to occur.] |
| 211 | +
|
| 212 | +Fix: |
| 213 | + [Description of how to fix the problem. If you don't know a |
| 214 | + fix for the problem, don't include this section.] |
| 215 | +EOF |
| 216 | + |
| 217 | +cp "$TEMPFILE1" "$TEMPFILE2" |
| 218 | +chmod u+w "$TEMPFILE1" |
| 219 | + |
| 220 | +trap '' 2 # ignore interrupts while in editor |
| 221 | + |
| 222 | +edstat=1 |
| 223 | +while [ $edstat -ne 0 ] |
| 224 | +do |
| 225 | + $EDITOR "$TEMPFILE1" |
| 226 | + edstat=$? |
| 227 | + |
| 228 | + if [ $edstat -ne 0 ] |
| 229 | + then |
| 230 | + echo "$0: editor \`$EDITOR' exited with nonzero status." |
| 231 | + echo "$0: Perhaps it was interrupted." |
| 232 | + echo "$0: Type \`y' to give up, and lose your bug report;" |
| 233 | + echo "$0: type \`n' to re-enter the editor." |
| 234 | + echo $n "$0: Do you want to give up? $c" |
| 235 | + |
| 236 | + read ans |
| 237 | + case "$ans" in |
| 238 | + [Yy]*) exit 1 ;; |
| 239 | + esac |
| 240 | + |
| 241 | + continue |
| 242 | + fi |
| 243 | + |
| 244 | + # find the subject from the temp file and see if it's been changed |
| 245 | + CURR_SUB=`grep '^Subject: ' "$TEMPFILE1" | sed 's|^Subject:[ ]*||' | sed 1q` |
| 246 | + |
| 247 | + case "$CURR_SUB" in |
| 248 | + "${INITIAL_SUBJECT}") |
| 249 | + echo |
| 250 | + echo "$0: You have not changed the subject from the default." |
| 251 | + echo "$0: Please use a more descriptive subject header." |
| 252 | + echo "$0: Type \`y' to give up, and lose your bug report;" |
| 253 | + echo "$0: type \`n' to re-enter the editor." |
| 254 | + echo $n "$0: Do you want to give up? $c" |
| 255 | + |
| 256 | + read ans |
| 257 | + case "$ans" in |
| 258 | + [Yy]*) exit 1 ;; |
| 259 | + esac |
| 260 | + |
| 261 | + echo "$0: The editor will be restarted in five seconds." |
| 262 | + sleep 5 |
| 263 | + edstat=1 |
| 264 | + ;; |
| 265 | + esac |
| 266 | + |
| 267 | +done |
| 268 | + |
| 269 | +trap 'rm -rf "$TEMPDIR"; exit 1' 2 # restore trap on SIGINT |
| 270 | + |
| 271 | +if cmp -s "$TEMPFILE1" "$TEMPFILE2" |
| 272 | +then |
| 273 | + echo "File not changed, no bug report submitted." |
| 274 | + exit |
| 275 | +fi |
| 276 | + |
| 277 | +echo $n "Send bug report to ${BUGADDR}? [y/n] $c" |
| 278 | +read ans |
| 279 | +case "$ans" in |
| 280 | +[Nn]*) exit 0 ;; |
| 281 | +esac |
| 282 | + |
| 283 | +${RMAIL} $SMARGS < "$TEMPFILE1" || { |
| 284 | + cat "$TEMPFILE1" >> $HOME/dead.gawkbug |
| 285 | + echo "$0: mail to ${BUGADDR} failed: report saved in $HOME/dead.gawkbug" >&2 |
| 286 | + echo "$0: please send it manually to ${BUGADDR}" >&2 |
| 287 | +} |
| 288 | + |
| 289 | +exit 0 |
0 commit comments