root/alternc/tags/0.9.7/install/mysql.sh

Revision 1914, 3.1 kB (checked in by anarcat, 1 year ago)

instead of assuming that SHOW TABLES; gives us GRANT privileges, simply try to GRANT with our multiple techniques

Fixes: #1060

  • Property svn:executable set to *
Line 
1 #!/bin/sh
2 #
3 # $Id: mysql.sh,v 1.11 2006/01/11 22:51:28 anarcat Exp $
4 # ----------------------------------------------------------------------
5 # AlternC - Web Hosting System
6 # Copyright (C) 2002 by the AlternC Development Team.
7 # http://alternc.org/
8 # ----------------------------------------------------------------------
9 # Based on:
10 # Valentin Lacambre's web hosting softwares: http://altern.org/
11 # ----------------------------------------------------------------------
12 # LICENSE
13 #
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License (GPL)
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
18 #
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23 #
24 # To read the license please visit http://www.gnu.org/copyleft/gpl.html
25 # ----------------------------------------------------------------------
26 # Original Author of file: Benjamin Sonntag
27 # Purpose of file: Install a fresh new mysql database system
28 # USAGE : "mysql.sh loginroot passroot systemdb"
29 # ----------------------------------------------------------------------
30 #
31
32 sqlserver="$1"
33 rootlogin="$2"
34 rootpass="$3"
35 systemdb="$4"
36
37 if [ -z "$rootlogin" -o -z "$rootpass" -o -z "$systemdb" ]
38 then
39     echo "Usage: mysql.sh <mysqlserver> <rootlogin> <rootpass> <systemdb>"
40     exit 1
41 fi
42
43 mysql="/usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf -h$sqlserver "
44
45 # The grant all is the most important right needed in this script.
46 # If this call fail, we may be connected to a mysql-server version 5.0.
47 echo "Granting users "
48 # In that case, change mysql parameters and retry. Use root / nopassword.
49 $mysql -e "GRANT ALL ON *.* TO '$rootlogin'@'${MYSQL_CLIENT}' IDENTIFIED BY '$rootpass' WITH GRANT OPTION"
50 if [ "$?" -ne "0" ]
51 then
52     echo "debian-sys-maintainer doesn't have the right credentials, assuming we're doing an upgrade"
53     mysql="/usr/bin/mysql -h$sqlserver -u$rootlogin -p$rootpass"
54     $mysql -e "GRANT ALL ON *.* TO '$rootlogin'@'${MYSQL_CLIENT}' IDENTIFIED BY '$rootpass' WITH GRANT OPTION"
55     if [ "$?" -ne "0" ]
56         then
57         echo "Still not working, assuming clean install and empty root password"
58         mysql="/usr/bin/mysql -h$sqlserver -uroot "
59         $mysql -e "GRANT ALL ON *.* TO '$rootlogin'@'${MYSQL_CLIENT}' IDENTIFIED BY '$rootpass' WITH GRANT OPTION"
60         if [ "$?" -ne "0" ]
61         then
62             echo "Can't grant system user $rootlogin, abording";
63             exit 1
64         fi
65     fi
66 fi
67
68 # Now we can use rootlogin and rootpass.
69 mysql="/usr/bin/mysql -h$sqlserver -u$rootlogin -p$rootpass" 
70
71 echo "Setting AlternC '$systemdb' system table and privileges "
72 $mysql -e "CREATE DATABASE IF NOT EXISTS $systemdb;"
73
74 echo "Installing AlternC schema "
75 $mysql $systemdb < /usr/share/alternc/install/mysql.sql
76
77 /usr/bin/mysql -h$sqlserver -u$rootlogin -p$rootpass $systemdb -e "SHOW TABLES" >/dev/null && echo "MYSQL.SH OK!" || echo "MYSQL.SH FAILED!"
Note: See TracBrowser for help on using the browser.