mysqlbug
上传用户:dzyhzl
上传日期:2019-04-29
资源大小:56270k
文件大小:10k
源码类别:

模拟服务器

开发平台:

C/C++

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