~drizzle-trunk/drizzle/development

1 by brian
clean slate
1
#!/bin/sh
2
# Copyright (C) 2000-2006 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
# This script is a wrapper to pipe the mysql_fix_privilege_tables.sql
18
# through the mysql client program to the mysqld server
19
20
# Default values (Can be changed in my.cnf)
21
password=""
22
host="localhost"
23
user="root"
24
sql_only=0
25
basedir="@prefix@"
26
verbose=0
27
args=""
28
# no elaborate fallback here; with no argument, it will happen in "mysql"
29
port=""
30
socket=""
31
database="mysql"
32
bindir=""
33
pkgdatadir="@pkgdatadir@"
34
print_defaults_bindir="."
35
36
file=mysql_fix_privilege_tables.sql
37
38
# The following test is to make this script compatible with the 4.0 where
39
# the single argument could be a password
40
if test "$#" = 1
41
then
42
  case "$1" in
43
  --*) ;;
44
  *) old_style_password="$1" ; shift ;;
45
  esac
46
fi
47
48
# The following code is almost identical to the code in mysql_install_db.sh
49
50
case "$1" in
51
    --no-defaults|--defaults-file=*|--defaults-extra-file=*)
52
      defaults="$1"; shift
53
      ;;
54
esac
55
56
parse_arguments() {
57
  # We only need to pass arguments through to the server if we don't
58
  # handle them here.  So, we collect unrecognized options (passed on
59
  # the command line) into the args variable.
60
  pick_args=
61
  if test "$1" = PICK-ARGS-FROM-ARGV
62
  then
63
    pick_args=1
64
    shift
65
  fi
66
67
  for arg do
68
    case "$arg" in
69
      --basedir=*) basedir=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
70
      --user=*) user=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
71
      --password=*) password=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
72
      --host=*) host=`echo "$arg" | sed -e 's/^[^=]*=//'` ;;
73
      --sql|--sql-only) sql_only=1 ;;
74
      --verbose) verbose=1 ;;
75
      --port=*) port=`echo "$arg" | sed -e "s;--port=;;"` ;;
76
      --socket=*) socket=`echo "$arg" | sed -e "s;--socket=;;"` ;;
77
      --database=*) database=`echo "$arg" | sed -e "s;--database=;;"` ;;
78
      --bindir=*) bindir=`echo "$arg" | sed -e "s;--bindir=;;"`
79
                  print_defaults_bindir=$bindir
80
		  ;;
81
      *)
82
        if test -n "$pick_args"
83
        then
84
          # This sed command makes sure that any special chars are quoted,
85
          # so the arg gets passed exactly to the server.
86
          args="$args "`echo "$arg" | sed -e 's,\([^=a-zA-Z0-9_.-]\),\\\\\1,g'`
87
        fi
88
        ;;
89
    esac
90
  done
91
}
92
93
# Get first arguments from the my.cfg file, groups [mysqld] and
94
# [mysql_install_db], and then merge with the command line arguments
95
96
print_defaults=my_print_defaults
97
for dir in ./bin @bindir@ @bindir@ extra $print_defaults_bindir/../bin $print_defaults_bindir/../extra
98
do
99
  if test -x $dir/my_print_defaults
100
  then
101
    print_defaults="$dir/my_print_defaults"
102
    break
103
  fi
104
done
105
106
parse_arguments `$print_defaults $defaults mysql_install_db mysql_fix_privilege_tables`
107
parse_arguments PICK-ARGS-FROM-ARGV "$@"
108
109
if test -z "$password"
110
then
111
  password=$old_style_password
112
fi
113
114
# Find where 'mysql' command is located
115
116
dirname=`dirname "$0"`
117
118
if test -z "$bindir"
119
then
120
  for i in @bindir@ $basedir/bin "$dirname/../client"
121
  do
122
    if test -f $i/mysql
123
    then
124
      bindir=$i
125
      break
126
    fi
127
  done
128
fi
129
130
if test -z "$bindir"
131
then
132
  echo "Could not find MySQL command-line client (mysql)."
133
  echo "Please use --basedir to specify the directory where MySQL is installed."
134
  exit 1
135
fi
136
137
cmd="$bindir/mysql --no-defaults --force --user=$user --host=$host"
138
if test ! -z "$port"; then
139
  cmd="$cmd --port=$port"
140
fi
141
if test ! -z "$socket"; then
142
  cmd="$cmd --socket=$socket"
143
fi
144
cmd="$cmd --database=$database"
145
146
if test $sql_only = 1
147
then
148
  cmd="cat"
149
fi
150
151
# Find where first mysql_fix_privilege_tables.sql is located
152
for i in $basedir/support-files $basedir/share $basedir/share/mysql \
153
        $basedir/scripts $pkgdatadir . "$dirname"
154
do
155
  if test -f $i/$file
156
  then
157
    pkgdatadir=$i
158
    break
159
  fi
160
done
161
162
sql_file="$pkgdatadir/$file"
163
if test ! -f $sql_file
164
then
165
  echo "Could not find file '$file'."
166
  echo "Please use --basedir to specify the directory where MySQL is installed"
167
  exit 1
168
fi
169
170
s_echo()
171
{
172
   if test $sql_only = 0
173
   then
174
     echo $1
175
   fi
176
}
177
178
s_echo "This script updates all the mysql privilege tables to be usable by"
179
s_echo "the current version of MySQL"
180
s_echo ""
181
182
if test $verbose = 1
183
then
184
  s_echo "You can safely ignore all 'Duplicate column' and 'Unknown column' errors"
185
  s_echo "because these just mean that your tables are already up to date."
186
  s_echo "This script is safe to run even if your tables are already up to date!"
187
  s_echo ""
188
fi
189
190
run_cmd() {
191
  # Password argument is added here to allow for spaces in password.
192
  
193
  if test ! -z "$password"
194
  then
195
    cat $sql_file | $cmd --password="$password"
196
  else
197
    cat $sql_file | $cmd
198
  fi
199
}
200
201
if test $verbose = 0
202
then
203
  run_cmd > /dev/null 2>&1
204
else
205
  run_cmd > /dev/null
206
fi
207
if test $? = 0
208
then
209
  s_echo "done"
210
else
211
  s_echo "Got a failure from command:"
212
  s_echo "cat $sql_file | $cmd"
213
  s_echo "Please check the above output and try again."
214
  if test $verbose = 0
215
  then
216
    s_echo ""
217
    s_echo "Running the script with the --verbose option may give you some information"
218
    s_echo "of what went wrong."
219
  fi
220
  s_echo ""
221
  s_echo "If you get an 'Access denied' error, you should run this script again and"
222
  s_echo "give the MySQL root user password as an argument with the --password= option"
223
fi