File:  [LON-CAPA] / doc / install / redhat7.3 / install.pl
Revision 1.10: download - view: text, annotated - select for diffs
Sat Nov 16 00:01:29 2002 UTC (21 years, 6 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
this is really frustrating... it didn't used to require single quotes..
and this changes the entry inside mysql:db table.

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

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