#!/usr/bin/perl -w
# The LearningOnline Network
# Red Hat 7.3 installation script
#
# $Id: install.pl,v 1.3 2002/06/27 20:45:36 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/
#
##
## Obvious flaws of this program:
## Dieing on every error may be a little extreme. On the other hand,
## how the heck am I supposed to know what absurd things the user
## has done with their system before inflicting LON-CAPA on it?
## The links to /etc/init.d for httpd and mysqld do not seem to work :(
## The user is never informed of the log file (/tmp/loncapa_install.log).
## It does not test the system at the end. Again, there are limits to
## what nonsense we can put up with. Of course, we will have to
## explain that to people at some point...
## There is probably an overuse of elipses (...) in the comments.
## It might be nice to check that all the files we need are here.
## Appletalk is installed but does not work and gives errors on
## boot up. I have not been able to find a clean way to get the
## appletalk support working but the powers that be insist on it.
##
#
# Needed files:
#
# The following files are assumed to be present in the current
# directory:
# RPMS:
# ImageMagick-5.4.3.11-1.i386.rpm
# ImageMagick-devel-5.4.3.11-1.i386.rpm
# ImageMagick-perl-5.4.3.11-1.i386.rpm
# gnuplot-3.7.1-5.i386.rpm
# libgd-1.3-4.i386.rpm
# libungif-progs-4.1.0-9.i386.rpm
# ncurses4-5.0-5.i386.rpm
# readline-2.2.1-6.i386.rpm
# readline-4.2a-4.i386.rpm
# perl-DBD-MySQL-1.2216-4.i386.rpm
# perl-DBI-1.21-1.i386.rpm
# mod_perl-1.26-5.i386.rpm
# perl-suidperl-5.6.1-34.99.6.i386.rpm
# LON-CAPA-systemperl-3.4-rh72.i386.rpm
# mysql-3.23.49-3.i386.rpm
# mysqlclient9-3.23.22-6.i386.rpm
# mysql-server-3.23.49-3.i386.rpm
# hwcrypto-1.0-3.i386.rpm
# m2crypto-0.05_snap4-2.i386.rpm
# netatalk-1.5pre6-1rh7.i386.rpm
# Other files:
# httpd.conf
# mod_auth_external-2.1.13.tar.gz
#
# The contingency plan for a 7.2 install tells the user to install these
# from the current directory.
# perl-5.6.1-34.99.6.i386.rpm
# perl-CGI-2.752-34.99.6.i386.rpm
#
use strict;
use File::Copy;
my $result;
my $test;
# note: The filehandle LOG is global.
open LOG,">/tmp/loncapa_install.log" || die "Unable to open log file.\n";
# Some friendly subroutines
sub die_if_nonempty {
my ($string,$error)=@_;
return if (! defined($error));
chomp($string);chomp($error);
if ($string ne '') {
print_and_log("$error\nHalting.\n");
die;
}
}
sub make_link_or_die {
my ($source,$dest)=@_;
&die_if_nonempty
(`ln -fs $source $dest`,"Unable to link $source to $dest.");
print LOG "Link from $source to $dest made successfully\n";
}
sub writelog {
while ($_ = shift) {
chomp;
print LOG "$_\n";
}
}
sub print_and_log {
while ($_=shift) {
chomp;
print "$_\n";
print LOG "$_\n";
}
}
##
## First, make sure it's a red hat system.
##
if (! -e "/etc/redhat-release") {
print_and_log(<<"END");
*********************************************************************
This does not a appear to be a Red-Hat system. More than likely the
installation will not be successful! Press control-c to abort now,
otherwise press enter to forge ahead and damn the torpedos.
*********************************************************************
END
undef = <STDIN>;
}
#
# The installation work begins now...
#
print <<"END";
********************************************************************
Welcome to LON-CAPA
This script will install the base software that LON-CAPA needs to
run properly.
********************************************************************
END
##
## Install needed RPMS
##
my $instdir = `pwd`;
chomp($instdir);
#
# This list of rpms needs to be pared down to some extent.
#
my @ImageMagick_rpms = (
"$instdir/ImageMagick-5.4.3.11-1.i386.rpm",
"$instdir/ImageMagick-devel-5.4.3.11-1.i386.rpm",
"$instdir/ImageMagick-perl-5.4.3.11-1.i386.rpm",
);
my @gnuplot_rpms = (
"$instdir/gnuplot-3.7.1-5.i386.rpm",
"$instdir/libgd-1.3-4.i386.rpm",
"$instdir/libungif-progs-4.1.0-9.i386.rpm",
"$instdir/ncurses4-5.0-5.i386.rpm",
"$instdir/readline-2.2.1-6.i386.rpm",
"$instdir/readline-4.2a-4.i386.rpm"
);
my @perl_rpms = (
"$instdir/perl-DBD-MySQL-1.2216-4.i386.rpm",
"$instdir/perl-DBI-1.21-1.i386.rpm",
"$instdir/mod_perl-1.26-5.i386.rpm",
"$instdir/perl-suidperl-5.6.1-34.99.6.i386.rpm",
);
my @loncapa_perl_rpms = (
"$instdir/LON-CAPA-systemperl-3.4-rh72.i386.rpm"
);
my @mysql_rpms = (
"$instdir/mysql-3.23.49-3.i386.rpm", # okay w/o f,nd
"$instdir/mysqlclient9-3.23.22-6.i386.rpm", # okay w/o f,nd
"$instdir/mysql-server-3.23.49-3.i386.rpm", # okay w/o f,nd
);
my @misc_rpms = (
"$instdir/hwcrypto-1.0-3.i386.rpm", # already installed
"$instdir/m2crypto-0.05_snap4-2.i386.rpm", # okay w/o f,nd
"$instdir/netatalk-1.5pre6-1rh7.i386.rpm" # hmmmm
);
##
## Okay, I have tried being nice about this and not doing '--force --nodeps',
## but it is an exercise in frustration. It would be nice to be kind, but
## frankly I do not want to spend the time to figure this out.
##
print_and_log("Installing ImageMagick packages.\n");
writelog (`rpm -ivh --force --nodeps @ImageMagick_rpms`);
print_and_log("Installing mysql packages.\n");
writelog (`rpm -ivh --force --nodeps @mysql_rpms`);
print_and_log("Installing gnuplot packages.\n");
writelog (`rpm -ivh --force --nodeps @gnuplot_rpms`);
print_and_log("Installing LON-CAPA Perl packages.\n");
writelog (`rpm -ivh --force --nodeps @loncapa_perl_rpms`);
print_and_log("Installing Perl packages.\n");
writelog (`rpm -ivh --force --nodeps @perl_rpms`);
print_and_log("Installing misc packages.\n");
writelog (`rpm -ivh --force --nodeps @misc_rpms`);
system("/etc/init.d/sshd start");
print_and_log("\n");
##
## Fix that stupid little sendmail bug
##
print_and_log("changing permissions on root directory.\n");
$result = `chmod g-w,u+w /`;
if ($result eq '') {
$result = "successful\n";
} else {
die "Unable to change permissions on root directory. Halting.\n";
}
writelog ($result);
print_and_log("\n");
##
## Set up www and authentication
##
print_and_log("Creating user 'www'\n");
$result = `/usr/sbin/useradd www`;
if (! (($result eq '') || ($result =~ /user www exists/))) {
die "Unable to add user www. Halting.\n";
}
writelog ($result);
my $num = `grep ^www /etc/passwd | cut -d':' -f3`;
chomp $num;
if (int($num) == $num) {
writelog ("uid of www = $num\n");
} else {
die "Unable to determine UID of user www\n Halting.\n";
}
print_and_log("\n");
##
## Patch mod_auth_external
##
print_and_log("Setting up authentication for 'www'\n");
my $patch = <<"ENDPATCH";
148c148
< #define SERVER_UIDS 99 /* user "nobody" */
---
> #define SERVER_UIDS $num /* user "www" */
ENDPATCH
if (! -e "/usr/bin/patch") {
print_and_log("You must install the software development tools package ".
"when installing RedHat.\n");
die;
}
&die_if_nonempty(`cd /tmp; tar zxf $instdir/mod_auth_external-2.1.13.tar.gz`,
"Unable to extract mod_auth_external\n");
my $dir = "/tmp/mod_auth_external-2.1.13/pwauth";
open PATCH, "| patch $dir/config.h" ||
die "Unable to start patch for mod_auth_external. Halting\n";
print PATCH $patch;
close PATCH;
print_and_log("\n");
##
## Compile patched pwauth
##
print_and_log("Compiling pwauth\n");
$result = `cd $dir/; make`;
my $expected = <<"END";
gcc -g -c -o pwauth.o pwauth.c
gcc -o pwauth -g pwauth.o -lcrypt
END
if ($result ne $expected) {
die "Unable to compile patched pwauth. Halting.\n";
}
print_and_log( $result );
##
## Install patched pwauth
##
print_and_log("Copying pwauth to /usr/local/sbin\n");
if (! copy "$dir/pwauth","/usr/local/sbin/pwauth") {
die "Unable to copy $dir/pwauth to /usr/local/sbin/pwauth.\n$!\nHalting\n";
}
if (! chmod (06755, "/usr/local/sbin/pwauth")) {
die "Unable to set permissions on /usr/local/sbin/pwauth.\n";
}
print_and_log("\n");
##
## Set up mysql
##
print_and_log("Setting mysqld to start on boot up.\n");
make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc0.d/K90mysqld");
make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc1.d/K90mysqld");
make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc2.d/S90mysqld");
make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc3.d/S90mysqld");
make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc4.d/S90mysqld");
make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc5.d/S90mysqld");
make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc6.d/K90mysqld");
writelog("mysql links created successfully\n");
writelog(`/etc/rc.d/init.d/mysqld start`);
print_and_log("Waiting for mysql daemon to start.\n");
sleep 5;
if (`/etc/rc.d/init.d/mysqld status` !~ / is running/) {
die "Unable to start mysql daemon\nHalting\n";
}
print_and_log("\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_and_log("\n");
##
## Run the damn thing (mysql, not LON-CAPA)
##
print_and_log("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'));
GRANT ALL PRIVILEGES ON *.* TO www\@localhost;
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;
print_and_log("\n");
##
## Kill the firewall, if it exists
##
#
# A better method would be to modify the firewall rules to make
# the lond port open. Someday.
#
if (-e "/etc/init.d/iptables" || -e "/etc/init.d/ipchans") {
print_and_log("Stopping and removing your firewall\n");
my @tokill = ("/etc/rc.d/rc2.d/S08ipchains",
"/etc/rc.d/rc2.d/S08iptables",
"/etc/rc.d/rc3.d/S08ipchains",
"/etc/rc.d/rc3.d/S08iptables",
"/etc/rc.d/rc4.d/S08ipchains",
"/etc/rc.d/rc4.d/S08iptables",
"/etc/rc.d/rc5.d/S08ipchains",
"/etc/rc.d/rc5.d/S08iptables" );
foreach (@tokill) {
unlink $_ if (-e $_ );
}
writelog(`/etc/init.d/ipchains stop`);
writelog(`/etc/init.d/ipchains stop`);
print_and_log("\n");
}
##
## Set up httpd
##
print_and_log("Setting httpd to start on boot up.\n");
make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc0.d/K15httpd");
make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc1.d/K15httpd");
make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc2.d/K15httpd");
make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc3.d/S85httpd");
make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc4.d/K15httpd");
make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc5.d/K15httpd");
make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc6.d/K15httpd");
##
## Copy our (probably lousy) httpd.conf to its rightful place
##
print_and_log("Copying our httpd.conf to /etc/httpd/conf/httpd.conf\n");
copy "$instdir/httpd.conf","/etc/httpd/conf/httpd.conf";
chmod 0444,"/etc/httpd/conf/httpd.conf";
print_and_log("\n");
##
## Retrieve loncapa.tar.gz
##
if (! -e "$instdir/loncapa.tar.gz") {
print_and_log("Retrieving LON-CAPA source files from install.loncapa.org\n");
system("wget http://install.loncapa.org/versions/current/loncapa.tar.gz 2>/dev/null 1>/dev/null");
if (! -e "./loncapa.tar.gz") {
die("Unable to retrieve LON-CAPA source files from\n".
"http://install.loncapa.org/versions/current/loncapa.tar.gz\n");
}
print_and_log("\n");
} else {
print_and_log(<<"END");
------------------------------------------------------------------------
You seem to have a version of loncapa.tar.gz in $instdir.
This copy will be used and a new version will NOT be downloaded.
If you wish, you may download a new version by executing:
wget http://install.loncapa.org/versions/current/loncapa.tar.gz
------------------------------------------------------------------------
END
}
##
## untar loncapa.tar.gz
##
print_and_log("Extracting LON-CAPA source files\n");
writelog(`cd ~root; tar zxf $instdir/loncapa.tar.gz`);
print_and_log("\n");
my $version = `cat /etc/redhat-release`;
if ($version =~ /7\.2/) {
print_and_log(<<"END");
This appears to be a Red Hat 7.2 system. You need to execute the following
commands now:
rpm -Uvh perl-5.6.1-34.99.6.i386.rpm
rpm -Uvh perl-CGI-2.752-34.99.6.i386.rpm
cd /root/loncapa
./UPDATE
END
} else {
##
## Assure them that everything worked okay....
##
print <<"ENDMSG";
All of the extra files seem to have been installed correctly. It remains for
you to execute the following commands:
cd /root/loncapa;
./UPDATE
If you have any trouble, please see http://install.loncapa.org and
http://help.loncapa.org.
ENDMSG
}
close LOG;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>