version 1.1, 2003/04/29 19:09:56
|
version 1.3, 2003/08/22 22:30:50
|
Line 24
|
Line 24
|
# |
# |
# http://www.lon-capa.org/ |
# http://www.lon-capa.org/ |
# |
# |
|
use strict; |
|
use lib '/home/httpd/lib/perl/'; |
|
use LONCAPA::Configuration; |
|
|
|
my $runstatus = shift(); |
|
if (! defined($runstatus)) { |
|
$runstatus = 'firstrun'; |
|
} |
|
my $rhver=`perl ../build/distprobe`; |
|
my $rpmname; |
|
if ($rhver eq 'redhat9') { |
|
$rpmname = "perl-DBD-MySQL-2.9002-1.i386.rpm"; |
|
} else { |
|
$rpmname = "perl-DBD-MySQL-1.2216-4.i386.rpm"; |
|
} |
|
|
|
my $perlvar = &LONCAPA::Configuration::read_conf('loncapa.conf'); |
|
delete($perlvar->{'lonReceipt'}); # remove since sensitive and not needed |
|
|
## |
## |
## Set up mysql |
## Set up mysql to run on boot |
## |
## |
print("Setting mysqld to start on boot up.\n"); |
my $add_result = system("/sbin/chkconfig --add mysqld 2>/dev/null"); |
system("/sbin/chkconfig --add mysqld"); |
my $on_result = system("/sbin/chkconfig mysqld on 2>/dev/null"); |
system("/sbin/chkconfig mysqld on"); |
if ($add_result != 0 || $on_result != 0) { |
print(`/sbin/chkconfig --list mysqld`); |
print "Your system is misconfigured. ". |
|
"You do not have MySQL installed.\n"; |
print("mysql links created successfully\n"); |
exit 1; |
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"); |
## Make sure it is running now |
|
## |
|
my $status = system("/etc/rc.d/init.d/mysqld status 1>/dev/null"); |
if ($status != 0) { |
if ($status != 0) { |
die "Unable to start mysql daemon\nHalting\n"; |
print(`/etc/rc.d/init.d/mysqld restart`); |
} else { |
print("Waiting 5 seconds for mysql daemon to restart.\n"); |
print("Mysql daemon is running.\n"); |
sleep 5; |
|
my $status = system("/etc/rc.d/init.d/mysqld status"); |
|
if ($status != 0) { |
|
die "Unable to start mysql daemon\nHalting\n"; |
|
} |
} |
} |
print("\n"); |
|
|
|
## |
## |
## Get root password for mysql client |
## Make sure the mysql is configured |
## |
## |
print <<END; |
if ($runstatus eq 'firstrun' && (! exists($perlvar->{'lonSqlAccess'}) || |
Please enter a root password for the mysql database. |
! defined($perlvar->{'lonSqlAccess'}))) { |
|
## |
|
## 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 |
It does not have to match your root account password, but you will need |
to remember it. |
to remember it. |
END |
END |
my $rootpass = <>; |
my $rootpass = <>; |
chomp $rootpass; |
chomp $rootpass; |
print("\n"); |
print("\n"); |
|
|
## |
my $extraargs; |
## Run the damn thing (mysql, not LON-CAPA) |
if ($rhver eq 'redhat9') { $extraargs=",'Y','Y'"; } |
## |
print("Starting mysql client and setting up permissions\n"); |
print("Starting mysql client.\n"); |
open MYSQL, "|mysql -u root mysql" || die "Unable to start mysql\n"; |
open MYSQL, "|mysql -u root mysql" || die "Unable to start mysql\n"; |
print MYSQL <<"ENDMYSQLPERMISSIONINIT"; |
print MYSQL <<"ENDMYSQL"; |
CREATE DATABASE IF NOT EXISTS loncapa; |
CREATE DATABASE loncapa; |
USE mysql; |
INSERT INTO user (Host, User, Password) |
INSERT IGNORE INTO user (Host, User, Password) |
VALUES ('localhost','www',password('localhostkey')); |
VALUES ('localhost','www',password('localhostkey')); |
INSERT INTO db VALUES ('localhost','loncapa','www', |
INSERT IGNORE INTO db VALUES ('localhost','loncapa','www', |
'Y','Y','Y','Y','Y','Y','N','Y','Y','Y'); |
'Y','Y','Y','Y','Y','Y','N','Y','Y','Y'$extraargs); |
SET PASSWORD FOR root\@localhost=PASSWORD('$rootpass'); |
SET PASSWORD FOR root\@localhost=PASSWORD('$rootpass'); |
DELETE FROM user WHERE host<>'localhost'; |
DELETE FROM user WHERE host<>'localhost'; |
FLUSH PRIVILEGES; |
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 |
EXIT |
ENDMYSQL |
ENDMYSQLPERMISSIONINIT |
|
$perlvar->{'lonSqlAccess'} = 'localhostkey'; |
|
} |
|
|
|
my $dbi_is_present = eval "use DBI;"; # will be defined on error |
|
if (defined($dbi_is_present)) { |
|
print "Your system is misconfigured. ". |
|
"You are missing the perl DBI package\n"; |
|
exit 1; |
|
} else { |
|
use DBI; |
|
} |
|
|
|
my $dbh; |
|
my $MySQL_Check = eval '$dbh = DBI->connect("DBI:mysql:loncapa","www",$perlvar->{\'lonSqlAccess\'});'; |
|
if (! defined($MySQL_Check)) { |
|
if ($runstatus ne 'firstrun') { |
|
print "Your system is misconfigured.\n"; |
|
exit 1; |
|
} |
|
# |
|
# Try to install from the current directory. |
|
# This is potentially dangerous |
|
my $install_result = system("rpm -Uvh $rpmname 2>/dev/null 1>/dev/null"); |
|
if (defined($install_result) && $install_result ne '0') { |
|
print "Your system is misconfigured. ". |
|
"You are missing the perl DBD MySQL package\n"; |
|
exit 1; |
|
} |
|
exec "./".$0." secondrun"; |
|
} |
|
|
|
use DBI; |
|
$dbh = DBI->connect("DBI:mysql:loncapa","www",$perlvar->{'lonSqlAccess'}); |
|
if (! defined($dbh)) { |
|
die "Unable to connect to mysql database.\n"; |
|
} |
|
$dbh->do(<<ENDDBINIT); |
|
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 |
|
ENDDBINIT |
|
|
|
$dbh->do(<<ENDDBINIT); |
|
CREATE TABLE IF NOT EXISTS dynamicmetadata (url TEXT NOT NULL, |
|
count INT UNSIGNED, |
|
num_uses INT UNSIGNED, |
|
clear REAL UNSIGNED, |
|
depth REAL UNSIGNED, |
|
helpful REAL UNSIGNED, |
|
correct REAL UNSIGNED, |
|
technical REAL UNSIGNED, |
|
avetries REAL UNSIGNED, |
|
stdno INT UNSIGNED) |
|
|
|
ENDDBINIT |
|
|
|
if ($dbh->err) { |
|
print "Error creating tables: ".$dbh->errstr()."\n"; |
|
} |
|
$dbh->disconnect(); |
|
|
close MYSQL; |
|
|
|