Annotation of doc/install/redhat7.3/install.pl, revision 1.3

1.1       matthew     1: #!/usr/bin/perl -w
                      2: # The LearningOnline Network 
                      3: # Red Hat 7.3 installation script
                      4: #
1.3     ! matthew     5: # $Id: install.pl,v 1.2 2002/06/19 19:27:17 matthew Exp $
1.1       matthew     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: #
1.2       matthew    27: 
1.1       matthew    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.
1.2       matthew    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.
1.1       matthew    43: ##
1.2       matthew    44: 
                     45: #
                     46: # Needed files:
                     47: #
                     48: #    The following files are assumed to be present in the current
                     49: #    directory:
                     50: #      RPMS:
1.3     ! matthew    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
1.2       matthew    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: 
1.1       matthew    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: 
1.3     ! matthew   165: my @ImageMagick_rpms = (
        !           166:              "$instdir/ImageMagick-5.4.3.11-1.i386.rpm",
        !           167:              "$instdir/ImageMagick-devel-5.4.3.11-1.i386.rpm",
        !           168:              "$instdir/ImageMagick-perl-5.4.3.11-1.i386.rpm",
        !           169:                        );
        !           170: 
1.1       matthew   171: my @gnuplot_rpms = (
                    172:              "$instdir/gnuplot-3.7.1-5.i386.rpm",
                    173:              "$instdir/libgd-1.3-4.i386.rpm",
                    174:              "$instdir/libungif-progs-4.1.0-9.i386.rpm",
                    175:              "$instdir/ncurses4-5.0-5.i386.rpm",
                    176:              "$instdir/readline-2.2.1-6.i386.rpm",
                    177:              "$instdir/readline-4.2a-4.i386.rpm"
                    178:                     );
                    179: my @perl_rpms = ( 
                    180:              "$instdir/perl-DBD-MySQL-1.2216-4.i386.rpm",
                    181:              "$instdir/perl-DBI-1.21-1.i386.rpm",
                    182:              "$instdir/mod_perl-1.26-5.i386.rpm",
                    183:              "$instdir/perl-suidperl-5.6.1-34.99.6.i386.rpm",
                    184:                  );
                    185: my @loncapa_perl_rpms = (
                    186:              "$instdir/LON-CAPA-systemperl-3.4-rh72.i386.rpm"
                    187:                     );
                    188: my @mysql_rpms = (
                    189:              "$instdir/mysql-3.23.49-3.i386.rpm",          # okay w/o f,nd
                    190:              "$instdir/mysqlclient9-3.23.22-6.i386.rpm",   # okay w/o f,nd
                    191:              "$instdir/mysql-server-3.23.49-3.i386.rpm",   # okay w/o f,nd
                    192:                   );
                    193: my @misc_rpms = (
                    194:              "$instdir/hwcrypto-1.0-3.i386.rpm",           # already installed
                    195:              "$instdir/m2crypto-0.05_snap4-2.i386.rpm",    # okay w/o f,nd
                    196:              "$instdir/netatalk-1.5pre6-1rh7.i386.rpm"     # hmmmm
                    197:              );
                    198: ##
                    199: ## Okay, I have tried being nice about this and not doing '--force --nodeps',
                    200: ## but it is an exercise in frustration.  It would be nice to be kind, but
                    201: ## frankly I do not want to spend the time to figure this out.
                    202: ##
1.3     ! matthew   203: print_and_log("Installing ImageMagick packages.\n");
        !           204: writelog (`rpm -ivh --force --nodeps @ImageMagick_rpms`);
1.1       matthew   205: print_and_log("Installing mysql packages.\n");
                    206: writelog (`rpm -ivh --force --nodeps @mysql_rpms`);
                    207: print_and_log("Installing gnuplot packages.\n");
                    208: writelog (`rpm -ivh --force --nodeps @gnuplot_rpms`);
                    209: print_and_log("Installing LON-CAPA Perl packages.\n");
                    210: writelog (`rpm -ivh --force --nodeps @loncapa_perl_rpms`);
                    211: print_and_log("Installing Perl packages.\n");
                    212: writelog (`rpm -ivh --force --nodeps @perl_rpms`);
                    213: print_and_log("Installing misc packages.\n");
                    214: writelog (`rpm -ivh --force --nodeps @misc_rpms`);
                    215: system("/etc/init.d/sshd start");
                    216: print_and_log("\n");
                    217: 
                    218: ##
                    219: ## Fix that stupid little sendmail bug
                    220: ##
                    221: print_and_log("changing permissions on root directory.\n");
                    222: $result = `chmod g-w,u+w /`;
                    223: if ($result eq '') {
                    224:     $result = "successful\n";
                    225: } else {
                    226:     die "Unable to change permissions on root directory.  Halting.\n";
                    227: }
                    228: writelog ($result);
                    229: print_and_log("\n");
                    230: 
                    231: ##
                    232: ## Set up www and authentication
                    233: ##
                    234: print_and_log("Creating user 'www'\n");
                    235: $result = `/usr/sbin/useradd www`;
                    236: if (! (($result eq '') || ($result =~ /user www exists/))) {
                    237:     die "Unable to add user www.  Halting.\n";
                    238: }
                    239: writelog ($result);
                    240: my $num = `grep ^www /etc/passwd | cut -d':' -f3`;
                    241: chomp $num;
                    242: if (int($num) == $num) {
                    243:     writelog ("uid of www = $num\n");
                    244: } else {
                    245:     die "Unable to determine UID of user www\n  Halting.\n";
                    246: }
                    247: print_and_log("\n");
                    248: 
                    249: ##
                    250: ## Patch mod_auth_external
                    251: ##
                    252: print_and_log("Setting up authentication for 'www'\n");
                    253: my $patch = <<"ENDPATCH";
                    254: 148c148
                    255: < #define SERVER_UIDS 99		/* user "nobody" */
                    256: ---
                    257: > #define SERVER_UIDS $num		/* user "www" */
                    258: ENDPATCH
                    259: 
                    260: if (! -e "/usr/bin/patch") {
                    261:     print_and_log("You must install the software development tools package ".
                    262:                   "when installing RedHat.\n");
                    263:     die;
                    264: }
                    265: &die_if_nonempty(`cd /tmp; tar zxf $instdir/mod_auth_external-2.1.13.tar.gz`,
                    266:                  "Unable to extract mod_auth_external\n");
                    267: my $dir = "/tmp/mod_auth_external-2.1.13/pwauth";
                    268: open PATCH, "| patch $dir/config.h" || 
                    269:     die "Unable to start patch for mod_auth_external.  Halting\n";
                    270: print PATCH $patch;
                    271: close PATCH;
                    272: print_and_log("\n");
                    273: 
                    274: ##
                    275: ## Compile patched pwauth
                    276: ##
                    277: print_and_log("Compiling pwauth\n");
                    278: $result = `cd $dir/; make`;
                    279: my $expected = <<"END";
                    280: gcc -g    -c -o pwauth.o pwauth.c
                    281: gcc -o pwauth -g  pwauth.o -lcrypt
                    282: END
                    283: 
                    284: if ($result ne $expected) {
                    285:     die "Unable to compile patched pwauth.  Halting.\n";
                    286: }    
                    287: print_and_log( $result );
                    288: 
                    289: ##
                    290: ## Install patched pwauth
                    291: ##
                    292: print_and_log("Copying pwauth to /usr/local/sbin\n");
                    293: if (! copy "$dir/pwauth","/usr/local/sbin/pwauth") {
                    294:     die "Unable to copy $dir/pwauth to /usr/local/sbin/pwauth.\n$!\nHalting\n";
                    295: }
                    296: if (! chmod (06755, "/usr/local/sbin/pwauth")) {
                    297:     die "Unable to set permissions on /usr/local/sbin/pwauth.\n";
                    298: }
                    299: print_and_log("\n");
                    300: 
                    301: ##
                    302: ## Set up mysql
                    303: ##
                    304: print_and_log("Setting mysqld to start on boot up.\n");
                    305: 
                    306: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc0.d/K90mysqld");
                    307: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc1.d/K90mysqld");
                    308: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc2.d/S90mysqld");
                    309: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc3.d/S90mysqld");
                    310: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc4.d/S90mysqld");
                    311: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc5.d/S90mysqld");
                    312: make_link_or_die("/etc/rc.d/init.d/mysqld","/etc/rc.d/rc6.d/K90mysqld");
                    313: 
                    314: writelog("mysql links created successfully\n");
                    315: writelog(`/etc/rc.d/init.d/mysqld start`);
                    316: print_and_log("Waiting for mysql daemon to start.\n");
                    317: sleep 5;
                    318: if (`/etc/rc.d/init.d/mysqld status` !~ / is running/) {
                    319:     die "Unable to start mysql daemon\nHalting\n";
                    320: }
                    321: print_and_log("\n");
                    322: 
                    323: ##
                    324: ## Get root password for mysql client
                    325: ##
                    326: print <<END;
                    327: Please enter a root password for the mysql database.
                    328: It does not have to match your root account password, but you will need
                    329: to remember it.
                    330: END
                    331: my $rootpass = <>;
                    332: chomp $rootpass;
                    333: print_and_log("\n");
                    334: 
                    335: ##
                    336: ## Run the damn thing (mysql, not LON-CAPA)
                    337: ##
                    338: print_and_log("Starting mysql client.\n");
                    339: open MYSQL, "|mysql -u root mysql" || die "Unable to start mysql\n";
                    340: print MYSQL <<"ENDMYSQL";
                    341: CREATE DATABASE loncapa;
                    342: INSERT INTO user (Host, User, Password)
                    343: VALUES ('localhost','www',password('localhostkey'));
                    344: GRANT ALL PRIVILEGES ON *.* TO www\@localhost;
                    345: SET PASSWORD FOR root\@localhost=PASSWORD('$rootpass');
                    346: DELETE FROM user WHERE host<>'localhost';
                    347: FLUSH PRIVILEGES;
                    348: USE loncapa;
                    349: 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;
                    350: EXIT
                    351: ENDMYSQL
                    352: 
                    353: close MYSQL;
                    354: print_and_log("\n");
                    355: 
                    356: ##
                    357: ## Kill the firewall, if it exists
                    358: ##
                    359: #
                    360: # A better method would be to modify the firewall rules to make
                    361: # the lond port open.  Someday.
                    362: #
                    363: if (-e "/etc/init.d/iptables" || -e "/etc/init.d/ipchans") {
                    364:     print_and_log("Stopping and removing your firewall\n");
                    365:     my @tokill = ("/etc/rc.d/rc2.d/S08ipchains",
                    366:                   "/etc/rc.d/rc2.d/S08iptables",
                    367:                   "/etc/rc.d/rc3.d/S08ipchains",
                    368:                   "/etc/rc.d/rc3.d/S08iptables",
                    369:                   "/etc/rc.d/rc4.d/S08ipchains",
                    370:                   "/etc/rc.d/rc4.d/S08iptables",
                    371:                   "/etc/rc.d/rc5.d/S08ipchains",
                    372:                   "/etc/rc.d/rc5.d/S08iptables" );
                    373:     foreach (@tokill) {
                    374:         unlink $_ if (-e $_ );
                    375:     }
                    376:     writelog(`/etc/init.d/ipchains stop`);
                    377:     writelog(`/etc/init.d/ipchains stop`);
                    378:     print_and_log("\n");
                    379: }
                    380: 
                    381: ##
                    382: ## Set up httpd 
                    383: ##
                    384: print_and_log("Setting httpd to start on boot up.\n");
                    385: 
                    386: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc0.d/K15httpd");
                    387: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc1.d/K15httpd");
                    388: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc2.d/K15httpd");
                    389: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc3.d/S85httpd");
                    390: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc4.d/K15httpd");
                    391: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc5.d/K15httpd");
                    392: make_link_or_die("/etc/rc.d/init.d/httpd","/etc/rc.d/rc6.d/K15httpd");
                    393: 
                    394: ##
                    395: ## Copy our (probably lousy) httpd.conf to its rightful place
                    396: ##
                    397: print_and_log("Copying our httpd.conf to /etc/httpd/conf/httpd.conf\n");
                    398: copy "$instdir/httpd.conf","/etc/httpd/conf/httpd.conf";
                    399: chmod 0444,"/etc/httpd/conf/httpd.conf";
                    400: print_and_log("\n");
                    401: 
                    402: ##
                    403: ## Retrieve loncapa.tar.gz
                    404: ##
                    405: if (! -e "$instdir/loncapa.tar.gz") {
                    406:     print_and_log("Retrieving LON-CAPA source files from install.loncapa.org\n");
                    407:     system("wget http://install.loncapa.org/versions/current/loncapa.tar.gz 2>/dev/null 1>/dev/null");
                    408:     if (! -e "./loncapa.tar.gz") {
                    409:         die("Unable to retrieve LON-CAPA source files from\n".
                    410:             "http://install.loncapa.org/versions/current/loncapa.tar.gz\n");
                    411:     }
                    412:     print_and_log("\n");
                    413: } else {
                    414:     print_and_log(<<"END");
                    415: ------------------------------------------------------------------------
                    416: 
                    417: You seem to have a version of loncapa.tar.gz in $instdir.  
                    418: This copy will be used and a new version will NOT be downloaded.  
                    419: If you wish, you may download a new version by executing:
                    420: 
                    421: wget http://install.loncapa.org/versions/current/loncapa.tar.gz
                    422: 
                    423: ------------------------------------------------------------------------
                    424: END
                    425: }
                    426: 
                    427: ##
                    428: ## untar loncapa.tar.gz
                    429: ##
                    430: print_and_log("Extracting LON-CAPA source files\n");
                    431: writelog(`cd ~root; tar zxf $instdir/loncapa.tar.gz`);
                    432: print_and_log("\n");
                    433: 
                    434: my $version = `cat /etc/redhat-release`;
                    435: if ($version =~ /7\.2/) {
                    436:     print_and_log(<<"END");
                    437: This appears to be a Red Hat 7.2 system.  You need to execute the following
                    438: commands now:
                    439: rpm -Uvh perl-5.6.1-34.99.6.i386.rpm
                    440: rpm -Uvh perl-CGI-2.752-34.99.6.i386.rpm
                    441: 
                    442: cd /root/loncapa
                    443: ./UPDATE
                    444: 
                    445: END
                    446: } else {
                    447:     ##
                    448:     ## Assure them that everything worked okay....
                    449:     ##
                    450:     print <<"ENDMSG";
                    451: All of the extra files seem to have been installed correctly.  It remains for 
                    452: you to execute the following commands:
                    453: 
                    454: cd /root/loncapa;
                    455: ./UPDATE
                    456: 
                    457: If you have any trouble, please see http://install.loncapa.org and 
                    458: http://help.loncapa.org.  
                    459: ENDMSG
                    460: }
                    461: 
                    462: close LOG;

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