6a2a47bf09ff76cb2572116bd4b5438b93dfa0a6
[platform/upstream/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@prep.ai.mit.edu.
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/bashbug.$$
25
26 case "$RELSTATUS" in
27 alpha*|beta*)   BUGBASH=chet@po.cwru.edu ;;
28 *)              BUGBASH=bug-bash@prep.ai.mit.edu ;;
29 esac
30
31 BUGADDR=${1-$BUGBASH}
32
33 : ${EDITOR=emacs}
34
35 : ${USER=${LOGNAME-`whoami`}}
36
37 trap 'rm -f $TEMP $TEMP.x; exit 1' 1 2 3 13 15
38 trap 'rm -f $TEMP $TEMP.x' 0
39
40 UN=
41 if (uname) >/dev/null 2>&1; then
42         UN=`uname -a`
43 fi
44
45 if [ -f /usr/lib/sendmail ] ; then
46         RMAIL="/usr/lib/sendmail"
47 elif [ -f /usr/sbin/sendmail ] ; then
48         RMAIL="/usr/sbin/sendmail"
49 else
50         RMAIL=rmail
51 fi
52
53 cat > $TEMP <<EOF
54 From: ${USER}
55 To: ${BUGADDR}
56 Subject: [50 character or so descriptive subject here (for reference)]
57
58 Configuration Information [Automatically generated, do not change]:
59 Machine: $MACHINE
60 OS: $OS
61 Compiler: $CC
62 Compilation CFLAGS: $CFLAGS
63 uname output: $UN
64 Machine Type: $MACHTYPE
65
66 Bash Version: $RELEASE
67 Patch Level: $PATCHLEVEL
68 Release Status: $RELSTATUS
69
70 Description:
71         [Detailed description of the problem, suggestion, or complaint.]
72
73 Repeat-By:
74         [Describe the sequence of events that causes the problem
75         to occur.]
76
77 Fix:
78         [Description of how to fix the problem.  If you don't know a
79         fix for the problem, don't include this section.]
80 EOF
81
82 chmod u+w $TEMP
83 cp $TEMP $TEMP.x
84
85 # Figure out how to echo a string without a trailing newline
86 N=`echo 'hi there\c'`
87 case "$N" in
88 *c)     n=-n c= ;;
89 *)      n= c='\c' ;;
90 esac
91
92 trap '' 2               # ignore interrupts while in editor
93
94 until $EDITOR $TEMP; do
95         echo "$0: editor \`$EDITOR' exited with nonzero status."
96         echo "$0: Perhaps it was interrupted."
97         echo "$0: Type `y' to give up, and lose your bug report;"
98         echo "$0: type `n' to re-enter the editor."
99         echo $n "$0: Do you want to give up? $c"
100
101         read ans
102         case "$ans" in
103         Yy]*) exit 1 ;;
104         esac
105 done
106
107 trap 'rm -f $TEMP $TEMP.x; exit 1' 2    # restore trap on SIGINT
108
109 if cmp -s $TEMP $TEMP.x
110 then
111         echo "File not changed, no bug report submitted."
112         exit
113 fi
114
115 ${RMAIL} $BUGADDR < $TEMP || {
116         cat $TEMP >> $HOME/dead.bashbug
117         echo "$0: mail failed: report saved in $HOME/dead.bashbug" >&2
118 }
119
120 exit 0