PageRenderTime 57ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/scripts/mysqlbug.sh

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