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