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 #     Parts were written/modified by Nico Golde <nion@muttng.org>
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="`muttng -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 if [ "$severity" != "wishlist" ] ; then
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 fi
162
163 echo $n "Do you want to include your personal Mutt-ng configuration files? [Y|n] $c"
164 read personal
165 case "$personal" in
166 [nN]*)  personal=no  ;;
167     *)  personal=yes ;;
168 esac
169
170 echo $n "Do you want to include your system's global Mutt-ng configuration file? [Y|n] $c"
171 read global
172 case "$global" in
173 [nN]*)  global=no  ;;
174     *)  global=yes ;;
175 esac
176
177 if test -f /etc/debian_version ; then
178         DEBIAN=yes
179         echo $n "Checking whether Mutt-ng has been installed as a Debian package... $c"
180         DEBIANVERSION="`dpkg -l muttng | grep '^[ih]' | awk '{print $3}'`" 2> /dev/null
181         if test "$DEBIANVERSION" ; then
182                 DPKG=yes
183         else
184                 DPKG=no
185                 unset DEBIANVERSION
186         fi
187     if [ "$DPKG" == "yes" ] ; then
188         echo "$DPKG"
189         echo $n "File this bug with Debian? [Y|n] $c"
190         read DPKG
191         case "$DPKG" in
192         [nN])   DPKG=no ;;
193         *)      DPKG=yes ;;
194         esac
195     fi
196 else
197         DEBIAN=no
198         DPKG=no
199 fi
200 if [ "$DPKG" == "yes" ] ; then
201     echo ""
202     echo "Use reportbug muttng to report the bug to the debian bug tracking system..."
203     exit
204 fi
205 if rpm -q mutt-ng > /dev/null 2> /dev/null ; then
206         echo "Mutt-ng seems to come from an RPM package."
207         RPMVERSION="`rpm -q mutt-ng`"
208         RPMPACKAGER="`rpm -q -i mutt-ng | sed -n -e 's/^Packager *: *//p'`"
209 fi
210
211 MUTTVERSION="`muttng -v | awk '{print $2 $3; exit; }'`"
212 test "$DPKG" = "yes" && SUBMIT="$SUBMIT, $DEBIAN_SUBMIT"
213
214 exec > ${TEMPLATE}
215
216 test "$EMAIL"        && echo "From: $EMAIL"
217 test "$REPLYTO"      && echo "Reply-To: $REPLYTO"
218 test "$ORGANIZATION" && echo "Organization: $ORGANIZATION"
219
220 echo "Subject: Mutt-ng $MUTTVERSION: $SUBJECT"
221 echo "To: $SUBMIT"
222 test "$EMAIL"        && echo "Bcc: ${EMAIL}"
223 echo
224 echo "Package: mutt-ng"
225 echo "Version: ${DEBIANVERSION-${RPMVERSION-$MUTTVERSION}}"
226 echo "Severity: $severity"
227 echo 
228 echo "-- Please type your report below this line"
229 echo
230 echo
231 echo
232
233 if test "$DEBIAN" = "yes" ; then
234         echo "Obtaining Debian-specific information..." > /dev/tty
235         bug -p -s dummy muttng < /dev/null 2> /dev/null |        \
236                 sed -n -e "/^-- System Information/,/^---/p" | \
237                 grep -v '^---'
238 else
239         echo "-- System Information"
240         echo "System Version: `uname -a`"
241         test -z "$RPMPACKAGER" || echo "RPM Packager: $RPMPACKAGER";
242         test -f /etc/redhat-release && echo "RedHat Release: `cat /etc/redhat-release`"
243         test -f /etc/SuSE-release && echo "SuSE Release: `sed 1q /etc/SuSE-release`"
244         # Please provide more of these if you have any.
245 fi
246
247 echo 
248 echo "-- Build environment information"
249 echo
250 echo "(Note: This is the build environment installed on the system"
251 echo "muttbug is run on.  Information may or may not match the environment"
252 echo "used to build mutt.)"
253 echo
254 echo "- gcc version information"
255 echo "@CC@"
256 @CC@ -v 2>&1
257 echo
258 echo "- CFLAGS"
259 echo @CFLAGS@
260
261 echo
262 echo "-- Mutt-ng Version Information"
263 echo
264 muttng -v
265
266 if test "$CORE" && test -f "$CORE" ; then
267         echo 
268         echo "-- Core Dump Analysis Output"
269         echo
270
271         case "$DEBUGGER" in
272                 *sdb) debug_sdb $CORE ;;
273                 *dbx) debug_dbx $CORE ;;
274                 *gdb) debug_gdb $CORE ;;
275         esac
276         
277         echo
278 fi
279
280 if test "$personal" = "yes" ; then
281         CANDIDATES=".muttngrc-${MUTTVERSION} .muttngrc .muttng/muttngrc-${MUTTVERSION} .muttng/muttngrc"
282         MATCHED="none"
283         for f in $CANDIDATES; do
284                 if test -f "${HOME}/$f" ; then
285                         MATCHED="${HOME}/$f"
286                         break
287                 fi
288         done
289         
290         if test "$MATCHED" = "none" ; then
291                 echo "Warning: Can't find your personal .muttngrc." >&2
292         else
293                 include_file $MATCHED
294         fi
295 fi
296
297
298 if test "$global" = "yes" ; then
299         CANDIDATES="Muttngrc-${MUTTVERSION} Muttngrc"
300         DIRECTORIES="$sysconfdir $pkgdatadir"
301         MATCHED="none"
302         for d in $DIRECTORIES ; do
303                 for f in $CANDIDATES; do
304                         if test -f $d/$f ; then
305                                 MATCHED="$d/$f"
306                                 break
307                         fi
308                 done
309                 test "$MATCHED" = "none" || break
310         done
311         
312         if test "$MATCHED" = "none" ; then
313                 echo "Warning: Can't find global Muttngrc." >&2
314         else
315                 include_file $MATCHED
316         fi
317 fi
318
319 exec > /dev/tty
320
321 cp $TEMPLATE $SCRATCH/mutt-bug.txt
322
323 input="e"
324 while : ; do
325         if test "$input" = "e" ; then
326                 ${VISUAL-${EDITOR-vi}} $SCRATCH/mutt-bug.txt
327                 if cmp $SCRATCH/mutt-bug.txt ${TEMPLATE} > /dev/null ; then
328                         echo "Warning: Bug report was not modified!"
329                 fi
330         fi
331         
332         echo $n "Submit, Edit, View, Quit? [S|e|v|q] $c"
333         read _input
334         input="`echo $_input | tr EVSQ evsq`"
335         case $input in
336         e*)     ;;
337         v*)     ${PAGER-more} $SCRATCH/mutt-bug.txt ;;
338         s*|"")  $SENDMAIL -t < $SCRATCH/mutt-bug.txt ; exit ;;
339         q*)     exit
340         esac
341 done
342