File:  [LON-CAPA] / doc / install / redhat7.3 / install.pl
Revision 1.1: download - view: text, annotated - select for diffs
Wed Jun 19 19:16:54 2002 UTC (22 years, 1 month ago) by matthew
Branches: MAIN
CVS tags: HEAD
Perl script to install on Red Hat 7.3 systems.

    1: #!/usr/bin/perl -w
    2: # The LearningOnline Network 
    3: # Red Hat 7.3 installation script
    4: #
    5: # $Id: install.pl,v 1.1 2002/06/19 19:16:54 matthew Exp $
    6: #
    7: # Copyright Michigan State University Board of Trustees
    8: #
    9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   10: #
   11: # LON-CAPA is free software; you can redistribute it and/or modify
   12: # it under the terms of the GNU General Public License as published by
   13: # the Free Software Foundation; either version 2 of the License, or
   14: # (at your option) any later version.
   15: #
   16: # LON-CAPA is distributed in the hope that it will be useful,
   17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19: # GNU General Public License for more details.
   20: #
   21: # You should have received a copy of the GNU General Public License
   22: # along with LON-CAPA; if not, write to the Free Software
   23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24: #
   25: # http://www.lon-capa.org/
   26: #
   27: ##
   28: ## Obvious flaws of this program: 
   29: ##   Dieing on every error may be a little extreme.  On the other hand, 
   30: ##       how the heck am I supposed to know what absurd things the user 
   31: ##       has done with their system before inflicting LON-CAPA on it?
   32: ##   The links to /etc/init.d for httpd and mysqld do not seem to work :(
   33: ##   The user is never informed of the log file (/tmp/loncapa_install.log).
   34: ##   It does not test the system at the end.  Again, there are limits to 
   35: ##       what nonsense we can put up with.  Of course, we will have to 
   36: ##       explain that to people at some point...
   37: ##   There is probably an overuse of elipses (...) in the comments.
   38: ##
   39: use strict;
   40: use File::Copy;
   41: 
   42: my $result; 
   43: my $test;
   44: 
   45: # note: The filehandle LOG is global.
   46: open LOG,">/tmp/loncapa_install.log" || die "Unable to open log file.\n";
   47: 
   48: # Some friendly subroutines
   49: sub die_if_nonempty {
   50:     my ($string,$error)=@_;
   51:     return if (! defined($error));
   52:     chomp($string);chomp($error);
   53:     if ($string ne '') {
   54:         print_and_log("$error\nHalting.\n");
   55:         die;
   56:     }
   57: }
   58: 
   59: sub make_link_or_die {
   60:     my ($source,$dest)=@_;
   61:     &die_if_nonempty
   62:         (`ln -fs $source $dest`,"Unable to link $source to $dest.");
   63:     print LOG "Link from $source to $dest made successfully\n";
   64: }
   65: 
   66: sub writelog {
   67:     while ($_ = shift) {
   68:         chomp;
   69:         print LOG "$_\n";
   70:     }
   71: }
   72: 
   73: sub print_and_log {
   74:     while ($_=shift) {
   75:         chomp;
   76:         print "$_\n";
   77:         print LOG "$_\n";
   78:     }
   79: }
   80: 
   81: ##
   82: ## First, make sure it's a red hat system.
   83: ##
   84: if (! -e "/etc/redhat-release") {
   85:     print_and_log(<<"END");
   86: *********************************************************************
   87: 
   88: This does not a appear to be a Red-Hat system.  More than likely the 
   89: installation will not be successful!  Press control-c to abort now, 
   90: otherwise press enter to forge ahead and damn the torpedos.
   91: 
   92: *********************************************************************
   93: END
   94:     undef = <STDIN>;
   95: }
   96: 
   97: 
   98: 
   99: #
  100: # The installation work begins now...
  101: #
  102: 
  103: print <<"END";
  104: ********************************************************************
  105: 
  106:                         Welcome to LON-CAPA
  107: 
  108: This script will install the base software that LON-CAPA needs to
  109: run properly. 
  110: 
  111: ********************************************************************
  112: END
  113: 
  114: ##
  115: ## Install needed RPMS
  116: ##
  117: my $instdir = `pwd`;
  118: chomp($instdir);
  119: # 
  120: # This list of rpms needs to be pared down to some extent.
  121: #
  122: 
  123: my @gnuplot_rpms = (
  124:              "$instdir/gnuplot-3.7.1-5.i386.rpm",
  125:              "$instdir/libgd-1.3-4.i386.rpm",
  126:              "$instdir/libungif-progs-4.1.0-9.i386.rpm",
  127:              "$instdir/ncurses4-5.0-5.i386.rpm",
  128:              "$instdir/readline-2.2.1-6.i386.rpm",
  129:              "$instdir/readline-4.2a-4.i386.rpm"
  130:                     );
  131: my @perl_rpms = ( 
  132:              "$instdir/perl-DBD-MySQL-1.2216-4.i386.rpm",
  133:              "$instdir/perl-DBI-1.21-1.i386.rpm",
  134:              "$instdir/mod_perl-1.26-5.i386.rpm",
  135:              "$instdir/perl-suidperl-5.6.1-34.99.6.i386.rpm",
  136:                  );
  137: my @loncapa_perl_rpms = (
  138:              "$instdir/LON-CAPA-systemperl-3.4-rh72.i386.rpm"
  139:                     );
  140: my @mysql_rpms = (
  141:              "$instdir/mysql-3.23.49-3.i386.rpm",          # okay w/o f,nd
  142:              "$instdir/mysqlclient9-3.23.22-6.i386.rpm",   # okay w/o f,nd
  143:              "$instdir/mysql-server-3.23.49-3.i386.rpm",   # okay w/o f,nd
  144:                   );
  145: my @misc_rpms = (
  146:              "$instdir/hwcrypto-1.0-3.i386.rpm",           # already installed
  147:              "$instdir/m2crypto-0.05_snap4-2.i386.rpm",    # okay w/o f,nd
  148:              "$instdir/netatalk-1.5pre6-1rh7.i386.rpm"     # hmmmm
  149:              );
  150: ##
  151: ## Okay, I have tried being nice about this and not doing '--force --nodeps',
  152: ## but it is an exercise in frustration.  It would be nice to be kind, but
  153: ## frankly I do not want to spend the time to figure this out.
  154: ##
  155: print_and_log("Installing mysql packages.\n");
  156: writelog (`rpm -ivh --force --nodeps @mysql_rpms`);
  157: print_and_log("Installing gnuplot packages.\n");
  158: writelog (`rpm -ivh --force --nodeps @gnuplot_rpms`);
  159: print_and_log("Installing LON-CAPA Perl packages.\n");
  160: writelog (`rpm -ivh --force --nodeps @loncapa_perl_rpms`);
  161: print_and_log("Installing Perl packages.\n");
  162: writelog (`rpm -ivh --force --nodeps @perl_rpms`);
  163: print_and_log("Installing misc packages.\n");
  164: writelog (`rpm -ivh --force --nodeps @misc_rpms`);
  165: system("/etc/init.d/sshd start");
  166: print_and_log("\n");
  167: 
  168: ##
  169: ## Fix that stupid little sendmail bug
  170: ##
  171: print_and_log("changing permissions on root directory.\n");
  172: $result = `chmod g-w,u+w /`;
  173: if ($result eq '') {
  174:     $result = "successful\n";
  175: } else {
  176:     die "Unable to change permissions on root directory.  Halting.\n";
  177: }
  178: writelog ($result);
  179: print_and_log("\n");
  180: 
  181: ##
  182: ## Set up www and authentication
  183: ##
  184: print_and_log("Creating user 'www'\n");
  185: $result = `/usr/sbin/useradd www`;
  186: if (! (($result eq '') || ($result =~ /user www exists/))) {
  187:     die "Unable to add user www.  Halting.\n";
  188: }
  189: writelog ($result);
  190: my $num = `grep ^www /etc/passwd | cut -d':' -f3`;
  191: chomp $num;
  192: if (int($num) == $num) {
  193:     writelog ("uid of www = $num\n");
  194: } else {
  195:     die "Unable to determine UID of user www\n  Halting.\n";
  196: }
  197: print_and_log("\n");
  198: 
  199: ##
  200: ## Patch mod_auth_external
  201: ##
  202: print_and_log("Setting up authentication for 'www'\n");
  203: my $patch = <<"ENDPATCH";
  204: 148c148
  205: < #define SERVER_UIDS 99		/* user "nobody" */
  206: ---
  207: > #define SERVER_UIDS $num		/* user "www" */
  208: ENDPATCH
  209: 
  210: if (! -e "/usr/bin/patch") {
  211:     print_and_log("You must install the software development tools package ".
  212:                   "when installing RedHat.\n");
  213:     die;
  214: }
  215: &die_if_nonempty(`cd /tmp; tar zxf $instdir/mod_auth_external-2.1.13.tar.gz`,
  216:                  "Unable to extract mod_auth_external\n");
  217: my $dir = "/tmp/mod_auth_external-2.1.13/pwauth";
  218: open PATCH, "| patch $dir/config.h" || 
  219:     die "Unable to start patch for mod_auth_external.  Halting\n";
  220: print PATCH $patch;
  221: close PATCH;
  222: print_and_log("\n");
  223: 
  224: ##
  225: ## Compile patched pwauth
  226: ##
  227: print_and_log("Compiling pwauth\n");
  228: $result = `cd $dir/; make`;
  229: my $expected = <<"END";
  230: gcc -g    -c -o pwauth.o pwauth.c
  231: gcc -o pwauth -g  pwauth.o -lcrypt
  232: END
  233: 
  234: if ($result ne $expected) {
  235:     die "Unable to compile patched pwauth.  Halting.\n";
  236: }    
  237: print_and_log( $result );
  238: 
  239: ##
  240: ## Install patched pwauth
  241: ##
  242: print_and_log("Copying pwauth to /usr/local/sbin\n");
  243: if (! copy "$dir/pwauth","/usr/local/sbin/pwauth") {
  244:     die "Unable to copy $dir/pwauth to /usr/local/sbin/pwauth.\n$!\nHalting\n";
  245: }
  246: if (! chmod (06755, "/usr/local/sbin/pwauth")) {
  247:     die "Unable to set permissions on /usr/local/sbin/pwauth.\n";
  248: }
  249: print_and_log("\n");
  250: 
  251: ##
  252: ## Set up mysql
  253: ##
  254: print_and_log("Setting mysqld to start on boot up.\n");
  255: 
  256: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc0.d/K90mysqld");
  257: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc1.d/K90mysqld");
  258: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc2.d/S90mysqld");
  259: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc3.d/S90mysqld");
  260: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc4.d/S90mysqld");
  261: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc5.d/S90mysqld");
  262: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc6.d/K90mysqld");
  263: 
  264: writelog("mysql links created successfully\n");
  265: writelog(`/etc/rc.d/init.d/mysqld start`);
  266: print_and_log("Waiting for mysql daemon to start.\n");
  267: sleep 5;
  268: if (`/etc/rc.d/init.d/mysqld status` !~ / is running/) {
  269:     die "Unable to start mysql daemon\nHalting\n";
  270: }
  271: print_and_log("\n");
  272: 
  273: ##
  274: ## Get root password for mysql client
  275: ##
  276: print <<END;
  277: Please enter a root password for the mysql database.
  278: It does not have to match your root account password, but you will need
  279: to remember it.
  280: END
  281: my $rootpass = <>;
  282: chomp $rootpass;
  283: print_and_log("\n");
  284: 
  285: ##
  286: ## Run the damn thing (mysql, not LON-CAPA)
  287: ##
  288: print_and_log("Starting mysql client.\n");
  289: open MYSQL, "|mysql -u root mysql" || die "Unable to start mysql\n";
  290: print MYSQL <<"ENDMYSQL";
  291: CREATE DATABASE loncapa;
  292: INSERT INTO user (Host, User, Password)
  293: VALUES ('localhost','www',password('localhostkey'));
  294: GRANT ALL PRIVILEGES ON *.* TO www\@localhost;
  295: SET PASSWORD FOR root\@localhost=PASSWORD('$rootpass');
  296: DELETE FROM user WHERE host<>'localhost';
  297: FLUSH PRIVILEGES;
  298: USE loncapa;
  299: 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;
  300: EXIT
  301: ENDMYSQL
  302: 
  303: close MYSQL;
  304: print_and_log("\n");
  305: 
  306: ##
  307: ## Kill the firewall, if it exists
  308: ##
  309: #
  310: # A better method would be to modify the firewall rules to make
  311: # the lond port open.  Someday.
  312: #
  313: if (-e "/etc/init.d/iptables" || -e "/etc/init.d/ipchans") {
  314:     print_and_log("Stopping and removing your firewall\n");
  315:     my @tokill = ("/etc/rc.d/rc2.d/S08ipchains",
  316:                   "/etc/rc.d/rc2.d/S08iptables",
  317:                   "/etc/rc.d/rc3.d/S08ipchains",
  318:                   "/etc/rc.d/rc3.d/S08iptables",
  319:                   "/etc/rc.d/rc4.d/S08ipchains",
  320:                   "/etc/rc.d/rc4.d/S08iptables",
  321:                   "/etc/rc.d/rc5.d/S08ipchains",
  322:                   "/etc/rc.d/rc5.d/S08iptables" );
  323:     foreach (@tokill) {
  324:         unlink $_ if (-e $_ );
  325:     }
  326:     writelog(`/etc/init.d/ipchains stop`);
  327:     writelog(`/etc/init.d/ipchains stop`);
  328:     print_and_log("\n");
  329: }
  330: 
  331: ##
  332: ## Set up httpd 
  333: ##
  334: print_and_log("Setting httpd to start on boot up.\n");
  335: 
  336: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc0.d/K15httpd");
  337: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc1.d/K15httpd");
  338: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc2.d/K15httpd");
  339: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc3.d/S85httpd");
  340: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc4.d/K15httpd");
  341: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc5.d/K15httpd");
  342: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc6.d/K15httpd");
  343: 
  344: ##
  345: ## Copy our (probably lousy) httpd.conf to its rightful place
  346: ##
  347: print_and_log("Copying our httpd.conf to /etc/httpd/conf/httpd.conf\n");
  348: copy "$instdir/httpd.conf","/etc/httpd/conf/httpd.conf";
  349: chmod 0444,"/etc/httpd/conf/httpd.conf";
  350: print_and_log("\n");
  351: 
  352: ##
  353: ## Retrieve loncapa.tar.gz
  354: ##
  355: if (! -e "$instdir/loncapa.tar.gz") {
  356:     print_and_log("Retrieving LON-CAPA source files from install.loncapa.org\n");
  357:     system("wget http://install.loncapa.org/versions/current/loncapa.tar.gz 2>/dev/null 1>/dev/null");
  358:     if (! -e "./loncapa.tar.gz") {
  359:         die("Unable to retrieve LON-CAPA source files from\n".
  360:             "http://install.loncapa.org/versions/current/loncapa.tar.gz\n");
  361:     }
  362:     print_and_log("\n");
  363: } else {
  364:     print_and_log(<<"END");
  365: ------------------------------------------------------------------------
  366: 
  367: You seem to have a version of loncapa.tar.gz in $instdir.  
  368: This copy will be used and a new version will NOT be downloaded.  
  369: If you wish, you may download a new version by executing:
  370: 
  371: wget http://install.loncapa.org/versions/current/loncapa.tar.gz
  372: 
  373: ------------------------------------------------------------------------
  374: END
  375: }
  376: 
  377: ##
  378: ## untar loncapa.tar.gz
  379: ##
  380: print_and_log("Extracting LON-CAPA source files\n");
  381: writelog(`cd ~root; tar zxf $instdir/loncapa.tar.gz`);
  382: print_and_log("\n");
  383: 
  384: my $version = `cat /etc/redhat-release`;
  385: if ($version =~ /7\.2/) {
  386:     print_and_log(<<"END");
  387: This appears to be a Red Hat 7.2 system.  You need to execute the following
  388: commands now:
  389: rpm -Uvh perl-5.6.1-34.99.6.i386.rpm
  390: rpm -Uvh perl-CGI-2.752-34.99.6.i386.rpm
  391: 
  392: cd /root/loncapa
  393: ./UPDATE
  394: 
  395: END
  396: } else {
  397:     ##
  398:     ## Assure them that everything worked okay....
  399:     ##
  400:     print <<"ENDMSG";
  401: All of the extra files seem to have been installed correctly.  It remains for 
  402: you to execute the following commands:
  403: 
  404: cd /root/loncapa;
  405: ./UPDATE
  406: 
  407: If you have any trouble, please see http://install.loncapa.org and 
  408: http://help.loncapa.org.  
  409: ENDMSG
  410: }
  411: 
  412: close LOG;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>