~linuxjedi/drizzle/trunk-bug-667053

« back to all changes in this revision

Viewing changes to scripts/mysqlbug.sh

  • Committer: brian
  • Date: 2008-06-25 05:29:13 UTC
  • Revision ID: brian@localhost.localdomain-20080625052913-6upwo0jsrl4lnapl
clean slate

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/sh
 
2
# Copyright (C) 2000-2002, 2004 MySQL AB
 
3
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; version 2 of the License.
 
7
 
8
# This program is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
# GNU General Public License for more details.
 
12
 
13
# You should have received a copy of the GNU General Public License
 
14
# along with this program; if not, write to the Free Software
 
15
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
16
 
 
17
# Create a bug report and mail it to the mysql mailing list
 
18
# Based on glibc bug reporting script.
 
19
 
 
20
echo "Finding system information for a MySQL bug report"
 
21
 
 
22
VERSION="@VERSION@@MYSQL_SERVER_SUFFIX@"
 
23
COMPILATION_COMMENT="@COMPILATION_COMMENT@"
 
24
BUGmysql="mysql@lists.mysql.com"
 
25
# This is set by configure
 
26
COMP_CALL_INFO="CC='@SAVE_CC@'  CFLAGS='@SAVE_CFLAGS@'  CXX='@SAVE_CXX@'  CXXFLAGS='@SAVE_CXXFLAGS@'  LDFLAGS='@SAVE_LDFLAGS@'  ASFLAGS='@SAVE_ASFLAGS@'"
 
27
COMP_RUN_INFO="CC='@CC@'  CFLAGS='@CFLAGS@'  CXX='@CXX@'  CXXFLAGS='@CXXFLAGS@'  LDFLAGS='@LDFLAGS@'  ASFLAGS='@ASFLAGS@'"
 
28
CONFIGURE_LINE="@CONF_COMMAND@"
 
29
 
 
30
LIBC_INFO=""
 
31
for pat in /lib/libc.* /lib/libc-* /usr/lib/libc.* /usr/lib/libc-*
 
32
do
 
33
    TMP=`ls -l $pat 2>/dev/null`
 
34
    if test $? = 0
 
35
    then
 
36
      LIBC_INFO="$LIBC_INFO
 
37
$TMP"
 
38
    fi
 
39
done
 
40
 
 
41
PATH=../client:$PATH:/bin:/usr/bin:/usr/local/bin
 
42
export PATH
 
43
 
 
44
BUGADDR=${1-$BUGmysql}
 
45
ENVIRONMENT=`uname -a`
 
46
 
 
47
: ${USER=${LOGNAME-`whoami`}}
 
48
 
 
49
COMMAND=`echo $0|sed 's%.*/\([^/]*\)%\1%'`
 
50
 
 
51
# Try to create a secure tmpfile
 
52
umask 077
 
53
TEMPDIR=/tmp/mysqlbug-$$
 
54
mkdir $TEMPDIR || (echo "can not create directory in /tmp, aborting"; exit 1;)
 
55
TEMP=${TEMPDIR}/mysqlbug
 
56
 
 
57
trap 'rm -f $TEMP $TEMP.x; rmdir $TEMPDIR; exit 1' 1 2 3 13 15
 
58
trap 'rm -f $TEMP $TEMP.x; rmdir $TEMPDIR' 0
 
59
 
 
60
# How to read the passwd database.
 
61
PASSWD="cat /etc/passwd"
 
62
 
 
63
if test -f /usr/lib/sendmail
 
64
then
 
65
  MAIL_AGENT="/usr/lib/sendmail -oi -t"
 
66
elif test -f /usr/sbin/sendmail
 
67
then
 
68
  MAIL_AGENT="/usr/sbin/sendmail -oi -t"
 
69
else
 
70
  MAIL_AGENT="rmail $BUGmysql"
 
71
fi
 
72
 
 
73
# Figure out how to echo a string without a trailing newline
 
74
N=`echo 'hi there\c'`
 
75
case "$N" in
 
76
  *c)   ECHON1='echo -n' ECHON2= ;;
 
77
  *)    ECHON1=echo ECHON2='\c' ;;
 
78
esac
 
79
 
 
80
# Find out the name of the originator of this PR.
 
81
if test -n "$NAME" 
 
82
then
 
83
  ORIGINATOR="$NAME"
 
84
elif test -f $HOME/.fullname
 
85
then
 
86
  ORIGINATOR="`sed -e '1q' $HOME/.fullname`"
 
87
else
 
88
  # Must use temp file due to incompatibilities in quoting behavior
 
89
  # and to protect shell metacharacters in the expansion of $LOGNAME
 
90
  $PASSWD | grep "^$LOGNAME:" | awk -F: '{print $5}' | sed -e 's/,.*//' > $TEMP
 
91
  ORIGINATOR="`cat $TEMP`"
 
92
  rm -f $TEMP
 
93
fi
 
94
 
 
95
if test -n "$ORGANIZATION"
 
96
then
 
97
  if test -f "$ORGANIZATION"
 
98
  then
 
99
    ORGANIZATION="`cat $ORGANIZATION`"
 
100
  fi
 
101
else
 
102
  if test -f $HOME/.organization
 
103
  then
 
104
    ORGANIZATION="`cat $HOME/.organization`"
 
105
  elif test -f $HOME/.signature
 
106
  then
 
107
    ORGANIZATION=`sed -e "s/^/  /" $HOME/.signature; echo ">"`
 
108
  fi
 
109
fi
 
110
 
 
111
PATH_DIRS=`echo $PATH | sed -e 's/^:/. /' -e 's/:$/ ./' -e 's/::/ . /g' -e 's/:/ /g' `
 
112
 
 
113
which_1 ()
 
114
{
 
115
  for cmd
 
116
  do
 
117
    # Absolute path ?. 
 
118
    if expr "x$cmd" : "x/" > /dev/null
 
119
    then
 
120
      echo "$cmd"
 
121
      exit 0
 
122
    else
 
123
      for d in $PATH_DIRS
 
124
      do
 
125
        file="$d/$cmd"
 
126
        if test -x "$file" -a ! -d "$file"
 
127
        then
 
128
          echo "$file"
 
129
          exit 0
 
130
        fi
 
131
      done
 
132
    fi
 
133
  done
 
134
  exit 1
 
135
}
 
136
 
 
137
change_editor ()
 
138
{
 
139
  echo "You can change editor by setting the environment variable VISUAL."
 
140
  echo "If your shell is a bourne shell (sh) do"
 
141
  echo "VISUAL=your_editors_name; export VISUAL"
 
142
  echo "If your shell is a C shell (csh) do"
 
143
  echo "setenv VISUAL your_editors_name"
 
144
}
 
145
 
 
146
# If they don't have a preferred editor set, then use emacs
 
147
if test -z "$VISUAL"
 
148
then
 
149
  if test -z "$EDITOR"
 
150
  then
 
151
    # Honor debian sensible-editor
 
152
    if test -x "/usr/bin/sensible-editor"
 
153
    then
 
154
      EDIT=/usr/bin/sensible-editor
 
155
    else
 
156
      EDIT=emacs
 
157
    fi
 
158
  else
 
159
    EDIT="$EDITOR"
 
160
  fi
 
161
else
 
162
  EDIT="$VISUAL"
 
163
fi
 
164
 
 
165
#which_1 $EDIT
 
166
used_editor=`which_1 $EDIT`
 
167
 
 
168
echo "test -x $used_editor"
 
169
if test -x "$used_editor"
 
170
then
 
171
  echo "Using editor $used_editor";
 
172
  change_editor
 
173
  sleep 2
 
174
else
 
175
  echo "Could not find a text editor. (tried $EDIT)"
 
176
  change_editor
 
177
  exit 1
 
178
fi
 
179
 
 
180
# Find out some information.
 
181
SYSTEM=`( test -f /bin/uname  && /bin/uname -a ) || \
 
182
        ( test -f /usr/bin/uname  && /usr/bin/uname -a ) || echo ""`
 
183
ARCH=`test -f /bin/arch  && /bin/arch`
 
184
MACHINE=`test -f /bin/machine  && /bin/machine`
 
185
FILE_PATHS=
 
186
 
 
187
for cmd in perl make gmake gcc cc
 
188
do
 
189
  file=`which_1 $cmd`
 
190
  if test $? = 0
 
191
  then
 
192
    if test $cmd = "gcc"
 
193
    then
 
194
      GCC_INFO=`$file -v 2>&1`
 
195
    elif test $cmd = "perl"
 
196
    then
 
197
      PERL_INFO=`$file -v | grep -i version 2>&1`
 
198
    fi
 
199
    FILE_PATHS="$FILE_PATHS $file"
 
200
  fi
 
201
done
 
202
 
 
203
admin=`which_1 mysqladmin`
 
204
MYSQL_SERVER=
 
205
if test -x "$admin"
 
206
then
 
207
  MYSQL_SERVER=`$admin version 2> /dev/null`
 
208
  if test "$?" = "1"
 
209
  then
 
210
    MYSQL_SERVER=""
 
211
  fi
 
212
fi
 
213
 
 
214
SUBJECT_C="[50 character or so descriptive subject here (for reference)]"
 
215
ORGANIZATION_C='<organization of PR author (multiple lines)>'
 
216
LICENCE_C='[none | licence | email support | extended email support ]'
 
217
SYNOPSIS_C='<synopsis of the problem (one line)>'
 
218
SEVERITY_C='<[ non-critical | serious | critical ] (one line)>'
 
219
PRIORITY_C='<[ low | medium | high ] (one line)>'
 
220
CLASS_C='<[ sw-bug | doc-bug | change-request | support ] (one line)>'
 
221
RELEASE_C='<release number or tag (one line)>'
 
222
ENVIRONMENT_C='<machine, os, target, libraries (multiple lines)>'
 
223
DESCRIPTION_C='<precise description of the problem (multiple lines)>'
 
224
HOW_TO_REPEAT_C='<code/input/activities to reproduce the problem (multiple lines)>'
 
225
FIX_C='<how to correct or work around the problem, if known (multiple lines)>'
 
226
 
 
227
 
 
228
cat > $TEMP <<EOF
 
229
SEND-PR: -*- send-pr -*-
 
230
SEND-PR: Lines starting with \`SEND-PR' will be removed automatically, as
 
231
SEND-PR: will all comments (text enclosed in \`<' and \`>').
 
232
SEND-PR:
 
233
From: ${USER}
 
234
To: ${BUGADDR}
 
235
Subject: $SUBJECT_C
 
236
 
 
237
>Description:
 
238
        $DESCRIPTION_C
 
239
>How-To-Repeat:
 
240
        $HOW_TO_REPEAT_C
 
241
>Fix:
 
242
        $FIX_C
 
243
 
 
244
>Submitter-Id:  <submitter ID>
 
245
>Originator:    ${ORIGINATOR}
 
246
>Organization:
 
247
${ORGANIZATION- $ORGANIZATION_C}
 
248
>MySQL support: $LICENCE_C
 
249
>Synopsis:      $SYNOPSIS_C
 
250
>Severity:      $SEVERITY_C
 
251
>Priority:      $PRIORITY_C
 
252
>Category:      mysql
 
253
>Class:         $CLASS_C
 
254
>Release:       mysql-${VERSION} ($COMPILATION_COMMENT)
 
255
`test -n "$MYSQL_SERVER" && echo ">Server: $MYSQL_SERVER"`
 
256
>C compiler:    @CC_VERSION@
 
257
>C++ compiler:  @CXX_VERSION@
 
258
>Environment:
 
259
        $ENVIRONMENT_C
 
260
`test -n "$SYSTEM"  && echo "System: $SYSTEM"`
 
261
`test -n "$ARCH"  && echo "Architecture: $ARCH"`
 
262
`test -n "$MACHINE"  && echo "Machine: $MACHINE"`
 
263
`test -n "$FILE_PATHS"  && echo "Some paths: $FILE_PATHS"`
 
264
`test -n "$GCC_INFO"  && echo "GCC: $GCC_INFO"`
 
265
`test -n "$COMP_CALL_INFO"  && echo "Compilation info (call): $COMP_CALL_INFO"`
 
266
`test -n "$COMP_RUN_INFO"   && echo "Compilation info (used): $COMP_RUN_INFO"`
 
267
`test -n "$LIBC_INFO"  && echo "LIBC: $LIBC_INFO"`
 
268
`test -n "$CONFIGURE_LINE"  && echo "Configure command: $CONFIGURE_LINE"`
 
269
`test -n "$PERL_INFO"  && echo "Perl: $PERL_INFO"`
 
270
EOF
 
271
 
 
272
chmod u+w $TEMP
 
273
cp $TEMP $TEMP.x
 
274
 
 
275
eval $EDIT $TEMP
 
276
 
 
277
if cmp -s $TEMP $TEMP.x
 
278
then
 
279
  echo "File not changed, no bug report submitted."
 
280
  mv -f $TEMP /tmp/failed-mysql-bugreport
 
281
  echo "The raw bug report exists in /tmp/failed-mysql-bugreport"
 
282
  echo "If you use this remember that the first lines of the report are now a lie.."
 
283
  exit 1
 
284
fi
 
285
 
 
286
#
 
287
#       Check the enumeration fields
 
288
 
 
289
# This is a "sed-subroutine" with one keyword parameter
 
290
# (with workaround for Sun sed bug)
 
291
#
 
292
SED_CMD='
 
293
/$PATTERN/{
 
294
s|||
 
295
s|<.*>||
 
296
s|^[    ]*||
 
297
s|[     ]*$||
 
298
p
 
299
q
 
300
}'
 
301
 
 
302
 
 
303
while :; do
 
304
  CNT=0
 
305
 
 
306
  #
 
307
  # 1) Severity
 
308
  #
 
309
  PATTERN=">Severity:"
 
310
  SEVERITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
 
311
  case "$SEVERITY" in
 
312
    ""|non-critical|serious|critical) CNT=`expr $CNT + 1` ;;
 
313
    *)  echo "$COMMAND: \`$SEVERITY' is not a valid value for \`Severity'."
 
314
  esac
 
315
  #
 
316
  # 2) Priority
 
317
  #
 
318
  PATTERN=">Priority:"
 
319
  PRIORITY=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
 
320
  case "$PRIORITY" in
 
321
    ""|low|medium|high) CNT=`expr $CNT + 1` ;;
 
322
    *)  echo "$COMMAND: \`$PRIORITY' is not a valid value for \`Priority'."
 
323
  esac
 
324
  #
 
325
  # 3) Class
 
326
  #
 
327
  PATTERN=">Class:"
 
328
  CLASS=`eval sed -n -e "\"$SED_CMD\"" $TEMP`
 
329
  case "$CLASS" in
 
330
    ""|sw-bug|doc-bug|change-request|support) CNT=`expr $CNT + 1` ;;
 
331
    *)  echo "$COMMAND: \`$CLASS' is not a valid value for \`Class'."
 
332
  esac
 
333
 
 
334
  #
 
335
  # 4) Synopsis
 
336
  #
 
337
  VALUE=`grep "^>Synopsis:" $TEMP | sed 's/>Synopsis:[  ]*//'`
 
338
  case "$VALUE" in
 
339
    "$SYNOPSIS_C")  echo "$COMMAND: \`$VALUE' is not a valid value for \`Synopsis'." ;;
 
340
    *) CNT=`expr $CNT + 1` 
 
341
  esac
 
342
 
 
343
  test $CNT -lt 4  &&
 
344
    echo "Errors were found with the problem report."
 
345
 
 
346
 
 
347
  #       Check if subject of mail was changed, if not, use Synopsis field
 
348
  #
 
349
  subject=`grep "^Subject" $TEMP| sed 's/^Subject:[     ]*//'`
 
350
  if [ X"$subject" = X"$SUBJECT_C" -o X"$subject" = X"$SYNOPSIS_C" ]; then
 
351
    subject=`grep Synopsis $TEMP | sed 's/>Synopsis:[     ]*//'`
 
352
    sed "s/^Subject:[   ]*.*/Subject: $subject/" $TEMP > $TEMP.tmp
 
353
    mv -f $TEMP.tmp $TEMP
 
354
  fi
 
355
 
 
356
  while :; do
 
357
    $ECHON1 "a)bort, e)dit or s)end? $ECHON2"
 
358
    read input
 
359
    case "$input" in
 
360
      a*)
 
361
        echo "$COMMAND: problem report saved in $HOME/dead.mysqlbug."
 
362
        cat $TEMP >> $HOME/dead.mysqlbug
 
363
        xs=1; exit
 
364
        ;;
 
365
      e*)
 
366
        eval $EDIT $TEMP
 
367
        continue 2
 
368
        ;;
 
369
      s*)
 
370
        break 2
 
371
        ;;
 
372
    esac
 
373
  done
 
374
done
 
375
#
 
376
#       Remove comments and send the problem report
 
377
#       (we have to use patterns, where the comment contains regex chars)
 
378
#
 
379
# /^>Originator:/s;$ORIGINATOR;;
 
380
sed  -e "
 
381
/^SEND-PR:/d
 
382
/^>Organization:/,/^>[A-Za-z-]*:/s;$ORGANIZATION_C;;
 
383
/^>Confidential:/s;<.*>;;
 
384
/^>Synopsis:/s;$SYNOPSIS_C;;
 
385
/^>Severity:/s;<.*>;;
 
386
/^>Priority:/s;<.*>;;
 
387
/^>Class:/s;<.*>;;
 
388
/^>Release:/,/^>[A-Za-z-]*:/s;$RELEASE_C;;
 
389
/^>Environment:/,/^>[A-Za-z-]*:/s;$ENVIRONMENT_C;;
 
390
/^>Description:/,/^>[A-Za-z-]*:/s;$DESCRIPTION_C;;
 
391
/^>How-To-Repeat:/,/^>[A-Za-z-]*:/s;$HOW_TO_REPEAT_C;;
 
392
/^>Fix:/,/^>[A-Za-z-]*:/s;$FIX_C;;
 
393
" $TEMP > $TEMP.x
 
394
 
 
395
if $MAIL_AGENT < $TEMP.x
 
396
then
 
397
  echo "$COMMAND: problem report sent"
 
398
  xs=0; exit
 
399
else
 
400
  echo "$COMMAND: mysterious mail failure, report not sent."
 
401
  echo "$COMMAND: problem report saved in $HOME/dead.mysqlbug."
 
402
  cat $TEMP >> $HOME/dead.mysqlbug
 
403
fi
 
404
 
 
405
exit 0