Annotation of doc/install/suse/install.pl, revision 1.2

1.1       albertel    1: #!/usr/bin/perl -w
                      2: # The LearningOnline Network 
                      3: # Fedora installation script
                      4: #
1.2     ! albertel    5: # $Id: install.pl,v 1.1 2005/06/15 17:56:41 albertel Exp $
1.1       albertel    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.2     ! albertel   38: print LOG '$Id: install.pl,v 1.1 2005/06/15 17:56:41 albertel Exp $'."\n";
1.1       albertel   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       = 0;
                     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 = 0;
1.2     ! albertel   84: my $download_loncapa  = 1;
1.1       albertel   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("insserv apache");
                    177: 
                    178: if ($install_httpd_conf) {
                    179:     &copy_httpd_conf();
                    180: }
                    181: 
                    182: #my $lctarball = 'loncapa-current.tar.gz';
1.2     ! albertel  183: #my $lctarball = 'loncapa-fedora-current.tar.gz';
        !           184: my $lctarball = 'loncapa-suse-current.tar.gz';
1.1       albertel  185: if ($download_loncapa) {
                    186:     &download_loncapa($lctarball);
                    187: } else {
                    188:     print_and_log(<<"END");
                    189: 
                    190: You have requested not to have the LON-CAPA source downloaded from 
                    191: install.loncapa.org.
                    192: 
                    193: LON-CAPA is not yet installed on your system.
                    194: 
                    195: You may retrieve the source for LON-CAPA by executing :
                    196: wget http://install.loncapa.org/versions/$lctarball
                    197: END
                    198: }
                    199: 
                    200: exit;
                    201: 
                    202: ####################################################################
                    203: ####################################################################
                    204: 
                    205: ###############################################
                    206: ###############################################
                    207: sub setup_www {
                    208:     ##
                    209:     ## Set up www
                    210:     ##
                    211:     print_and_log("Creating user 'www'\n");
                    212:     $result = `/usr/sbin/useradd www`;
                    213:     if (! (($result eq '') || ($result =~ /user www exists/))) {
                    214: 	die "Unable to add user www.  Halting.\n";
                    215:     }
                    216:     writelog ($result);
                    217: }
                    218: 
                    219: ###############################################
                    220: ###############################################
                    221: sub uid_of_www {
                    222:     my ($num) = (getpwnam('www'))[2];
                    223:     return $num;
                    224: }
                    225: 
                    226: ###############################################
                    227: ##
                    228: ## mod_auth_external
                    229: ##
                    230: ###############################################
                    231: sub build_and_install_mod_auth_external {
                    232:     my $num = &uid_of_www();
                    233:     # Patch mod_auth_external
                    234:     print_and_log("Building authentication system for LON-CAPA users.\n");
                    235:     my $patch = <<"ENDPATCH";
                    236: 148c148
                    237: < #define SERVER_UIDS 99		/* user "nobody" */
                    238: ---
                    239: > #define SERVER_UIDS $num		/* user "www" */
                    240: ENDPATCH
                    241: 
                    242:     if (! -e "/usr/bin/patch") {
                    243: 	print_and_log("You must install the software development tools package ".
                    244: 		      "when installing RedHat.\n");
                    245: 	die;
                    246:     }
                    247:     &die_if_nonempty(`cd /tmp; tar zxf $instdir/mod_auth_external-2.1.15.tar.gz`,
                    248: 		     "Unable to extract mod_auth_external\n");
                    249:     my $dir = "/tmp/mod_auth_external-2.1.15/pwauth";
                    250:     open PATCH, "| patch $dir/config.h" || 
                    251: 	die "Unable to start patch for mod_auth_external.  Halting\n";
                    252:     print PATCH $patch;
                    253:     close PATCH;
                    254:     print_and_log("\n");
                    255:     ##
                    256:     ## Compile patched pwauth
                    257:     ##
                    258:     print_and_log("Compiling pwauth\n");
                    259:     $result = `cd $dir/; make`;
                    260:     my $expected = <<"END";
                    261: gcc -g    -c -o pwauth.o pwauth.c
                    262: gcc -o pwauth -g  pwauth.o -lcrypt
                    263: END
                    264:     if ($result ne $expected) {
                    265: 	die "Unable to compile patched pwauth.  Halting.\n";
                    266:     }    
                    267:     print_and_log( "appearant success compiling pwauth:\n".$result );
                    268:     # Install patched pwauth
                    269:     print_and_log("Copying pwauth to /usr/local/sbin\n");
                    270:     if (! copy "$dir/pwauth","/usr/local/sbin/pwauth") {
                    271: 	die "Unable to copy $dir/pwauth to /usr/local/sbin/pwauth.\n$!\nHalting\n";
                    272:     }
                    273:     if (! chmod (06755, "/usr/local/sbin/pwauth")) {
                    274: 	die "Unable to set permissions on /usr/local/sbin/pwauth.\n";
                    275:     }
                    276:     print_and_log("\n");
                    277: }
                    278: 
                    279: ###############################################
                    280: ##
                    281: ## Kill some services
                    282: ##
                    283: ###############################################
                    284: sub kill_extra_services {
                    285:     &print_and_log("\nKilling unneccessary services.\n");
                    286:     foreach my $service ('cups','sendmail') {
                    287: 	&print_and_log(`/etc/init.d/$service stop`);
                    288: 	&print_and_log("removing $service from startup.\n");
                    289: 	&print_and_log(`chkconfig --del $service`);
                    290:     }
                    291: }
                    292: 
                    293: ###############################################
                    294: ##
                    295: ## Set up mysql
                    296: ##
                    297: ###############################################
                    298: sub setup_mysql {
                    299:     print_and_log("Setting mysqld to start on boot up.\n");
                    300:     system("insserv mysql");
                    301:     #
                    302:     writelog("mysql will start automatically on boot.\n");
                    303:     writelog(`/etc/init.d/mysql start`);
                    304:     print_and_log("Waiting for mysql daemon to start.\n");
                    305:     sleep 5;
                    306:     my $status = system("/etc/init.d/mysql status");
                    307:     if ($status != 0) {
                    308: 	die "Unable to start mysql daemon\nHalting\n";
                    309:     } else {
                    310: 	print_and_log("Mysql daemon is running.\n");
                    311:     }
                    312:     print_and_log("\n");
                    313:     #
                    314:     my $mysql_commands = "CREATE DATABASE loncapa;\n";
                    315:     if ($setup_mysql_permissions) {
                    316: 	##
                    317: 	## Get root password for mysql client
                    318: 	##
                    319: 	print <<END;
                    320: Please enter a root password for the mysql database.
                    321: It does not have to match your root account password, but you will need
                    322: to remember it.
                    323: END
                    324:         my $rootpass = <>;
                    325: 	chomp $rootpass;
                    326: 	$mysql_commands .= <<"END";
                    327: INSERT INTO user (Host, User, Password)
                    328: VALUES ('localhost','www',password('localhostkey'));
                    329: INSERT INTO db VALUES ('localhost','loncapa','www','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y');
                    330: SET PASSWORD FOR root\@localhost=PASSWORD('$rootpass');
                    331: DELETE FROM user WHERE host<>'localhost';
                    332: FLUSH PRIVILEGES;
                    333: END
                    334:         print_and_log("Retrieved MySQL root password.\n");
                    335:     } else {
                    336: 	print_and_log("Skipping mysql permissions setup.\n");
                    337:     }
                    338:     $mysql_commands .= <<"ENDMYSQL";
                    339: USE loncapa;
                    340: 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;
                    341: EXIT
                    342: ENDMYSQL
                    343:     ##
                    344:     ## Execute the MySQL commands
                    345:     ##
                    346:     print_and_log("Starting mysql client.\n");
                    347:     open MYSQL, "|mysql -u root mysql" || die "Unable to start mysql\n";
                    348:     print MYSQL $mysql_commands;
                    349: 
                    350:     close MYSQL;
                    351:     print_and_log("\n");
                    352: }
                    353: 
                    354: 
                    355: ###############################################
                    356: ##
                    357: ## Copy our (probably lousy) httpd.conf to its rightful place
                    358: ##
                    359: ###############################################
                    360: sub copy_httpd_conf {
                    361:     print_and_log("Copying our httpd.conf to /etc/httpd/conf/httpd.conf\n");
                    362:     copy "/etc/httpd/conf/httpd.conf","/etc/httpd/conf/httpd.conf.original";
                    363:     copy "$instdir/httpd.conf","/etc/httpd/conf/httpd.conf";
                    364:     chmod 0444,"/etc/httpd/conf/httpd.conf";
                    365:     print_and_log("\n");
                    366: }
                    367: 
                    368: 
                    369: ###############################################
                    370: ##
                    371: ## Retrieve the latest LON-CAPA release
                    372: ##
                    373: ###############################################
                    374: sub download_loncapa {
                    375:     my ($lctarball) = @_;
                    376:     if (! -e "$instdir/$lctarball") {
                    377: 	print_and_log("Retrieving LON-CAPA source files from ".
                    378: 		      "http://install.loncapa.org\n");
                    379: 	system("wget http://install.loncapa.org/versions/$lctarball ".
                    380: 	       "2>/dev/null 1>/dev/null");
                    381: 	if (! -e "./$lctarball") {
                    382: 	    die("Unable to retrieve LON-CAPA source files from\n".
                    383: 		"http://install.loncapa.org/versions/$lctarball\n");
                    384: 	}
                    385: 	print_and_log("\n");
                    386:     } else {
                    387: 	print_and_log(<<"END");
                    388: ------------------------------------------------------------------------
                    389: 
                    390: You seem to have a version of loncapa-current.tar.gz in $instdir.  
                    391: This copy will be used and a new version will NOT be downloaded.  
                    392: If you wish, you may download a new version by executing:
                    393: 
                    394: wget http://install.loncapa.org/versions/loncapa-fedora-current.tar.gz
                    395: 
                    396: ------------------------------------------------------------------------
                    397: END
                    398:     }
                    399: 
                    400:     ##
                    401:     ## untar loncapa.tar.gz
                    402:     ##
                    403:     print_and_log("Extracting LON-CAPA source files\n");
                    404:     writelog(`cd ~root; tar zxf $instdir/$lctarball`);
                    405:     print_and_log("\n");
                    406:     print <<"ENDMSG";
                    407: All of the extra files seem to have been installed correctly.  It remains for 
                    408: you to execute the following commands:
                    409: 
                    410: cd /root/loncapa-N.N     (N.N should correspond to a version number like '0.4')
                    411: ./UPDATE
                    412: 
                    413: If you have any trouble, please see http://install.loncapa.org/ and 
                    414: http://help.loncapa.org/.  
                    415: ENDMSG
                    416: }
                    417: 
                    418: close LOG;
                    419: 

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