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

Revision 1617, 3.0 kB (checked in by benjamin, 3 years ago)

changing mysql.sh for install/upgrade time so that it work with mysql5 debian version also (debian-sys-maint with limited rights)

  • 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 rootlogin="$1"
33 rootpass="$2"
34 systemdb="$3"
35
36 if [ -z "$rootlogin" -o -z "$rootpass" -o -z "$systemdb" ]
37 then
38     echo "Usage: mysql.sh <rootlogin> <rootpass> <systemdb>"
39     exit 1
40 fi
41
42 mysql="/usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf"
43
44 if ! $mysql mysql -e "SHOW TABLES" >/dev/null
45 then
46     # is this an upgrade then?
47     mysql="/usr/bin/mysql -u$rootlogin -p$rootpass"
48     if ! $mysql mysql -e "SHOW TABLES" >/dev/null
49     then
50         echo "Can't get proper credentials, aborting"
51         exit 1
52     fi
53 fi
54
55 # The grant all is the most important right needed in this script.
56 # If this call fail, we may be connected to a mysql-server version 5.0.
57 echo "Granting users "
58     # In that case, change mysql parameters and retry. Use root / nopassword.
59 $mysql -e "GRANT ALL ON *.* TO '$rootlogin'@'${MYSQL_CLIENT}' IDENTIFIED BY '$rootpass' WITH GRANT OPTION"
60 if [ "$?" -ne "0" ]
61 then
62     echo "You are using mysql 5.0, so we try with root account and no password since debian-sys-maint doesn't work."
63     mysql="/usr/bin/mysql -uroot "
64     echo "Granting users "
65     $mysql -e "GRANT ALL ON *.* TO '$rootlogin'@'${MYSQL_CLIENT}' IDENTIFIED BY '$rootpass' WITH GRANT OPTION"
66     if [ "$?" -ne "0" ]
67         then
68         echo "Can't grant system user $rootlogin, abording";
69         exit 1
70     fi
71 fi
72
73 # Now we can use rootlogin and rootpass.
74 mysql="/usr/bin/mysql -u$rootlogin -p$rootpass" 
75
76 echo "Setting AlternC '$systemdb' system table and privileges "
77 $mysql -e "CREATE DATABASE IF NOT EXISTS $systemdb;"
78
79 echo "Installing AlternC schema "
80 $mysql $systemdb < /usr/share/alternc/install/mysql.sql
81
82 /usr/bin/mysql -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.