2006-05-12 09:42:59 +00:00
|
|
|
|
#!/bin/sh
|
2006-04-26 12:28:53 +00:00
|
|
|
|
#
|
|
|
|
|
# $Id: mysql.sh,v 1.11 2006/01/11 22:51:28 anarcat Exp $
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
# AlternC - Web Hosting System
|
|
|
|
|
# Copyright (C) 2002 by the AlternC Development Team.
|
|
|
|
|
# http://alternc.org/
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
# Based on:
|
|
|
|
|
# Valentin Lacambre's web hosting softwares: http://altern.org/
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
# LICENSE
|
|
|
|
|
#
|
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
|
# modify it under the terms of the GNU General Public License (GPL)
|
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
|
#
|
|
|
|
|
# To read the license please visit http://www.gnu.org/copyleft/gpl.html
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
# Original Author of file: Benjamin Sonntag
|
|
|
|
|
# Purpose of file: Install a fresh new mysql database system
|
|
|
|
|
# USAGE : "mysql.sh loginroot passroot systemdb"
|
|
|
|
|
# ----------------------------------------------------------------------
|
|
|
|
|
#
|
|
|
|
|
|
2007-08-23 08:24:15 +00:00
|
|
|
|
sqlserver="$1"
|
|
|
|
|
rootlogin="$2"
|
|
|
|
|
rootpass="$3"
|
|
|
|
|
systemdb="$4"
|
2006-05-12 09:42:59 +00:00
|
|
|
|
|
|
|
|
|
if [ -z "$rootlogin" -o -z "$rootpass" -o -z "$systemdb" ]
|
|
|
|
|
then
|
2007-08-23 08:24:15 +00:00
|
|
|
|
echo "Usage: mysql.sh <mysqlserver> <rootlogin> <rootpass> <systemdb>"
|
2006-05-12 09:42:59 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
2007-08-23 08:24:15 +00:00
|
|
|
|
mysql="/usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf -h$sqlserver "
|
2006-04-26 12:28:53 +00:00
|
|
|
|
|
2006-05-12 09:42:59 +00:00
|
|
|
|
# The grant all is the most important right needed in this script.
|
|
|
|
|
# If this call fail, we may be connected to a mysql-server version 5.0.
|
|
|
|
|
echo "Granting users "
|
2007-08-27 16:33:31 +00:00
|
|
|
|
#<23>In that case, change mysql parameters and retry. Use root / nopassword.
|
2006-05-12 09:42:59 +00:00
|
|
|
|
$mysql -e "GRANT ALL ON *.* TO '$rootlogin'@'${MYSQL_CLIENT}' IDENTIFIED BY '$rootpass' WITH GRANT OPTION"
|
|
|
|
|
if [ "$?" -ne "0" ]
|
|
|
|
|
then
|
2007-08-27 16:33:31 +00:00
|
|
|
|
echo "debian-sys-maintainer doesn't have the right credentials, assuming we're doing an upgrade"
|
|
|
|
|
mysql="/usr/bin/mysql -h$sqlserver -u$rootlogin -p$rootpass"
|
2006-05-12 09:42:59 +00:00
|
|
|
|
$mysql -e "GRANT ALL ON *.* TO '$rootlogin'@'${MYSQL_CLIENT}' IDENTIFIED BY '$rootpass' WITH GRANT OPTION"
|
|
|
|
|
if [ "$?" -ne "0" ]
|
|
|
|
|
then
|
2007-08-27 16:33:31 +00:00
|
|
|
|
echo "Still not working, assuming clean install and empty root password"
|
|
|
|
|
mysql="/usr/bin/mysql -h$sqlserver -uroot "
|
|
|
|
|
$mysql -e "GRANT ALL ON *.* TO '$rootlogin'@'${MYSQL_CLIENT}' IDENTIFIED BY '$rootpass' WITH GRANT OPTION"
|
|
|
|
|
if [ "$?" -ne "0" ]
|
|
|
|
|
then
|
2007-12-12 22:16:17 +00:00
|
|
|
|
echo "Can't grant system user $rootlogin, aborting";
|
2007-08-27 16:33:31 +00:00
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2006-05-12 09:42:59 +00:00
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Now we can use rootlogin and rootpass.
|
2007-08-23 08:24:15 +00:00
|
|
|
|
mysql="/usr/bin/mysql -h$sqlserver -u$rootlogin -p$rootpass"
|
2006-05-12 09:42:59 +00:00
|
|
|
|
|
|
|
|
|
echo "Setting AlternC '$systemdb' system table and privileges "
|
2006-04-26 12:28:53 +00:00
|
|
|
|
$mysql -e "CREATE DATABASE IF NOT EXISTS $systemdb;"
|
2006-05-12 09:42:59 +00:00
|
|
|
|
|
2006-04-26 12:28:53 +00:00
|
|
|
|
echo "Installing AlternC schema "
|
|
|
|
|
$mysql $systemdb < /usr/share/alternc/install/mysql.sql
|
|
|
|
|
|
2007-08-23 08:24:15 +00:00
|
|
|
|
/usr/bin/mysql -h$sqlserver -u$rootlogin -p$rootpass $systemdb -e "SHOW TABLES" >/dev/null && echo "MYSQL.SH OK!" || echo "MYSQL.SH FAILED!"
|