~percona-toolkit-dev/percona-toolkit/2.2

« back to all changes in this revision

Viewing changes to lib/bash/mysql_options.sh

Merge pt-ms-pt-stalk-standard-mysql-options.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This program is copyright 2011 Percona Inc.
 
2
# Feedback and improvements are welcome.
 
3
#
 
4
# THIS PROGRAM IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
 
5
# WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 
6
# MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 
7
#
 
8
# This program is free software; you can redistribute it and/or modify it under
 
9
# the terms of the GNU General Public License as published by the Free Software
 
10
# Foundation, version 2; OR the Perl Artistic License.  On UNIX and similar
 
11
# systems, you can issue `man perlgpl' or `man perlartistic' to read these
 
12
# licenses.
 
13
#
 
14
# You should have received a copy of the GNU General Public License along with
 
15
# this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 
16
# Place, Suite 330, Boston, MA  02111-1307  USA.
 
17
# ###########################################################################
 
18
# mysql_options package
 
19
# ###########################################################################
 
20
 
 
21
# Package: mysql_options
 
22
# Handle --defaults-file & related options
 
23
 
 
24
set -u
 
25
 
 
26
mysql_options() {
 
27
   local MYSQL_ARGS=""
 
28
   if [ -n "$OPT_DEFAULTS_FILE" ]; then
 
29
      MYSQL_ARGS="--defaults-file=$OPT_DEFAULTS_FILE"
 
30
   fi
 
31
   if [ -n "$OPT_PORT" ]; then
 
32
      MYSQL_ARGS="$MYSQL_ARGS --port=$OPT_PORT"
 
33
   fi
 
34
   if [ -n "$OPT_SOCKET" ]; then
 
35
      MYSQL_ARGS="$MYSQL_ARGS --socket=$OPT_SOCKET"
 
36
   fi
 
37
   if [ -n "$OPT_HOST" ]; then
 
38
      MYSQL_ARGS="$MYSQL_ARGS --host=$OPT_HOST"
 
39
   fi
 
40
   if [ -n "$OPT_USER" ]; then
 
41
      MYSQL_ARGS="$MYSQL_ARGS --user=$OPT_USER"
 
42
   fi
 
43
   if [ -n "$OPT_PASSWORD" ]; then
 
44
      MYSQL_ARGS="$MYSQL_ARGS --password=$OPT_PASSWORD"
 
45
   fi
 
46
   
 
47
   echo $MYSQL_ARGS
 
48
}
 
49
 
 
50
# This basically makes sure that --defaults-file comes first
 
51
arrange_mysql_options() {
 
52
   local opts="$1"
 
53
   
 
54
   local rearranged=""
 
55
   for opt in $opts; do
 
56
      if [ "$(echo $opt | awk -F= '{print $1}')" = "--defaults-file" ]; then
 
57
          rearranged="$opt $rearranged"
 
58
      else
 
59
         rearranged="$rearranged $opt"
 
60
      fi
 
61
   done
 
62
   
 
63
   echo "$rearranged"
 
64
}
 
65
 
 
66
# ###########################################################################
 
67
# End mysql_options package
 
68
# ###########################################################################