1 | #!/bin/sh |
---|
2 | # $Id: sendbug.sh,v 1.21 2003-07-30 19:16:12 zacheiss Exp $ |
---|
3 | |
---|
4 | visual=false |
---|
5 | |
---|
6 | help () { |
---|
7 | echo "Usage: $0 [program]" |
---|
8 | echo "Assist a user in sending an accurate and useful bug report." |
---|
9 | } |
---|
10 | |
---|
11 | TEMP="$(getopt -n "$0" -o '' -l gnome,help -- "$@")" || exit $? |
---|
12 | eval set -- "$TEMP" |
---|
13 | |
---|
14 | while true; do |
---|
15 | case "$1" in |
---|
16 | # This is how we are invoked from the panel menu |
---|
17 | --gnome) gnome=true; shift;; |
---|
18 | --help) help; exit;; |
---|
19 | --) shift; break;; |
---|
20 | esac |
---|
21 | done |
---|
22 | |
---|
23 | subject=$1 |
---|
24 | bugs_address=bugs@mit.edu |
---|
25 | sendmail="/usr/sbin/sendmail -t -oi" |
---|
26 | report_file=$(mktemp -t "sendbug.$USER.XXXX") |
---|
27 | machtype=$(machtype) |
---|
28 | cpu=$(machtype -c) |
---|
29 | hostname=$(hostname) |
---|
30 | dpy=$(machtype -d) |
---|
31 | |
---|
32 | localacct= |
---|
33 | shell=`awk -F: '/^'$USER':/ { print $7; exit; }' /etc/passwd 2>/dev/null` |
---|
34 | if [ -z "$shell" ]; then |
---|
35 | shell=`getent passwd $USER 2>/dev/null | cut -d ':' -f 7` |
---|
36 | else |
---|
37 | localacct="(local account)" |
---|
38 | fi |
---|
39 | case $shell in |
---|
40 | $SHELL) |
---|
41 | ;; |
---|
42 | "") |
---|
43 | shell="$SHELL (?)" |
---|
44 | ;; |
---|
45 | *) |
---|
46 | shell="$shell ($SHELL?)" |
---|
47 | ;; |
---|
48 | esac |
---|
49 | |
---|
50 | if [ -z "$subject" ]; then |
---|
51 | text="Please enter the name of the program or locker with which you are" |
---|
52 | text="$text having problems." |
---|
53 | if [ true = "$gnome" ]; then |
---|
54 | if ! subject=$(zenity --entry --text="$text"); then |
---|
55 | exit |
---|
56 | fi |
---|
57 | else |
---|
58 | echo "$text" || fmt |
---|
59 | echo -n ' --> ' |
---|
60 | read subject |
---|
61 | fi |
---|
62 | fi |
---|
63 | |
---|
64 | cat > $report_file << EOF |
---|
65 | To: $bugs_address |
---|
66 | Subject: Debathena: $subject |
---|
67 | |
---|
68 | System name: $hostname |
---|
69 | Type: $cpu |
---|
70 | Display type: $dpy |
---|
71 | |
---|
72 | Shell: $shell $localacct |
---|
73 | Window manager: ${WINDOW_MANAGER:-unknown} |
---|
74 | Desktop session: ${GDMSESSION:-unknown} |
---|
75 | |
---|
76 | 1) What were you trying to do? |
---|
77 | |
---|
78 | |
---|
79 | 2) What happened? |
---|
80 | |
---|
81 | |
---|
82 | 3) What should have happened? |
---|
83 | |
---|
84 | |
---|
85 | 4) Does this problem happen only on this workstation, or other workstations? |
---|
86 | |
---|
87 | |
---|
88 | 5) If you were following instructions, please include the URL or a |
---|
89 | description of the documentation: |
---|
90 | (e.g. a "problem set for 18.03" or http://ist.mit.edu) |
---|
91 | |
---|
92 | |
---|
93 | EOF |
---|
94 | |
---|
95 | if [ true = "$gnome" ]; then |
---|
96 | text="After you click OK, an editor window will appear with the bug report" |
---|
97 | text="$text contents. Please fill out the form, then save and exit. If" |
---|
98 | text="$text you change your mind, you will have a chance to cancel before" |
---|
99 | text="$text the bug report is sent." |
---|
100 | zenity --info --text="$text" |
---|
101 | gnome-text-editor "$report_file" |
---|
102 | # zenity doesn't let us specify the buttons on a question, and the |
---|
103 | # list dialog is awkward. So while we'd like to do something more |
---|
104 | # like what we do in the terminal case, we'll compromise a bit. |
---|
105 | question="Do you still want to send the bug report?" |
---|
106 | if ! zenity --question --text="$question"; then |
---|
107 | text="Cancelled. Your text is in $report_file if you wish to recover it." |
---|
108 | zenity --info --no-wrap --text="$text" |
---|
109 | exit |
---|
110 | fi |
---|
111 | |
---|
112 | if $sendmail < $report_file; then |
---|
113 | text="Thank you for your bug report." |
---|
114 | zenity --info --text="$text" |
---|
115 | else |
---|
116 | text="Failed to send the bug report! Please contact olc@mit.edu for" |
---|
117 | text="$text\nassistance. Your text is in $report_file" |
---|
118 | text="$text\nif you wish to recover it and submit it to $bugs_address" |
---|
119 | zenity --error --no-wrap --text="$text" |
---|
120 | fi |
---|
121 | else |
---|
122 | : ${EDITOR=nano} |
---|
123 | helpstr= |
---|
124 | case "$EDITOR" in |
---|
125 | nano|pico) |
---|
126 | helpstr="(Ctrl-O, then Enter to save; Ctrl-X to quit after saving)" |
---|
127 | ;; |
---|
128 | emacs) |
---|
129 | helpstr="(Ctrl-X, Ctrl-S to save; Ctrl-X, Ctrl-C to quit after saving)" |
---|
130 | ;; |
---|
131 | esac |
---|
132 | fmt << EOF |
---|
133 | |
---|
134 | After you press <Enter>, an editor will now open with the bug report |
---|
135 | form. Some fields have been filled out already. Please answer the |
---|
136 | numbered questions with as much detail as possible. |
---|
137 | Remember to save the file before exiting the editor. |
---|
138 | $helpstr |
---|
139 | |
---|
140 | Press <Enter> to continue. |
---|
141 | EOF |
---|
142 | read dummy |
---|
143 | $EDITOR "$report_file" |
---|
144 | while true; do |
---|
145 | fmt << EOF |
---|
146 | |
---|
147 | Please enter "send" to send the report, "edit" to re-edit it, or |
---|
148 | "quit" to quit. |
---|
149 | EOF |
---|
150 | echo -n ' --> ' |
---|
151 | read reply |
---|
152 | [ send = "$reply" ] && break |
---|
153 | [ quit = "$reply" ] && exit |
---|
154 | [ edit = "$reply" ] && $EDITOR "$report_file" |
---|
155 | done |
---|
156 | |
---|
157 | if $sendmail < $report_file; then |
---|
158 | echo "Thank you for your bug report." |
---|
159 | else |
---|
160 | fmt << EOF |
---|
161 | Failed to send the bug report! This shouldn't happen! |
---|
162 | Your text is in $report_file if you wish to recover it, |
---|
163 | and you can submit it to $bugs_address. |
---|
164 | EOF |
---|
165 | fi |
---|
166 | fi |
---|