Changeset 1617

Show
Ignore:
Timestamp:
05/12/06 11:42:59 (2 years ago)
Author:
benjamin
Message:

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

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • alternc/trunk/install/mysql.sh

    r889 r1617  
    1 #!/bin/sh -e 
     1#!/bin/sh  
    22# 
    33# $Id: mysql.sh,v 1.11 2006/01/11 22:51:28 anarcat Exp $ 
     
    2929# ---------------------------------------------------------------------- 
    3030# 
    31 rootlogin=$1 
    32 rootpass=$2 
    33 systemdb=$3 
    3431 
    35 mysql="mysql --defaults-file=/etc/mysql/debian.cnf" 
     32rootlogin="$1" 
     33rootpass="$2" 
     34systemdb="$3" 
     35 
     36if [ -z "$rootlogin" -o -z "$rootpass" -o -z "$systemdb" ] 
     37then 
     38    echo "Usage: mysql.sh <rootlogin> <rootpass> <systemdb>" 
     39    exit 1 
     40fi 
     41 
     42mysql="/usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf" 
    3643 
    3744if ! $mysql mysql -e "SHOW TABLES" >/dev/null 
    3845then 
    3946    # is this an upgrade then? 
    40     mysql="mysql -u $rootlogin -p$rootpass"  
     47    mysql="/usr/bin/mysql -u$rootlogin -p$rootpass"  
    4148    if ! $mysql mysql -e "SHOW TABLES" >/dev/null 
    4249    then 
     
    4653fi 
    4754 
    48 echo "Setting AlternC $systemdb system table and privileges " 
     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. 
     57echo "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" 
     60if [ "$?" -ne "0" ] 
     61then 
     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 
     71fi 
     72 
     73# Now we can use rootlogin and rootpass.  
     74mysql="/usr/bin/mysql -u$rootlogin -p$rootpass"  
     75 
     76echo "Setting AlternC '$systemdb' system table and privileges " 
    4977$mysql -e "CREATE DATABASE IF NOT EXISTS $systemdb;"  
     78 
    5079echo "Installing AlternC schema " 
    5180$mysql $systemdb < /usr/share/alternc/install/mysql.sql 
    5281 
    53 echo "Granting users " 
    54 $mysql -e "GRANT ALL ON *.* TO '$rootlogin'@'${MYSQL_CLIENT}' IDENTIFIED BY '$rootpass' WITH GRANT OPTION"  
    55  
    56 mysql -u $rootlogin -p$rootpass $systemdb -e "SHOW TABLES" >/dev/null && echo "MYSQL.SH OK!" || echo "MYSQL.SH FAILED!" 
     82/usr/bin/mysql -u$rootlogin -p$rootpass $systemdb -e "SHOW TABLES" >/dev/null && echo "MYSQL.SH OK!" || echo "MYSQL.SH FAILED!"