#!/usr/bin/perl -w
# The LearningOnline Network 
# Red Hat 7.3 installation script
#
# $Id: configure_mysql_db.pl,v 1.1 2003/04/29 19:09:56 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA 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.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# http://www.lon-capa.org/
#

##
## Set up mysql
##
print("Setting mysqld to start on boot up.\n");
system("/sbin/chkconfig --add mysqld");
system("/sbin/chkconfig mysqld on");
print(`/sbin/chkconfig --list mysqld`);

print("mysql links created successfully\n");
print(`/etc/rc.d/init.d/mysqld start`);
print("Waiting for mysql daemon to start.\n");
sleep 5;
my $status = system("/etc/rc.d/init.d/mysqld status");
if ($status != 0) {
    die "Unable to start mysql daemon\nHalting\n";
} else {
    print("Mysql daemon is running.\n");
}
print("\n");

##
## Get root password for mysql client
##
print <<END;
Please enter a root password for the mysql database.
It does not have to match your root account password, but you will need
to remember it.
END
my $rootpass = <>;
chomp $rootpass;
print("\n");

##
## Run the damn thing (mysql, not LON-CAPA)
##
print("Starting mysql client.\n");
open MYSQL, "|mysql -u root mysql" || die "Unable to start mysql\n";
print MYSQL <<"ENDMYSQL";
CREATE DATABASE loncapa;
INSERT INTO user (Host, User, Password)
VALUES ('localhost','www',password('localhostkey'));
INSERT INTO db VALUES ('localhost','loncapa','www',
'Y','Y','Y','Y','Y','Y','N','Y','Y','Y');
SET PASSWORD FOR root\@localhost=PASSWORD('$rootpass');
DELETE FROM user WHERE host<>'localhost';
FLUSH PRIVILEGES;
USE loncapa;
CREATE TABLE IF NOT EXISTS metadata (title TEXT, author TEXT, subject TEXT, url TEXT, keywords TEXT, version TEXT, notes TEXT, abstract TEXT, mime TEXT, language TEXT, creationdate DATETIME, lastrevisiondate DATETIME, owner TEXT, copyright TEXT, FULLTEXT idx_title (title), FULLTEXT idx_author (author), FULLTEXT idx_subject (subject), FULLTEXT idx_url (url), FULLTEXT idx_keywords (keywords), FULLTEXT idx_version (version), FULLTEXT idx_notes (notes), FULLTEXT idx_abstract (abstract), FULLTEXT idx_mime (mime), FULLTEXT idx_language (language), FULLTEXT idx_owner (owner), FULLTEXT idx_copyright (copyright)) TYPE=MYISAM;
EXIT
ENDMYSQL

close MYSQL;

