#!/bin/sh # # $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" # ---------------------------------------------------------------------- # # This script expects the following environment to exist: # * host # * user # * password # * database # * alternc_mail_user # * alternc_mail_password # * MYSQL_CLIENT # # XXX: the sed script should be generated here # # So this file should generally be sourced like this: # . /usr/share/alternc/install/mysql.sh # # Those values are used to set the username/passwords... # The grant all is the most important right needed in this script. echo "Granting users..." MYSQL_CONFIG="/etc/alternc/my.cnf" MYSQL_MAIL_CONFIG="/etc/alternc/my_mail.cnf" . /etc/alternc/local.sh # the purpose of this "grant" is to make sure that the generated my.cnf works # this means (a) creating the user and (b) creating the database grant="GRANT ALL ON *.* TO '$user'@'${MYSQL_CLIENT}' IDENTIFIED BY '$password' WITH GRANT OPTION; CREATE DATABASE IF NOT EXISTS $database; " grant_mail="GRANT ALL ON $database.dovecot_view TO '$alternc_mail_user'@'${MYSQL_CLIENT}' IDENTIFIED BY '$alternc_mail_password';" grant_mail=$grant_mail"GRANT SELECT ON $database.* TO '$alternc_mail_user'@'${MYSQL_CLIENT}' IDENTIFIED BY '$alternc_mail_password';" echo -n "Trying debian.cnf: " mysql="/usr/bin/mysql --defaults-file=/etc/mysql/debian.cnf" # If this call fail, we may be connected to a mysql-server version 5.0. # In that case, change mysql parameters and retry. Use root / nopassword. if ! $mysql < $MYSQL_CONFIG < $MYSQL_MAIL_CONFIG < $SED_SCRIPT_NAME < $MYSQL_CONFIG.$$ mv -f $MYSQL_CONFIG.$$ $MYSQL_CONFIG rm -f $SED_SCRIPT_NAME SED_SCRIPT_NAME_MAIL=`mktemp` cat > $SED_SCRIPT_NAME_MAIL < $MYSQL_MAIL_CONFIG.$$ mv -f $MYSQL_MAIL_CONFIG.$$ $MYSQL_MAIL_CONFIG rm -f $SED_SCRIPT_NAME_MAIL # Now we should be able to use the mysql configuration mysql="/usr/bin/mysql --defaults-file=$MYSQL_CONFIG" mysql_mail="/usr/bin/mysql --defaults-file=$MYSQL_MAIL_CONFIG" echo "Checking for MySQL connectivity" $mysql -e "SHOW TABLES" >/dev/null && echo "MYSQL.SH OK!" || echo "MYSQL.SH FAILED: database user setup failed" # Final mysql setup: db schema echo "installing AlternC schema in $database..." $mysql < /usr/share/alternc/install/mysql.sql || echo cannot load database schema $mysql <