Annotation of doc/install/fedora/install.pl, revision 1.5

1.1       matthew     1: #!/usr/bin/perl -w
                      2: # The LearningOnline Network 
1.3       matthew     3: # Fedora installation script
1.1       matthew     4: #
1.5     ! matthew     5: # $Id: install.pl,v 1.4 2003/12/19 15:12:59 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: #
                     27: 
                     28: use strict;
                     29: use File::Copy;
                     30: use Getopt::Long;
                     31: 
                     32: my $result; 
                     33: my $test;
                     34: 
                     35: # note: The filehandle LOG is global.
                     36: open LOG,">>loncapa_install.log" || die "Unable to open log file.\n";
                     37: 
1.5     ! matthew    38: print LOG '$Id: install.pl,v 1.4 2003/12/19 15:12:59 matthew Exp $'."\n";
1.1       matthew    39: 
                     40: # Some friendly subroutines
                     41: sub die_if_nonempty {
                     42:     my ($string,$error)=@_;
                     43:     return if (! defined($error));
                     44:     chomp($string);chomp($error);
                     45:     if ($string ne '') {
                     46:         print_and_log("$error\nHalting.\n");
                     47:         die;
                     48:     }
                     49: }
                     50: 
                     51: sub make_link_or_die {
                     52:     my ($source,$dest)=@_;
                     53:     &die_if_nonempty
                     54:         (`ln -fs $source $dest`,"Unable to link $source to $dest.");
                     55:     print LOG "Link from $source to $dest made successfully\n";
                     56: }
                     57: 
                     58: sub writelog {
                     59:     while ($_ = shift) {
                     60:         chomp;
                     61:         print LOG "$_\n";
                     62:     }
                     63: }
                     64: 
                     65: sub print_and_log {
                     66:     while ($_=shift) {
                     67:         chomp;
                     68:         print "$_\n";
                     69:         print LOG "$_\n";
                     70:     }
                     71: }
                     72: 
                     73: ###############################
                     74: #                             #
                     75: #  Define default behaviour   #
                     76: #                             #
                     77: ###############################
                     78: my $make_www       = 1;
                     79: my $install_pwauth = 1;
                     80: my $setup_mysql    = 1;
                     81: my $setup_mysql_permissions = 1;
                     82: my $stop_services     = 0;
                     83: my $install_httpd_conf = 1;
                     84: my $download_loncapa  = 1;
                     85: my $showhelp          = 0;
                     86: 
                     87: ###################################
                     88: #
                     89: #  Deal with command line options
                     90: #
                     91: ###################################
                     92: GetOptions(
                     93: 	   "make_www!"                => \$make_www,
                     94: 	   "install_pwauth!"          => \$install_pwauth,
                     95: 	   "setup_mysql!"             => \$setup_mysql,
                     96: 	   "setup_mysql_permissions!" => \$setup_mysql_permissions,
                     97: 	   "stop_services!"           => \$stop_services,
                     98: 	   "install_httpd_conf!"      => \$install_httpd_conf,
                     99: 	   "download_loncapa!"        => \$download_loncapa,
                    100:            "help"                     => \$showhelp,
                    101: 	   );
                    102: 
                    103: if ($showhelp) {
                    104:     print <<END;
                    105: $0: The following options are available:
                    106: 
                    107:   Option               Default  Description
                    108: ---------------------------------------------
                    109: make_www                 yes    Create the www user
                    110: install_pwauth           yes    Install pwauth
                    111: setup_mysql              yes    Configure MySQL
                    112: setup_mysql_permissions  yes    Configure MySQL Permissions
                    113: stop_services            no     Stop unneeded services
                    114: install_httpd_conf       yes    Install LON-CAPA provided httpd.conf
                    115: download_loncapa         yes    Download LON-CAPA sources code
                    116: help                            Show this help
                    117: 
                    118: Examples:
                    119: 
                    120: Default behaviour is the same as:
                    121: 
                    122:   $0 --make_www --install_pwauth --setup_mysql \
                    123:      --setup_mysql_permissions --install_httpd_conf \
                    124:      --download_loncapa 
                    125: 
                    126: Do everything as normal but do not configure MySQL database:
                    127: 
                    128:   $0 --nosetup_mysql
                    129: 
                    130: END
                    131:     exit;
                    132: }
                    133: 
                    134: print <<"END";
                    135: ********************************************************************
                    136: 
                    137:                     Welcome to LON-CAPA 
                    138: 
                    139: This script will configure the base software that LON-CAPA needs to
                    140: run properly. 
                    141: 
                    142: ********************************************************************
                    143: END
                    144: 
                    145: my $instdir = `pwd`;
                    146: chomp($instdir);
                    147: 
                    148: if ($make_www) {
                    149:     &setup_www();
                    150: } else {
                    151:     &print_and_log("Skipping creation of user 'www'.\n");
                    152: }
                    153: 
                    154: if ($install_pwauth) {
                    155:     &build_and_install_mod_auth_external();
                    156: } else {
                    157:     &print_and_log("Skipping pwauth installation.\n");
                    158: }
                    159: 
                    160: if ($stop_services) {
                    161:     &kill_extra_services();
                    162: } else {
                    163:     # No message as not stopping the services is the default
                    164: }
                    165: 
                    166: if ($setup_mysql) {
                    167:     &setup_mysql();
                    168: } else {
                    169:     &print_and_log("Skipping configuration of MySQL.\n");
                    170: }
                    171: 
                    172: ##
                    173: ## Set up httpd 
                    174: ##
                    175: print_and_log("Setting httpd to start on boot up.\n");
                    176: system("/sbin/chkconfig httpd on");
                    177: 
                    178: if ($install_httpd_conf) {
                    179:     &copy_httpd_conf();
                    180: }
                    181: 
1.2       matthew   182: #my $lctarball = 'loncapa-current.tar.gz';
1.4       matthew   183: my $lctarball = 'loncapa-fedora-current.tar.gz';
1.1       matthew   184: if ($download_loncapa) {
                    185:     &download_loncapa($lctarball);
                    186: } else {
                    187:     print_and_log(<<"END");
                    188: 
                    189: You have requested not to have the LON-CAPA source downloaded from 
                    190: install.loncapa.org.
                    191: 
                    192: LON-CAPA is not yet installed on your system.
                    193: 
                    194: You may retrieve the source for LON-CAPA by executing :
                    195: wget http://install.loncapa.org/versions/$lctarball
                    196: END
                    197: }
                    198: 
                    199: exit;
                    200: 
                    201: ####################################################################
                    202: ####################################################################
                    203: 
                    204: ###############################################
                    205: ###############################################
                    206: sub setup_www {
                    207:     ##
                    208:     ## Set up www
                    209:     ##
                    210:     print_and_log("Creating user 'www'\n");
                    211:     $result = `/usr/sbin/useradd www`;
                    212:     if (! (($result eq '') || ($result =~ /user www exists/))) {
                    213: 	die "Unable to add user www.  Halting.\n";
                    214:     }
                    215:     writelog ($result);
                    216: }
                    217: 
                    218: ###############################################
                    219: ###############################################
                    220: sub uid_of_www {
                    221:     my $num = `grep ^www /etc/passwd | cut -d':' -f3`;
                    222:     chomp $num;
                    223:     if (int($num) == $num) {
                    224: 	writelog ("uid of www = $num\n");
                    225:     } else {
                    226: 	die "Unable to determine UID of user www\n  Halting.\n";
                    227:     }
                    228:     print_and_log("\n");
                    229:     return $num;
                    230: }
                    231: 
                    232: ###############################################
                    233: ##
                    234: ## mod_auth_external
                    235: ##
                    236: ###############################################
                    237: sub build_and_install_mod_auth_external {
                    238:     my $num = &uid_of_www();
                    239:     # Patch mod_auth_external
                    240:     print_and_log("Building authentication system for LON-CAPA users.\n");
                    241:     my $patch = <<"ENDPATCH";
                    242: 148c148
                    243: < #define SERVER_UIDS 99		/* user "nobody" */
                    244: ---
                    245: > #define SERVER_UIDS $num		/* user "www" */
                    246: ENDPATCH
                    247: 
                    248:     if (! -e "/usr/bin/patch") {
                    249: 	print_and_log("You must install the software development tools package ".
                    250: 		      "when installing RedHat.\n");
                    251: 	die;
                    252:     }
                    253:     &die_if_nonempty(`cd /tmp; tar zxf $instdir/mod_auth_external-2.1.13.tar.gz`,
                    254: 		     "Unable to extract mod_auth_external\n");
                    255:     my $dir = "/tmp/mod_auth_external-2.1.13/pwauth";
                    256:     open PATCH, "| patch $dir/config.h" || 
                    257: 	die "Unable to start patch for mod_auth_external.  Halting\n";
                    258:     print PATCH $patch;
                    259:     close PATCH;
                    260:     print_and_log("\n");
                    261:     ##
                    262:     ## Compile patched pwauth
                    263:     ##
                    264:     print_and_log("Compiling pwauth\n");
                    265:     $result = `cd $dir/; make`;
                    266:     my $expected = <<"END";
                    267: gcc -g    -c -o pwauth.o pwauth.c
                    268: gcc -o pwauth -g  pwauth.o -lcrypt
                    269: END
                    270:     if ($result ne $expected) {
                    271: 	die "Unable to compile patched pwauth.  Halting.\n";
                    272:     }    
                    273:     print_and_log( "appearant success compiling pwauth:\n".$result );
                    274:     # Install patched pwauth
                    275:     print_and_log("Copying pwauth to /usr/local/sbin\n");
                    276:     if (! copy "$dir/pwauth","/usr/local/sbin/pwauth") {
                    277: 	die "Unable to copy $dir/pwauth to /usr/local/sbin/pwauth.\n$!\nHalting\n";
                    278:     }
                    279:     if (! chmod (06755, "/usr/local/sbin/pwauth")) {
                    280: 	die "Unable to set permissions on /usr/local/sbin/pwauth.\n";
                    281:     }
                    282:     print_and_log("\n");
                    283: }
                    284: 
                    285: ###############################################
                    286: ##
                    287: ## Kill some services
                    288: ##
                    289: ###############################################
                    290: sub kill_extra_services {
                    291:     &print_and_log("\nKilling unneccessary services.\n");
                    292:     foreach my $service ('cups','sendmail') {
                    293: 	&print_and_log(`/etc/init.d/$service stop`);
                    294: 	&print_and_log("removing $service from startup.\n");
                    295: 	&print_and_log(`chkconfig --del $service`);
                    296:     }
                    297: }
                    298: 
                    299: ###############################################
                    300: ##
                    301: ## Set up mysql
                    302: ##
                    303: ###############################################
                    304: sub setup_mysql {
                    305:     print_and_log("Setting mysqld to start on boot up.\n");
                    306:     system("/sbin/chkconfig --add mysqld");
                    307:     system("/sbin/chkconfig mysqld on");
                    308:     &writelog(`/sbin/chkconfig --list mysqld`);
                    309:     #
                    310:     writelog("mysql will start automatically on boot.\n");
                    311:     writelog(`/etc/rc.d/init.d/mysqld start`);
                    312:     print_and_log("Waiting for mysql daemon to start.\n");
                    313:     sleep 5;
                    314:     my $status = system("/etc/rc.d/init.d/mysqld status");
                    315:     if ($status != 0) {
                    316: 	die "Unable to start mysql daemon\nHalting\n";
                    317:     } else {
                    318: 	print_and_log("Mysql daemon is running.\n");
                    319:     }
                    320:     print_and_log("\n");
                    321:     #
                    322:     my $mysql_commands = "CREATE DATABASE loncapa;\n";
                    323:     if ($setup_mysql_permissions) {
                    324: 	##
                    325: 	## Get root password for mysql client
                    326: 	##
                    327: 	print <<END;
                    328: Please enter a root password for the mysql database.
                    329: It does not have to match your root account password, but you will need
                    330: to remember it.
                    331: END
                    332:         my $rootpass = <>;
                    333: 	chomp $rootpass;
                    334: 	$mysql_commands .= <<"END";
                    335: INSERT INTO user (Host, User, Password)
                    336: VALUES ('localhost','www',password('localhostkey'));
1.5     ! matthew   337: INSERT INTO db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv) VALUES ('localhost','loncapa','www','Y','Y','Y','Y','Y','Y','N','Y','Y','Y');
1.1       matthew   338: SET PASSWORD FOR root\@localhost=PASSWORD('$rootpass');
                    339: DELETE FROM user WHERE host<>'localhost';
                    340: FLUSH PRIVILEGES;
                    341: END
                    342:         print_and_log("Retrieved MySQL root password.\n");
                    343:     } else {
                    344: 	print_and_log("Skipping mysql permissions setup.\n");
                    345:     }
                    346:     $mysql_commands .= <<"ENDMYSQL";
                    347: USE loncapa;
                    348: 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;
                    349: EXIT
                    350: ENDMYSQL
                    351:     ##
                    352:     ## Execute the MySQL commands
                    353:     ##
                    354:     print_and_log("Starting mysql client.\n");
                    355:     open MYSQL, "|mysql -u root mysql" || die "Unable to start mysql\n";
                    356:     print MYSQL $mysql_commands;
                    357: 
                    358:     close MYSQL;
                    359:     print_and_log("\n");
                    360: }
                    361: 
                    362: 
                    363: ###############################################
                    364: ##
                    365: ## Copy our (probably lousy) httpd.conf to its rightful place
                    366: ##
                    367: ###############################################
                    368: sub copy_httpd_conf {
                    369:     print_and_log("Copying our httpd.conf to /etc/httpd/conf/httpd.conf\n");
                    370:     copy "/etc/httpd/conf/httpd.conf","/etc/httpd/conf/httpd.conf.original";
                    371:     copy "$instdir/httpd.conf","/etc/httpd/conf/httpd.conf";
                    372:     chmod 0444,"/etc/httpd/conf/httpd.conf";
                    373:     print_and_log("\n");
                    374: }
                    375: 
                    376: 
                    377: ###############################################
                    378: ##
                    379: ## Retrieve the latest LON-CAPA release
                    380: ##
                    381: ###############################################
                    382: sub download_loncapa {
                    383:     my ($lctarball) = @_;
                    384:     if (! -e "$instdir/$lctarball") {
                    385: 	print_and_log("Retrieving LON-CAPA source files from ".
                    386: 		      "http://install.loncapa.org\n");
                    387: 	system("wget http://install.loncapa.org/versions/$lctarball ".
                    388: 	       "2>/dev/null 1>/dev/null");
                    389: 	if (! -e "./$lctarball") {
                    390: 	    die("Unable to retrieve LON-CAPA source files from\n".
                    391: 		"http://install.loncapa.org/versions/$lctarball\n");
                    392: 	}
                    393: 	print_and_log("\n");
                    394:     } else {
                    395: 	print_and_log(<<"END");
                    396: ------------------------------------------------------------------------
                    397: 
                    398: You seem to have a version of loncapa-current.tar.gz in $instdir.  
                    399: This copy will be used and a new version will NOT be downloaded.  
                    400: If you wish, you may download a new version by executing:
                    401: 
                    402: wget http://install.loncapa.org/versions/loncapa-current.tar.gz
                    403: 
                    404: ------------------------------------------------------------------------
                    405: END
                    406:     }
                    407: 
                    408:     ##
                    409:     ## untar loncapa.tar.gz
                    410:     ##
                    411:     print_and_log("Extracting LON-CAPA source files\n");
1.3       matthew   412:     writelog(`cd ~root; tar zxf $instdir/$lctarball`);
1.1       matthew   413:     print_and_log("\n");
                    414:     print <<"ENDMSG";
                    415: All of the extra files seem to have been installed correctly.  It remains for 
                    416: you to execute the following commands:
                    417: 
                    418: cd /root/loncapa-N.N     (N.N should correspond to a version number like '0.4')
                    419: ./UPDATE
                    420: 
                    421: If you have any trouble, please see http://install.loncapa.org/ and 
                    422: http://help.loncapa.org/.  
                    423: ENDMSG
                    424: }
                    425: 
                    426: close LOG;
                    427: 

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