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