Nico Golde:
[apps/madmutt.git] / muttbug.sh.in
1 #!/bin/sh
2
3 #
4 #     File a bug against the Mutt mail user agent.
5 #
6
7
8 #     $Id: muttbug.sh.in,v 3.7 2005/01/09 15:35:51 roessler Exp $
9 #
10
11 #
12 #     Copyright (c) 2000 Thomas Roessler <roessler@guug.de>
13 #
14 #
15 #     This program is free software; you can redistribute it and/or modify
16 #     it under the terms of the GNU General Public License as published by
17 #     the Free Software Foundation; either version 2 of the License, or
18 #     (at your option) any later version.
19
20 #     This program is distributed in the hope that it will be useful,
21 #     but WITHOUT ANY WARRANTY; without even the implied warranty of
22 #     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 #     GNU General Public License for more details.
24
25 #     You should have received a copy of the GNU General Public License
26 #     along with this program; if not, write to the Free Software
27 #     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
28 #
29
30 SUBMIT="mutt-ng-devel@lists.berlios.de"
31 DEBIAN_SUBMIT="submit@bugs.debian.org"
32
33 prefix=@prefix@
34
35 DEBUGGER=@DEBUGGER@
36 SENDMAIL=@SENDMAIL@
37 sysconfdir=@sysconfdir@
38 pkgdatadir=@pkgdatadir@
39
40 include_file ()
41 {
42         echo
43         echo "--- Begin $1"
44         sed -e 's/^-/- -/' $1 | egrep -v '^[    ]*(#|$)'
45         echo "--- End $1"
46         echo
47 }
48
49 debug_gdb ()
50 {
51         cat << EOF > $SCRATCH/gdb.rc
52 bt
53 list
54 quit
55 EOF
56         $DEBUGGER -n -x $SCRATCH/gdb.rc -c $CORE mutt
57 }
58
59 debug_dbx ()
60 {
61         cat << EOF > $SCRATCH/dbx.rc
62 where
63 list
64 quit
65 EOF
66         $DEBUGGER -s $SCRATCH/dbx.rc mutt $CORE
67 }
68
69 debug_sdb ()
70 {
71         cat << EOF > $SCRATCH/sdb.rc
72 t
73 w
74 q
75 EOF
76         $DEBUGGER mutt $CORE < $SCRATCH/sdb.rc
77 }
78
79 case `echo -n` in
80 "") n=-n; c=   ;;
81  *) n=; c='\c' ;;
82 esac
83  
84
85 exec > /dev/tty
86 exec < /dev/tty
87
88 SCRATCH=${TMPDIR-/tmp}/`basename $0`.`hostname`.$$
89
90 mkdir ${SCRATCH} || \
91
92         echo "`basename $0`: Can't create temporary directory." >& 2 ; 
93         exit 1 ; 
94 }
95
96 trap "rm -r -f ${SCRATCH} ; trap '' 0 ; exit" 0 1 2
97
98 TEMPLATE=${SCRATCH}/template.txt
99
100 if test -z "$EMAIL" ; then
101         EMAIL="`mutt -Q from 2> /dev/null | sed -e 's/^from=.\(.*\).$/\1/'`"
102 fi
103
104 echo "Please enter your e-mail address [$EMAIL]:"
105 echo $n "> $c"
106 read EMAILTMP
107
108 if test -n "$EMAILTMP" ; then
109         EMAIL="$EMAILTMP"
110 fi
111
112 echo "Please enter a one-line description of the problem you experience:"
113 echo $n "> $c"
114 read SUBJECT
115
116 cat <<EOF  
117 What should the severity for this bug report be?
118
119        0) Feature request, or maybe a bug which is very difficult to
120        fix due to major design considerations.
121
122        1) The package fails to perform correctly in some conditions,
123        or on some systems, or fails to comply with current policy
124        documents. Most bugs are in this category.
125
126        2) This bug makes this version of the package unsuitable for
127        a stable release.
128
129        3) Dangerous bug. Makes the package in question unusable by
130        anyone or mostly so, or causes data loss, or introduces a
131        security hole allowing access to the accounts of users who
132        use the package.
133
134        4) Critical bug. Makes unrelated software on the system (or
135        the whole system) break, or causes serious data loss, or
136        introduces a security hole on systems where you install the
137        package.
138
139 EOF
140 echo $n "Severity? [01234] $c"
141 read severity
142 case "$severity" in
143 0|[Ww]) severity=wishlist  ;;
144 2|[Ii]) severity=important ;;
145 3|[Gg]) severity=grave     ;;
146 4|[Cc]) severity=critical  ;;
147      *) severity=normal    ;;
148 esac
149
150 if test -x $DEBUGGER ; then
151         test -f core && CORE=core
152         echo "If Mutt-ng has crashed, it may have saved some program state in"
153         echo "a file named core.  We can include this information with the bug"
154         echo "report if you wish so."
155         echo "Do you want to include information gathered from a core file?"
156         echo "If yes, please enter the path - otherwise just say no: [$CORE]"
157         echo $n "> $c"
158         read _CORE
159         test "$_CORE" && CORE="$_CORE"
160 fi
161
162 echo $n "Do you want to include your personal Mutt-ng configuration files? [Y|n] $c"
163 read personal
164 case "$personal" in
165 [nN]*)  personal=no  ;;
166     *)  personal=yes ;;
167 esac
168
169 echo $n "Do you want to include your system's global Mutt-ng configuration file? [Y|n] $c"
170 read global
171 case "$global" in
172 [nN]*)  global=no  ;;
173     *)  global=yes ;;
174 esac
175
176 if test -f /etc/debian_version ; then
177         DEBIAN=yes
178         echo $n "Checking whether mutt-ng has been installed as a package... $c"
179         DEBIANVERSION="`dpkg -l muttng | grep '^[ih]' | awk '{print $3}'`" 2> /dev/null
180         if test "$DEBIANVERSION" ; then
181                 DPKG=yes
182         else
183                 DPKG=no
184                 unset DEBIANVERSION
185         fi
186         echo "$DPKG"
187         echo $n "File this bug with Debian? [Y|n] $c"
188         read DPKG
189         case "$DPKG" in
190         [nN])   DPKG=no ;;
191         *)      DPKG=yes ;;
192         esac
193 else
194         DEBIAN=no
195         DPKG=no
196 fi
197
198 if rpm -q mutt > /dev/null 2> /dev/null ; then
199         echo "Mutt seems to come from an RPM package."
200         RPMVERSION="`rpm -q mutt`"
201         RPMPACKAGER="`rpm -q -i muttng | sed -n -e 's/^Packager *: *//p'`"
202 fi
203
204 MUTTVERSION="`muttng -v | awk '{print $2 $3; exit; }'`"
205 test "$DPKG" = "yes" && SUBMIT="$SUBMIT, $DEBIAN_SUBMIT"
206
207 exec > ${TEMPLATE}
208
209 test "$EMAIL"        && echo "From: $EMAIL"
210 test "$REPLYTO"      && echo "Reply-To: $REPLYTO"
211 test "$ORGANIZATION" && echo "Organization: $ORGANIZATION"
212
213 echo "Subject: Mutt-ng-$MUTTVERSION: $SUBJECT"
214 echo "To: $SUBMIT"
215 test "$EMAIL"        && echo "Bcc: ${EMAIL}"
216 echo
217 echo "Package: muttng"
218 echo "Version: ${DEBIANVERSION-${RPMVERSION-$MUTTVERSION}}"
219 echo "Severity: $severity"
220 echo 
221 echo "-- Please type your report below this line"
222 echo
223 echo
224 echo
225
226 if test "$DEBIAN" = "yes" ; then
227         echo "Obtaining Debian-specific information..." > /dev/tty
228         bug -p -s dummy muttng < /dev/null 2> /dev/null |        \
229                 sed -n -e "/^-- System Information/,/^---/p" | \
230                 grep -v '^---'
231 else
232         echo "-- System Information"
233         echo "System Version: `uname -a`"
234         test -z "$RPMPACKAGER" || echo "RPM Packager: $RPMPACKAGER";
235         test -f /etc/redhat-release && echo "RedHat Release: `cat /etc/redhat-release`"
236         test -f /etc/SuSE-release && echo "SuSE Release: `sed 1q /etc/SuSE-release`"
237         # Please provide more of these if you have any.
238 fi
239
240 echo 
241 echo "-- Build environment information"
242 echo
243 echo "(Note: This is the build environment installed on the system"
244 echo "muttbug is run on.  Information may or may not match the environment"
245 echo "used to build mutt.)"
246 echo
247 echo "- gcc version information"
248 echo "@CC@"
249 @CC@ -v 2>&1
250 echo
251 echo "- CFLAGS"
252 echo @CFLAGS@
253
254
255 echo
256 echo "-- Mutt-ng Version Information"
257 echo
258 muttng -v
259
260 if test "$CORE" && test -f "$CORE" ; then
261         echo 
262         echo "-- Core Dump Analysis Output"
263         echo
264
265         case "$DEBUGGER" in
266                 *sdb) debug_sdb $CORE ;;
267                 *dbx) debug_dbx $CORE ;;
268                 *gdb) debug_gdb $CORE ;;
269         esac
270         
271         echo
272 fi
273
274 if test "$personal" = "yes" ; then
275         CANDIDATES=".muttngrc-${MUTTVERSION} .muttngrc .muttng/muttngrc-${MUTTVERSION} .muttng/muttngrc"
276         MATCHED="none"
277         for f in $CANDIDATES; do
278                 if test -f "${HOME}/$f" ; then
279                         MATCHED="${HOME}/$f"
280                         break
281                 fi
282         done
283         
284         if test "$MATCHED" = "none" ; then
285                 echo "Warning: Can't find your personal .muttngrc." >&2
286         else
287                 include_file $MATCHED
288         fi
289 fi
290
291
292 if test "$global" = "yes" ; then
293         CANDIDATES="Muttngrc-${MUTTVERSION} Muttngrc"
294         DIRECTORIES="$sysconfdir $pkgdatadir"
295         MATCHED="none"
296         for d in $DIRECTORIES ; do
297                 for f in $CANDIDATES; do
298                         if test -f $d/$f ; then
299                                 MATCHED="$d/$f"
300                                 break
301                         fi
302                 done
303                 test "$MATCHED" = "none" || break
304         done
305         
306         if test "$MATCHED" = "none" ; then
307                 echo "Warning: Can't find global Muttngrc." >&2
308         else
309                 include_file $MATCHED
310         fi
311 fi
312
313 exec > /dev/tty
314
315 cp $TEMPLATE $SCRATCH/mutt-bug.txt
316
317 input="e"
318 while : ; do
319         if test "$input" = "e" ; then
320                 ${VISUAL-${EDITOR-vi}} $SCRATCH/mutt-bug.txt
321                 if cmp $SCRATCH/mutt-bug.txt ${TEMPLATE} > /dev/null ; then
322                         echo "Warning: Bug report was not modified!"
323                 fi
324         fi
325         
326         echo $n "Submit, Edit, View, Quit? [S|e|v|q] $c"
327         read _input
328         input="`echo $_input | tr EVSQ evsq`"
329         case $input in
330         e*)     ;;
331         v*)     ${PAGER-more} $SCRATCH/mutt-bug.txt ;;
332         s*|"")  $SENDMAIL -t < $SCRATCH/mutt-bug.txt ; exit ;;
333         q*)     exit
334         esac
335 done
336