File:  [LON-CAPA] / doc / install / suse / install.pl
Revision 1.3: download - view: text, annotated - select for diffs
Fri Jul 29 22:21:58 2005 UTC (19 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_9_X, version_2_9_99_0, version_2_9_1, version_2_9_0, version_2_8_X, version_2_8_99_1, version_2_8_99_0, version_2_8_2, version_2_8_1, version_2_8_0, version_2_7_X, version_2_7_99_1, version_2_7_99_0, version_2_7_1, version_2_7_0, version_2_6_X, version_2_6_99_1, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_X, version_2_5_99_1, version_2_5_99_0, version_2_5_2, version_2_5_1, version_2_5_0, version_2_4_X, version_2_4_99_0, version_2_4_2, version_2_4_1, version_2_4_0, version_2_3_X, version_2_3_99_0, version_2_3_2, version_2_3_1, version_2_3_0, version_2_2_X, version_2_2_99_1, version_2_2_99_0, version_2_2_2, version_2_2_1, version_2_2_0, version_2_1_X, version_2_1_99_3, version_2_1_99_2, version_2_1_99_1, version_2_1_99_0, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_12_X, version_2_11_X, version_2_11_5_msu, version_2_11_5, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, version_2_0_X, version_2_0_99_1, version_2_0_2, version_2_0_1, version_2_0_0, version_1_99_3, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, bz6209-base, bz6209, HEAD, GCI_3, GCI_2, GCI_1, BZ4492-merge, BZ4492-feature_horizontal_radioresponse, BZ4492-feature_Support_horizontal_radioresponse, BZ4492-Support_horizontal_radioresponse
Make default options (create user www, install-httpd_conf) consistent with fedora/redhat. Location of httpd.conf in suse is /etc/httpd/ not /etc/httpd/conf. Create conf directory for loncapa_apache.conf and loncapa.conf.

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

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