Annotation of doc/install/suse/suse10.1/install.pl, revision 1.1

1.1     ! raeburn     1: #!/usr/bin/perl -w
        !             2: # The LearningOnline Network 
        !             3: # SLES10 installation script
        !             4: #
        !             5: # Copyright Michigan State University Board of Trustees
        !             6: #
        !             7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
        !             8: #
        !             9: # LON-CAPA is free software; you can redistribute it and/or modify
        !            10: # it under the terms of the GNU General Public License as published by
        !            11: # the Free Software Foundation; either version 2 of the License, or
        !            12: # (at your option) any later version.
        !            13: #
        !            14: # LON-CAPA is distributed in the hope that it will be useful,
        !            15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            17: # GNU General Public License for more details.
        !            18: #
        !            19: # You should have received a copy of the GNU General Public License
        !            20: # along with LON-CAPA; if not, write to the Free Software
        !            21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        !            22: #
        !            23: # http://www.lon-capa.org/
        !            24: #
        !            25: 
        !            26: use strict;
        !            27: use File::Copy;
        !            28: use Getopt::Long;
        !            29: 
        !            30: my $result; 
        !            31: my $test;
        !            32: 
        !            33: # note: The filehandle LOG is global.
        !            34: open LOG,">>loncapa_install.log" || die "Unable to open log file.\n";
        !            35: 
        !            36: print LOG '$Id: install.pl,v 1.2 2006/10/10 01:16:33 raeburn Exp $'."\n";
        !            37: 
        !            38: # Some friendly subroutines
        !            39: sub die_if_nonempty {
        !            40:     my ($string,$error)=@_;
        !            41:     return if (! defined($error));
        !            42:     chomp($string);chomp($error);
        !            43:     if ($string ne '') {
        !            44:         print_and_log("$error\nHalting.\n");
        !            45:         die;
        !            46:     }
        !            47: }
        !            48: 
        !            49: sub make_link_or_die {
        !            50:     my ($source,$dest)=@_;
        !            51:     &die_if_nonempty
        !            52:         (`ln -fs $source $dest`,"Unable to link $source to $dest.");
        !            53:     print LOG "Link from $source to $dest made successfully\n";
        !            54: }
        !            55: 
        !            56: sub writelog {
        !            57:     while ($_ = shift) {
        !            58:         chomp;
        !            59:         print LOG "$_\n";
        !            60:     }
        !            61: }
        !            62: 
        !            63: sub print_and_log {
        !            64:     while ($_=shift) {
        !            65:         chomp;
        !            66:         print "$_\n";
        !            67:         print LOG "$_\n";
        !            68:     }
        !            69: }
        !            70: 
        !            71: ###############################
        !            72: #                             #
        !            73: #  Define default behaviour   #
        !            74: #                             #
        !            75: ###############################
        !            76: my $make_www       = 1;
        !            77: my $install_pwauth = 1;
        !            78: my $setup_mysql    = 1;
        !            79: my $setup_mysql_permissions = 1;
        !            80: my $stop_services     = 0;
        !            81: my $install_apache2_conf = 1;
        !            82: my $download_loncapa  = 1;
        !            83: my $showhelp          = 0;
        !            84: 
        !            85: ###################################
        !            86: #
        !            87: #  Deal with command line options
        !            88: #
        !            89: ###################################
        !            90: GetOptions(
        !            91: 	   "make_www!"                => \$make_www,
        !            92: 	   "install_pwauth!"          => \$install_pwauth,
        !            93: 	   "setup_mysql!"             => \$setup_mysql,
        !            94: 	   "setup_mysql_permissions!" => \$setup_mysql_permissions,
        !            95: 	   "stop_services!"           => \$stop_services,
        !            96: 	   "install_apache2_conf!"    => \$install_apache2_conf,
        !            97: 	   "download_loncapa!"        => \$download_loncapa,
        !            98:            "help"                     => \$showhelp,
        !            99: 	   );
        !           100: 
        !           101: if ($showhelp) {
        !           102:     print <<END;
        !           103: $0: The following options are available:
        !           104: 
        !           105:   Option               Default  Description
        !           106: ---------------------------------------------
        !           107: make_www                 yes    Create the www user
        !           108: install_pwauth           yes    Install pwauth
        !           109: setup_mysql              yes    Configure MySQL
        !           110: setup_mysql_permissions  yes    Configure MySQL Permissions
        !           111: stop_services            no     Stop unneeded services
        !           112: install_apache2_conf     yes    Install LON-CAPA provided Apache 2 config files.
        !           113: download_loncapa         yes    Download LON-CAPA sources code
        !           114: help                            Show this help
        !           115: 
        !           116: Examples:
        !           117: 
        !           118: Default behaviour is the same as:
        !           119: 
        !           120:   $0 --make_www --install_pwauth --setup_mysql \
        !           121:      --setup_mysql_permissions --install_apache2_conf \
        !           122:      --download_loncapa 
        !           123: 
        !           124: Do everything as normal but do not configure MySQL database:
        !           125: 
        !           126:   $0 --nosetup_mysql
        !           127: 
        !           128: END
        !           129:     exit;
        !           130: }
        !           131: 
        !           132: print <<"END";
        !           133: ********************************************************************
        !           134: 
        !           135:                     Welcome to LON-CAPA 
        !           136: 
        !           137: This script will configure the base software that LON-CAPA needs to
        !           138: run properly. 
        !           139: 
        !           140: ********************************************************************
        !           141: END
        !           142: 
        !           143: my $instdir = `pwd`;
        !           144: chomp($instdir);
        !           145: 
        !           146: if ($make_www) {
        !           147:     &setup_www();
        !           148: } else {
        !           149:     &print_and_log("Skipping creation of user 'www'.\n");
        !           150: }
        !           151: 
        !           152: if ($install_pwauth) {
        !           153:     &build_and_install_mod_auth_external();
        !           154: } else {
        !           155:     &print_and_log("Skipping pwauth installation.\n");
        !           156: }
        !           157: 
        !           158: if ($stop_services) {
        !           159:     &kill_extra_services();
        !           160: } else {
        !           161:     # No message as not stopping the services is the default
        !           162: }
        !           163: 
        !           164: if ($setup_mysql) {
        !           165:     &setup_mysql();
        !           166: } else {
        !           167:     &print_and_log("Skipping configuration of MySQL.\n");
        !           168: }
        !           169: 
        !           170: ##
        !           171: ## Set up httpd 
        !           172: ##
        !           173: print_and_log("Setting httpd to start on boot up.\n");
        !           174: system("insserv apache2");
        !           175: 
        !           176: if ($install_apache2_conf) {
        !           177:     &copy_apache2_conf();
        !           178: }
        !           179: 
        !           180: my $lctarball = 'loncapa-suse-current.tar.gz';
        !           181: if ($download_loncapa) {
        !           182:     &download_loncapa($lctarball);
        !           183: } else {
        !           184:     print_and_log(<<"END");
        !           185: 
        !           186: You have requested not to have the LON-CAPA source downloaded from 
        !           187: install.loncapa.org.
        !           188: 
        !           189: LON-CAPA is not yet installed on your system.
        !           190: 
        !           191: You may retrieve the source for LON-CAPA by executing :
        !           192: wget http://install.loncapa.org/versions/$lctarball
        !           193: END
        !           194: }
        !           195: 
        !           196: exit;
        !           197: 
        !           198: ####################################################################
        !           199: ####################################################################
        !           200: 
        !           201: ###############################################
        !           202: ###############################################
        !           203: sub setup_www {
        !           204:     ##
        !           205:     ## Set up www
        !           206:     ##
        !           207:     print_and_log("Creating user 'www'\n");
        !           208:     # -- Add group
        !           209:     my $status = `/usr/sbin/groupadd www`;
        !           210:     if (! (($status eq '') || ($status =~ /Group `www' already exists\./))) {
        !           211:         die "Unable to add group www.  Halting.\n";
        !           212:     }
        !           213:     my $gid = getgrnam('www');
        !           214: 
        !           215:     if (open (PIPE, "/usr/sbin/useradd -c LONCAPA -g $gid www 2>&1 |")) {
        !           216:         $status = <PIPE>;
        !           217:         close(PIPE);
        !           218:         chomp($status);
        !           219:         if (! (($status eq '') || ($status =~ /Account `www' already exists\./))){
        !           220:             die "Unable to add user www.  Halting.\n";
        !           221:         }
        !           222:     }  else {
        !           223:         die "Unable to run command to add user www. Halting.\n";
        !           224:     }
        !           225: 
        !           226:     if (!-e '/home/www') {
        !           227:         mkdir('/home/www',0755);
        !           228:         system('chmod www:www /home/www');
        !           229:     }
        !           230:     writelog ($status);
        !           231: }
        !           232: 
        !           233: ###############################################
        !           234: ###############################################
        !           235: sub uid_of_www {
        !           236:     my ($num) = (getpwnam('www'))[2];
        !           237:     return $num;
        !           238: }
        !           239: 
        !           240: ###############################################
        !           241: ##
        !           242: ## mod_auth_external
        !           243: ##
        !           244: ###############################################
        !           245: sub build_and_install_mod_auth_external {
        !           246:     my $num = &uid_of_www();
        !           247:     # Patch pwauth
        !           248:     print_and_log("Building authentication system for LON-CAPA users.\n");
        !           249:     my $patch = <<"ENDPATCH";
        !           250: 148c148
        !           251: < #define SERVER_UIDS 99		/* user "nobody" */
        !           252: ---
        !           253: > #define SERVER_UIDS $num		/* user "www" */
        !           254: ENDPATCH
        !           255: 
        !           256:     if (! -e "/usr/bin/patch") {
        !           257: 	print_and_log("You must install the software development tools package ".
        !           258: 		      "when installing RedHat.\n");
        !           259: 	die;
        !           260:     }
        !           261:     &die_if_nonempty(`cd /tmp; tar zxf $instdir/pwauth-2.2.8.tar.gz`,
        !           262: 		     "Unable to extract pwauth\n");
        !           263:     my $dir = "/tmp/pwauth-2.2.8";
        !           264:     open PATCH, "| patch $dir/config.h" || 
        !           265: 	die "Unable to start patch for pwauth.  Halting\n";
        !           266:     print PATCH $patch;
        !           267:     close PATCH;
        !           268:     print_and_log("\n");
        !           269:     ##
        !           270:     ## Compile patched pwauth
        !           271:     ##
        !           272:     print_and_log("Compiling pwauth\n");
        !           273:     $result = `cd $dir/; make`;
        !           274:     my $expected = <<"END";
        !           275: gcc -g    -c -o pwauth.o pwauth.c
        !           276: gcc -o pwauth -g  pwauth.o -lcrypt
        !           277: END
        !           278:     if ($result ne $expected) {
        !           279: 	die "Unable to compile patched pwauth.  Halting.\n";
        !           280:     }    
        !           281:     print_and_log( "appearant success compiling pwauth:\n".$result );
        !           282:     # Install patched pwauth
        !           283:     print_and_log("Copying pwauth to /usr/local/sbin\n");
        !           284:     if (! copy "$dir/pwauth","/usr/local/sbin/pwauth") {
        !           285: 	die "Unable to copy $dir/pwauth to /usr/local/sbin/pwauth.\n$!\nHalting\n";
        !           286:     }
        !           287:     if (! chmod (06755, "/usr/local/sbin/pwauth")) {
        !           288: 	die "Unable to set permissions on /usr/local/sbin/pwauth.\n";
        !           289:     }
        !           290:     print_and_log("\n");
        !           291: }
        !           292: 
        !           293: ###############################################
        !           294: ##
        !           295: ## Kill some services
        !           296: ##
        !           297: ###############################################
        !           298: sub kill_extra_services {
        !           299:     &print_and_log("\nKilling unneccessary services.\n");
        !           300:     foreach my $service ('cups','sendmail') {
        !           301: 	&print_and_log(`/etc/init.d/$service stop`);
        !           302: 	&print_and_log("removing $service from startup.\n");
        !           303: 	&print_and_log(`chkconfig --del $service`);
        !           304:     }
        !           305: }
        !           306: 
        !           307: ###############################################
        !           308: ##
        !           309: ## Set up mysql
        !           310: ##
        !           311: ###############################################
        !           312: sub setup_mysql {
        !           313:     print_and_log("Setting mysqld to start on boot up.\n");
        !           314:     system("insserv mysql");
        !           315:     #
        !           316:     writelog("mysql will start automatically on boot.\n");
        !           317:     writelog(`/etc/init.d/mysql start`);
        !           318:     print_and_log("Waiting for mysql daemon to start.\n");
        !           319:     sleep 5;
        !           320:     my $status = system("/etc/init.d/mysql status");
        !           321:     if ($status != 0) {
        !           322: 	die "Unable to start mysql daemon\nHalting\n";
        !           323:     } else {
        !           324: 	print_and_log("Mysql daemon is running.\n");
        !           325:     }
        !           326:     print_and_log("\n");
        !           327:     #
        !           328:     my $mysql_commands = "CREATE DATABASE loncapa;\n";
        !           329:     if ($setup_mysql_permissions) {
        !           330: 	##
        !           331: 	## Get root password for mysql client
        !           332: 	##
        !           333: 	print <<END;
        !           334: Please enter a root password for the mysql database.
        !           335: It does not have to match your root account password, but you will need
        !           336: to remember it.
        !           337: END
        !           338:         my $rootpass = <>;
        !           339: 	chomp $rootpass;
        !           340: 	$mysql_commands .= <<"END";
        !           341: INSERT INTO user (Host, User, Password)
        !           342: VALUES ('localhost','www',password('localhostkey'));
        !           343: INSERT INTO db VALUES ('localhost','loncapa','www','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y','N','N','N','N','N');
        !           344: DELETE FROM user WHERE host<>'localhost';
        !           345: SET PASSWORD FOR 'root'\@'localhost'=PASSWORD('$rootpass');
        !           346: FLUSH PRIVILEGES;
        !           347: END
        !           348:         print_and_log("Retrieved MySQL root password.\n");
        !           349:     } else {
        !           350: 	print_and_log("Skipping mysql permissions setup.\n");
        !           351:     }
        !           352:     $mysql_commands .= <<"ENDMYSQL";
        !           353: USE loncapa;
        !           354: 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;
        !           355: EXIT
        !           356: ENDMYSQL
        !           357:     ##
        !           358:     ## Execute the MySQL commands
        !           359:     ##
        !           360:     print_and_log("Starting mysql client.\n");
        !           361:     open MYSQL, "|mysql -u root mysql" || die "Unable to start mysql\n";
        !           362:     print MYSQL $mysql_commands;
        !           363: 
        !           364:     close MYSQL;
        !           365:     print_and_log("\n");
        !           366: }
        !           367: 
        !           368: 
        !           369: ###############################################
        !           370: ##
        !           371: ## Copy apache2 config files: default-server.conf,
        !           372: ##   uid.conf, /etc/sysconfig/apache2 
        !           373: ##   and create symlink from /srv/www/conf to /etc/apache2 
        !           374: ##
        !           375: ###############################################
        !           376: sub copy_apache2_conf {
        !           377:     print_and_log("Copying our default-server.conf to /etc/apache2/default-server.conf\n");
        !           378:     if (!-e "/etc/apache2/default-server.conf.original") {
        !           379:         copy "/etc/apache2/default-server.conf","/etc/apache2/default-server.conf.original";
        !           380:     }
        !           381:     copy "$instdir/default-server.conf","/etc/apache2/default-server.conf";
        !           382:     chmod 0444,"/etc/apache2/default-server.conf";
        !           383:     # Make symlink for conf directory (included in loncapa_apache.conf)
        !           384:     my $can_symlink = (eval { symlink('/etc/apache2','/srv/www/conf'); }, $@ eq '');
        !           385:     if ($can_symlink) {
        !           386:         &print_and_log("Symlink created for /srv/www/conf to /etc/apache2");
        !           387:     } else {
        !           388:         &print_and_log("Symlink creation failed for /srv/www/conf to /etc/apache2.  You will need to perform this action from the command line");
        !           389:     }
        !           390:     &copy_apache2_conf_files();
        !           391:     &copy_sysconfig_apache2_file(); 
        !           392:     print_and_log("\n");
        !           393: }
        !           394: 
        !           395: ###############################################
        !           396: ##
        !           397: ## Modify uid.conf 
        !           398: ##
        !           399: ###############################################
        !           400: sub copy_apache2_conf_files {
        !           401:     print_and_log("Copying our uid.conf to /etc/apache2/uid.conf\n");
        !           402:     if (!-e "/etc/apache2/uid.conf.original") {
        !           403:         copy "/etc/apache2/uid.conf","/etc/apache2/uid.conf.original";
        !           404:     }
        !           405:     copy "$instdir/uid.conf","/etc/apache2/uid.conf";
        !           406:     chmod 0444,"/etc/apache2/uid.conf";
        !           407: }
        !           408: 
        !           409: ###############################################
        !           410: ##
        !           411: ## Modify /etc/sysconfig/apache2  
        !           412: ##
        !           413: ###############################################
        !           414: sub copy_sysconfig_apache2_file {
        !           415:     print_and_log("Copying our sysconfig/apache2 file to /etc/sysconfig/apache2\n");
        !           416:     if (!-e "/etc/sysconfig/apache2.original") {
        !           417:         copy "/etc/sysconfig/apache2","/etc/sysconfig/apache2.original";
        !           418:     }
        !           419:     copy "$instdir/sysconfig_apache2","/etc/sysconfig/apache2";
        !           420:     chmod 0444,"/etc/sysconfig/apache2";
        !           421: }
        !           422: 
        !           423: ###############################################
        !           424: ##
        !           425: ## Retrieve the latest LON-CAPA release
        !           426: ##
        !           427: ###############################################
        !           428: sub download_loncapa {
        !           429:     my ($lctarball) = @_;
        !           430:     if (! -e "$instdir/$lctarball") {
        !           431: 	print_and_log("Retrieving LON-CAPA source files from ".
        !           432: 		      "http://install.loncapa.org\n");
        !           433: 	system("wget http://install.loncapa.org/versions/$lctarball ".
        !           434: 	       "2>/dev/null 1>/dev/null");
        !           435: 	if (! -e "./$lctarball") {
        !           436: 	    die("Unable to retrieve LON-CAPA source files from\n".
        !           437: 		"http://install.loncapa.org/versions/$lctarball\n");
        !           438: 	}
        !           439: 	print_and_log("\n");
        !           440:     } else {
        !           441: 	print_and_log(<<"END");
        !           442: ------------------------------------------------------------------------
        !           443: 
        !           444: You seem to have a version of loncapa-current.tar.gz in $instdir.  
        !           445: This copy will be used and a new version will NOT be downloaded.  
        !           446: If you wish, you may download a new version by executing:
        !           447: 
        !           448: wget http://install.loncapa.org/versions/loncapa-fedora-current.tar.gz
        !           449: 
        !           450: ------------------------------------------------------------------------
        !           451: END
        !           452:     }
        !           453: 
        !           454:     ##
        !           455:     ## untar loncapa.tar.gz
        !           456:     ##
        !           457:     print_and_log("Extracting LON-CAPA source files\n");
        !           458:     writelog(`cd ~root; tar zxf $instdir/$lctarball`);
        !           459:     print_and_log("\n");
        !           460:     print <<"ENDMSG";
        !           461: All of the extra files seem to have been installed correctly.  It remains for 
        !           462: you to execute the following commands:
        !           463: 
        !           464: cd /root/loncapa-N.N     (N.N should correspond to a version number like '0.4')
        !           465: ./UPDATE
        !           466: 
        !           467: If you have any trouble, please see http://install.loncapa.org/ and 
        !           468: http://help.loncapa.org/.  
        !           469: ENDMSG
        !           470: }
        !           471: 
        !           472: close LOG;
        !           473: 

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