Annotation of doc/install/linux/install.pl, revision 1.21

1.1       raeburn     1: #!/usr/bin/perl
                      2: # The LearningOnline Network 
                      3: # Pre-installation script for LON-CAPA
                      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 Term::ReadKey;
                     29: use DBI;
                     30: use LCLocalization::localize;
                     31: 
                     32: # ========================================================= The language handle
                     33: 
                     34: my %languages = (
                     35:                   ar => 'Arabic', 
                     36:                   de => 'German',
                     37:                   en => 'English',
                     38:                   es => 'Spanish (Castellan)',
                     39:                   fa => 'Persian',
                     40:                   fr => 'French', 
                     41:                   he => 'Hebrew', 
                     42:                   ja => 'Japanese',
                     43:                   pt => 'Portuguese',
                     44:                   ru => 'Russian',
                     45:                   tr => 'Turkish',
                     46:                   zh => 'Chinese Simplified'
                     47:                ); 
                     48: 
                     49: use vars qw($lh $lang);
                     50: $lang = 'en';
                     51: if (@ARGV > 0) {
                     52:     foreach my $poss (keys(%languages)) {
                     53:         if ($ARGV[0] eq $poss) {
                     54:             $lang = $ARGV[0]; 
                     55:         }
                     56:     }
                     57: }
                     58: 
                     59: &get_language_handle($lang);
                     60: 
                     61: # Check user has root privs
                     62: if (0 != $<) {
                     63:     print &mt('This script must be run as root.')."\n".
                     64:           &mt('Stopping execution.')."\n";
                     65:     exit;
                     66: }
                     67: 
                     68: 
                     69: # Globals: filehandle LOG is global.
                     70: if (!open(LOG,">>loncapa_install.log")) {
                     71:     print &mt('Unable to open log file.')."\n".
                     72:           &mt('Stopping execution.')."\n";
                     73:     exit;
                     74: } else {
1.21    ! raeburn    75:     print LOG '$Id: install.pl,v 1.20 2011/06/07 15:17:51 raeburn Exp $'."\n";
1.1       raeburn    76: }
                     77: 
                     78: #
1.2       raeburn    79: # Helper routines and routines to establish recommended actions
1.1       raeburn    80: #
                     81: 
                     82: sub get_language_handle {
                     83:     my @languages = @_;
                     84:     $lh=LCLocalization::localize->get_handle(@languages);
                     85: }
                     86: 
                     87: sub mt (@) {
                     88:     if ($lh) {
                     89:         if ($_[0] eq '') {
                     90:             if (wantarray) {
                     91:                 return @_;
                     92:             } else {
                     93:                 return $_[0];
                     94:             }
                     95:         } else {
                     96:             return $lh->maketext(@_);
                     97:         }
                     98:     } else {
                     99:         if (wantarray) {
                    100:             return @_;
                    101:         } else {
                    102:             return $_[0];
                    103:         }
                    104:     }
                    105: }
                    106: 
                    107: sub texthash {
                    108:     my (%hash) = @_;
                    109:     foreach (keys(%hash)) {
                    110:         $hash{$_}=&mt($hash{$_});
                    111:     }
                    112:     return %hash;
                    113: }
                    114: 
                    115: 
                    116: sub skip_if_nonempty {
                    117:     my ($string,$error)=@_;
                    118:     return if (! defined($error));
                    119:     chomp($string);chomp($error);
                    120:     if ($string ne '') {
                    121:         print_and_log("$error\n".&mt('Stopping execution.')."\n");
                    122:         return 1;
                    123:     }
                    124:     return;
                    125: }
                    126: 
                    127: sub writelog {
                    128:     while ($_ = shift) {
                    129:         chomp();
                    130:         print LOG "$_\n";
                    131:     }
                    132: }
                    133: 
                    134: sub print_and_log {
                    135:     while ($_=shift) {
                    136:         chomp();
                    137:         print "$_\n";
                    138:         print LOG "$_\n";
                    139:     }
                    140: }
                    141: 
                    142: sub get_user_selection {
                    143:     my ($defaultrun) = @_;
                    144:     my $do_action = 0;
                    145:     my $choice = <STDIN>;
                    146:     chomp($choice);
                    147:     $choice =~ s/(^\s+|\s+$)//g;
                    148:     my $yes = &mt('y');
                    149:     if ($defaultrun) {
                    150:         if (($choice eq '') || ($choice =~ /^\Q$yes\E/i)) {
                    151:             $do_action = 1;
                    152:         }
                    153:     } else {
                    154:         if ($choice =~ /^\Q$yes\E/i) {
                    155:             $do_action = 1;
                    156:         }
                    157:     }
                    158:     return $do_action;
                    159: }
                    160: 
                    161: sub get_distro {
                    162:     my ($distro,$gotprereqs,$updatecmd,$packagecmd,$installnow);
                    163:     $packagecmd = '/bin/rpm -q LONCAPA-prerequisites ';
                    164:     if (-e '/etc/redhat-release') {
                    165:         open(IN,'</etc/redhat-release');
                    166:         my $versionstring=<IN>;
                    167:         chomp($versionstring);
                    168:         close(IN);
                    169:         if ($versionstring =~ /^Red Hat Linux release ([\d\.]+) /) {
                    170:             my $version = $1;
                    171:             if ($version=~/^7\./) {
                    172:                 $distro='redhat7';
                    173:             } elsif ($version=~/^8\./) {
                    174:                 $distro='redhat8';
                    175:             } elsif ($version=~/^9/) {
                    176:                 $distro='redhat9';
                    177:             }
                    178:         } elsif ($versionstring =~ /Fedora( Core)? release ([\d\.]+) /) {
                    179:             my $version=$2;
                    180:             if ($version - int($version) > .9) {
                    181:                 $distro = 'fedora'.(int($version)+1);
                    182:             } else {
                    183:                 $distro = 'fedora'.int($version);
                    184:             }
                    185:             $updatecmd = 'yum install LONCAPA-prerequisites';
                    186:             $installnow = 'yum -y install LONCAPA-prerequisites';
                    187:         } elsif ($versionstring =~ /Red Hat Enterprise Linux [AE]S release ([\d\.]+) /) {
                    188:             $distro = 'rhes'.$1;
                    189:             $updatecmd = 'up2date -i LONCAPA-prerequisites';
                    190:         } elsif ($versionstring =~ /Red Hat Enterprise Linux Server release (\d+)/) {
                    191:             $distro = 'rhes'.$1;
                    192:             $updatecmd = 'yum install LONCAPA-prerequisites';
                    193:             $installnow = 'yum -y install LONCAPA-prerequisites';
1.21    ! raeburn   194:         } elsif ($versionstring =~ /CentOS(?:| Linux) release (\d+)/) {
1.1       raeburn   195:             $distro = 'centos'.$1;
                    196:             $updatecmd = 'yum install LONCAPA-prerequisites';
                    197:             $installnow = 'yum -y install LONCAPA-prerequisites';
1.11      raeburn   198:         } elsif ($versionstring =~ /Scientific Linux (SL )?release ([\d.]+) /) {
1.1       raeburn   199:             my $ver = $1;
                    200:             $ver =~ s/\.\d+$//;
                    201:             $distro = 'scientific'.$ver;
                    202:             $updatecmd = 'yum install LONCAPA-prerequisites';
                    203:             $installnow = 'yum -y install LONCAPA-prerequisites';
                    204:         } else {
                    205:             print &mt('Unable to interpret [_1] to determine system type.',
                    206:                       '/etc/redhat-release')."\n";
                    207:         }
                    208:     } elsif (-e '/etc/SuSE-release') {
                    209:         open(IN,'</etc/SuSE-release');
                    210:         my $versionstring=<IN>;
                    211:         chomp($versionstring);
                    212:         close(IN);
                    213:         if ($versionstring =~ /^SUSE LINUX Enterprise Server ([\d\.]+) /i) {
                    214:             $distro='sles'.$1;
                    215:             if ($1 >= 10) {
                    216:                 $updatecmd = 'zypper install LONCAPA-prerequisites';
                    217:             } else {
                    218:                 $updatecmd = 'yast -i LONCAPA-prerequisites';
                    219:             }
                    220:         } elsif ($versionstring =~ /^SuSE Linux ([\d\.]+) /i) {
                    221:             $distro = 'suse'.$1;
1.12      raeburn   222:             $updatecmd = 'yast -i LONCAPA-prerequisites';
1.1       raeburn   223:         } elsif ($versionstring =~ /^openSUSE ([\d\.]+) /i) {
                    224:             $distro = 'suse'.$1;
                    225:             if ($1 >= 10.3 ) {
                    226:                 $updatecmd = 'zypper install LONCAPA-prerequisites';
                    227:             } else {
                    228:                 $updatecmd = 'yast -i LONCAPA-prerequisites';
                    229:             }
                    230:         } else {
                    231:             print &mt('Unable to interpret [_1] to determine system type.',
                    232:                       '/etc/SuSE-release')."\n";
                    233:         }
                    234:     } elsif (-e '/etc/issue') {
                    235:         open(IN,'</etc/issue');
                    236:         my $versionstring=<IN>;
                    237:         chomp($versionstring);
                    238:         close(IN);
                    239:         $packagecmd = '/usr/bin/dpkg -l loncapa-prerequisites ';
                    240:         $updatecmd = 'apt-get install loncapa-prerequisites';
                    241:         if ($versionstring =~ /^Ubuntu (\d+)\.\d+/i) {
                    242:             $distro = 'ubuntu'.$1;
                    243:             $updatecmd = 'sudo apt-get install loncapa-prerequisites';
                    244:         } elsif ($versionstring =~ /^Debian\s+GNU\/Linux\s+(\d+)\.\d+/i) {
                    245:             $distro = 'debian'.$1;
                    246:         } elsif (-e '/etc/debian_version') {
                    247:             open(IN,'</etc/debian_version');
                    248:             my $version=<IN>;
                    249:             chomp($version);
                    250:             close(IN);
                    251:             if ($version =~ /^(\d+)\.\d+\.?\d*/) {
                    252:                 $distro='debian'.$1;
                    253:             } else {
                    254:                 print &mt('Unable to interpret [_1] to determine system type.',
                    255:                           '/etc/debian_version')."\n";
                    256:             }
                    257:         } else {
                    258:             print &mt('Unable to interpret [_1] to determine system type.',
                    259:                       '/etc/issue')."\n";
                    260:         }
                    261:     } elsif (-e '/etc/debian_version') {
                    262:         open(IN,'</etc/debian_version');
                    263:         my $version=<IN>;
                    264:         chomp($version);
                    265:         close(IN);
                    266:         if ($version =~  /^(\d+)\.\d+\.?\d*/) {
                    267:             $distro='debian'.$1;
                    268:             $packagecmd = '/usr/bin/dpkg -l loncapa-prerequisites ';
                    269:             $updatecmd = 'apt-get install loncapa-prerequisites';
                    270:         } else {
                    271:             print &mt('Unable to interpret [_1] to determine system type.',
                    272:                       '/etc/debian_version')."\n";
                    273:         }
                    274:     } else {
                    275:         print &mt('Unknown installation: expecting a debian, ubuntu, suse, sles, redhat, fedora or scientific linux system.')."\n";
                    276:     }
                    277:     return ($distro,$packagecmd,$updatecmd,$installnow);
                    278: }
                    279: 
                    280: sub check_prerequisites {
                    281:     my ($packagecmd,$distro) = @_;
                    282:     my $gotprereqs;
                    283:     if ($packagecmd ne '') {
                    284:         if (open(PIPE,"$packagecmd|")) {
                    285:             if ($distro =~ /^(debian|ubuntu)/) {
                    286:                 my @lines = <PIPE>;
                    287:                 chomp(@lines);
                    288:                 foreach my $line (@lines) {
                    289:                     if ($line =~ /^ii\s+loncapa-prerequisites\s+([\w\.]+)/) {
                    290:                         $gotprereqs = $1;
                    291:                     }
                    292:                 }
                    293:             } else {
                    294:                 my $line = <PIPE>;
                    295:                 chomp($line);
1.8       raeburn   296:                 if ($line =~ /^LONCAPA\-prerequisites\-([\d\-]+)\.(?:[.\w]+)$/) {
1.1       raeburn   297:                     $gotprereqs = $1;
                    298:                 }
                    299:             }
                    300:             close(PIPE);
                    301:         } else {
                    302:             print &mt('Error: could not determine if LONCAPA-prerequisites package is installed')."\n";
                    303:         }
                    304:     }
                    305:     return $gotprereqs;
                    306: }
                    307: 
1.6       raeburn   308: sub check_locale {
                    309:     my ($distro) = @_;
1.8       raeburn   310:     my ($fh,$langvar,$command);
                    311:     $langvar = 'LANG';
1.6       raeburn   312:     if ($distro =~ /^(ubuntu|debian)/) {
                    313:         if (!open($fh,"</etc/default/locale")) {
                    314:             print &mt('Failed to open: [_1], default locale not checked.',
                    315:                       '/etc/default/locale');
                    316:         }
1.8       raeburn   317:     } elsif ($distro =~ /^(suse|sles)/) {
                    318:         if (!open($fh,"</etc/sysconfig/language")) {
                    319:             print &mt('Failed to open: [_1], default locale not checked.',
                    320:                       '/etc/sysconfig/language');
                    321:         }
                    322:         $langvar = 'RC_LANG';
1.6       raeburn   323:     } else {
                    324:         if (!open($fh,"</etc/sysconfig/i18n")) {
                    325:             print &mt('Failed to open: [_1], default locale not checked.',
                    326:                       '/etc/sysconfig/i18n');
                    327:         }
                    328:     }
                    329:     my @data = <$fh>;
                    330:     chomp(@data);
                    331:     foreach my $item (@data) {
1.8       raeburn   332:         if ($item =~ /^\Q$langvar\E=\"([^\"]*)\"/) {
1.6       raeburn   333:             my $default = $1;
                    334:             if ($default ne 'en_US.UTF-8') {
                    335:                 if ($distro =~ /^debian/) {
                    336:                     $command = 'dpkg-reconfigure locales';
                    337:                 } elsif ($distro =~ /^ubuntu/) {
                    338:                     $command = 'sudo set-language-env -E'; 
1.7       raeburn   339:                 } elsif ($distro =~ /^(suse|sles)/) {
                    340:                     $command = 'yast language'; 
1.6       raeburn   341:                 } else {
                    342:                     $command = 'system-config-language';
                    343:                 }
                    344:             }
                    345:             last;
                    346:         }
                    347:     }
                    348:     close($fh);
                    349:     return $command;
                    350: }
                    351: 
1.1       raeburn   352: sub check_required {
                    353:     my ($instdir,$dsn) = @_;
                    354:     my ($distro,$packagecmd,$updatecmd,$installnow) = &get_distro();
                    355:     if ($distro eq '') {
                    356:         return;
                    357:     }
                    358:     my $gotprereqs = &check_prerequisites($packagecmd,$distro); 
                    359:     if ($gotprereqs eq '') {
1.6       raeburn   360:         return ($distro,$gotprereqs);
                    361:     }
                    362:     my $localecmd = &check_locale($distro);
                    363:     unless ($localecmd eq '') {
                    364:         return ($distro,$gotprereqs,$localecmd);
1.1       raeburn   365:     }
                    366:     my ($mysqlon,$mysqlsetup,$dbh,$has_pass,$has_lcdb,%recommended,$downloadstatus,
1.5       raeburn   367:         $filetouse,$production,$testing,$apachefw,$tostop);
1.1       raeburn   368:     my $wwwuid = &uid_of_www();
                    369:     my $wwwgid = getgrnam('www');
                    370:     if (($wwwuid eq '') || ($wwwgid eq '')) {
                    371:         $recommended{'wwwuser'} = 1;
                    372:     }
                    373:     unless( -e "/usr/local/sbin/pwauth") {
                    374:         $recommended{'pwauth'} = 1;
                    375:     }
                    376:     $mysqlon = &check_mysql_running($distro);
                    377:     if ($mysqlon) {
                    378:         my $mysql_has_wwwuser = &check_mysql_wwwuser();
                    379:         ($mysqlsetup,$has_pass,$dbh) = 
                    380:             &check_mysql_setup($instdir,$dsn);
                    381:         if ($mysqlsetup eq 'noroot') {
                    382:             $recommended{'mysqlperms'} = 1;
                    383:         } else {
                    384:             unless ($mysql_has_wwwuser) {
                    385:                 $recommended{'mysqlperms'} = 1;
                    386:             }
                    387:         }
                    388:         if ($dbh) {
                    389:             $has_lcdb = &check_loncapa_mysqldb($dbh);
                    390:         }
                    391:         unless ($has_lcdb) {
                    392:             $recommended{'mysql'} = 1;
                    393:         }
                    394:     }
1.5       raeburn   395:     ($recommended{'firewall'},$apachefw) = &chkfirewall($distro);
1.8       raeburn   396:     ($recommended{'runlevels'},$tostop) = &chkconfig($distro,$instdir);
1.1       raeburn   397:     $recommended{'apache'} = &chkapache($distro,$instdir);
                    398:     $recommended{'stopsrvcs'} = &chksrvcs($distro,$tostop);
                    399:     ($recommended{'download'},$downloadstatus,$filetouse,$production,$testing) 
                    400:         = &need_download();
1.6       raeburn   401:     return ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,
1.1       raeburn   402:             \%recommended,$dbh,$has_pass,$has_lcdb,$downloadstatus,
1.5       raeburn   403:             $filetouse,$production,$testing,$apachefw);
1.1       raeburn   404: }
                    405: 
                    406: sub check_mysql_running {
                    407:     my ($distro) = @_;
                    408:     my $mysqldaemon ='mysqld';
                    409:     if ($distro =~ /^(suse|sles|debian|ubuntu)/) {
                    410:         $mysqldaemon = 'mysql';
                    411:     }
1.6       raeburn   412:     my $process = 'mysqld_safe';
                    413:     my $proc_owner = 'root';
                    414:     if ($distro =~ /^ubuntu(\w+)/) {
                    415:         if ($1 >= 10) {
                    416:             $process = 'mysqld';
                    417:             $proc_owner = 'mysql';
                    418:         }
                    419:     }
                    420:     if (open(PIPE,"ps -ef |grep $process |grep -v grep 2>&1 |")) {
1.1       raeburn   421:         my $status = <PIPE>;
                    422:         close(PIPE);
                    423:         chomp($status);
1.6       raeburn   424:         if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
1.1       raeburn   425:             print_and_log(&mt('MySQL is running.')."\n");
                    426:             return 1;
                    427:         } else {
1.12      raeburn   428:             system("/etc/init.d/$mysqldaemon start >/dev/null 2>&1 "); 
1.1       raeburn   429:             print_and_log(&mt('Waiting for MySQL to start.')."\n");
                    430:             sleep 5;
1.12      raeburn   431:             if (open(PIPE,"ps -ef |grep $process |grep -v grep 2>&1 |")) {
                    432:                 $status = <PIPE>;
1.1       raeburn   433:                 close(PIPE);
                    434:                 chomp($status);
1.12      raeburn   435:                 if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
1.1       raeburn   436:                     print_and_log(&mt('MySQL is running.')."\n");
                    437:                     return 1;
                    438:                 } else {
1.12      raeburn   439:                     print_and_log(&mt('Still waiting for MySQL to start.')."\n");
                    440:                     sleep 5;
                    441:                     if (open(PIPE,"ps -ef |grep $process |grep -v grep 2>&1 |")) {
                    442:                         $status = <PIPE>;
                    443:                         close(PIPE);
                    444:                         chomp($status);
                    445:                         if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
                    446:                             print_and_log(&mt('MySQL is running.')."\n");
                    447:                             return 1;
                    448:                         } else {
                    449:                             print_and_log(&mt('Given up waiting for MySQL to start.')."\n"); 
                    450:                         }
                    451:                     }
1.1       raeburn   452:                 }
                    453:             }
                    454:         }
                    455:     } else {
                    456:         print &mt('Could not determine if MySQL is running.')."\n";
                    457:     }
                    458:     return;
                    459: }
                    460: 
                    461: sub chkconfig {
1.8       raeburn   462:     my ($distro,$instdir) = @_;
1.1       raeburn   463:     my (%needfix,%tostop);
                    464:     my $checker_bin = '/sbin/chkconfig';
1.6       raeburn   465:     my %daemon = (
                    466:                   mysql     => 'mysqld',
                    467:                   apache    => 'httpd',
                    468:                   cups      => 'cups',
                    469:                   ntp       => 'ntpd',
                    470:                   memcached => 'memcached',
                    471:     );
1.1       raeburn   472:     my @runlevels = qw/3 4 5/;
                    473:     my @norunlevels = qw/0 1 6/;
                    474:     if ($distro =~ /^(suse|sles)/) {
                    475:         @runlevels = qw/3 5/;
                    476:         @norunlevels = qw/0 2 1 6/;
1.6       raeburn   477:         $daemon{'mysql'} = 'mysql';
                    478:         $daemon{'apache'} = 'apache2';
1.8       raeburn   479:         $daemon{'ntp'}    = 'ntp';
1.1       raeburn   480:         if ($distro =~ /^(suse|sles)9/) {
1.6       raeburn   481:             $daemon{'apache'} = 'apache';
1.1       raeburn   482:         }
1.6       raeburn   483:     } elsif ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
                    484:         my $version = $1;
1.1       raeburn   485:         @runlevels = qw/2 3 4 5/;
                    486:         @norunlevels = qw/0 1 6/;
                    487:         $checker_bin = '/usr/sbin/sysv-rc-conf';
1.6       raeburn   488:         $daemon{'mysql'}  = 'mysql';
                    489:         $daemon{'apache'} = 'apache2';
                    490:         $daemon{'ntp'}    = 'ntp';
                    491:         if (($distro =~ /^ubuntu/) && ($version <= 8)) {
                    492:             $daemon{'cups'} = 'cupsys';
                    493:         }
1.1       raeburn   494:     }
                    495:     if (! -x $checker_bin) {
1.6       raeburn   496:         print &mt('Could not check runlevel status for MySQL or Apache')."\n";
1.1       raeburn   497:         return;
                    498:     }
                    499:     my $rlstr = join('',@runlevels);
                    500:     my $nrlstr = join('',@norunlevels);
1.6       raeburn   501:     foreach my $type ('apache','mysql','ntp','cups','memcached') {
                    502:         my $service = $daemon{$type};
1.19      raeburn   503:         if ($type eq 'ntp') {
                    504:             if ($distro =~ /^(?:fedora)(\d+)/) {
                    505:                 my $version = $1;
                    506:                 if ($version >= 15) {
                    507:                     if (!-l "/etc/systemd/system/multi-user.target.wants/ntpd.service") {
                    508:                         $needfix{$type} = 'systemctl enable ntpd.service';
                    509:                     }
                    510:                     next;
                    511:                 }
                    512:             }
                    513:         }
1.11      raeburn   514:         my $command = $checker_bin.' --list '.$service.' 2>/dev/null';
1.6       raeburn   515:         if ($type eq 'cups') { 
                    516:             if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
                    517:                 my $version = $1;
                    518:                 if (($distro =~ /^ubuntu/) && ($version <= 8)) {
1.11      raeburn   519:                     $command = $checker_bin.' --list cupsys 2>/dev/null';
1.6       raeburn   520:                 }
                    521:             }
1.1       raeburn   522:         }
                    523:         my $results = `$command`;
                    524:         my $tofix;
                    525:         if ($results eq '') {
1.6       raeburn   526:             if (($type eq 'apache') || ($type eq 'mysql') || ($type eq 'ntp')) {
1.1       raeburn   527:                 if ($distro  =~ /^(debian|ubuntu)/) {
1.6       raeburn   528:                     $tofix = "update-rc.d $type defaults";
1.1       raeburn   529:                 } else {
                    530:                     $tofix = "$checker_bin --add $service\n";
                    531:                 }
                    532:             }
                    533:         } else {
                    534:             my %curr_runlevels;
                    535:             for (my $rl=0; $rl<=6; $rl++) {
                    536:                 if ($results =~ /$rl:on/) { $curr_runlevels{$rl}++; }
                    537:             }
1.5       raeburn   538:             if (($type eq 'apache') || ($type eq 'mysql') || ($type eq 'ntp')) {
1.1       raeburn   539:                 my $warning;
                    540:                 foreach my $rl (@runlevels) {
                    541:                     if (!exists($curr_runlevels{$rl})) {
                    542:                         $warning = 1;
                    543:                     }
                    544:                 }
                    545:                 if ($warning) {
                    546:                     $tofix = "$checker_bin --level $rlstr $service on\n";
                    547:                 }
                    548:             } elsif (keys(%curr_runlevels) > 0) {
                    549:                 $tostop{$type} = 1;
                    550:             }
                    551:         }
                    552:         if ($tofix) {
                    553:             $needfix{$type} = $tofix;
1.5       raeburn   554:         }
1.1       raeburn   555:     }
                    556:     if ($distro =~ /^(suse|sles)([\d\.]+)$/) {
                    557:         my $name = $1;
                    558:         my $version = $2;
                    559:         my ($major,$minor);
                    560:         if ($name eq 'suse') {
                    561:             ($major,$minor) = split(/\./,$version);
                    562:         } else {
                    563:             $major = $version;
                    564:         }
                    565:         if ($major > 10) {
1.8       raeburn   566:             if (&check_SuSEfirewall2_setup($instdir)) {
                    567:                 $needfix{'insserv'} = 1;
                    568:             }
1.1       raeburn   569:         }
                    570:     }
                    571:     return (\%needfix,\%tostop);
                    572: }
                    573: 
                    574: sub chkfirewall {
1.5       raeburn   575:     my ($distro) = @_;
1.1       raeburn   576:     my $configfirewall = 1;
                    577:     my %ports = (
                    578:                     http  =>  80,
                    579:                     https => 443,
                    580:                 );
1.5       raeburn   581:     my %activefw;
1.1       raeburn   582:     if (&firewall_is_active()) {
                    583:         my $iptables = &get_pathto_iptables();
                    584:         if ($iptables eq '') {
                    585:             print &mt('Firewall not checked as path to iptables not determined.')."\n";
                    586:         } else {
1.5       raeburn   587:             my @fwchains = &get_fw_chains($iptables,$distro);
1.1       raeburn   588:             if (@fwchains) {
                    589:                 foreach my $service ('http','https') {
                    590:                     foreach my $fwchain (@fwchains) {
                    591:                         if (&firewall_is_port_open($iptables,$fwchain,$ports{$service})) {
                    592:                             $activefw{$service} = 1;
                    593:                             last;
                    594:                         }
                    595:                     }
                    596:                 }
                    597:                 if ($activefw{'http'}) {
                    598:                     $configfirewall = 0;
                    599:                 }
                    600:             } else {
                    601:                 print &mt('Firewall not checked as iptables Chains not identified.')."\n";
                    602:             }
                    603:         }
                    604:     } else {
                    605:         print &mt('Firewall not enabled.')."\n";
                    606:     }
1.5       raeburn   607:     return ($configfirewall,\%activefw);
1.1       raeburn   608: }
                    609: 
                    610: sub chkapache {
                    611:     my ($distro,$instdir) = @_;
                    612:     my $fixapache = 1;
                    613:     if ($distro =~ /^(debian|ubuntu)/) {
1.17      raeburn   614:         if (!-e "$instdir/debian-ubuntu/loncapa") {
1.1       raeburn   615:             $fixapache = 0;
                    616:             print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n"; 
1.17      raeburn   617:         } elsif ((-e "/etc/apache2/sites-available/loncapa") && (-e "$instdir/debian-ubuntu/loncapa")) {
                    618:             if (open(PIPE, "diff --brief $instdir/debian-ubuntu/loncapa /etc/apache2/sites-available/loncapa |")) {
1.1       raeburn   619:                 my $diffres = <PIPE>;
                    620:                 close(PIPE);
                    621:                 chomp($diffres);
                    622:                 unless ($diffres) {
                    623:                     $fixapache = 0;
                    624:                 }
                    625:             }
                    626:         }
1.6       raeburn   627:         if (!$fixapache) {
                    628:             foreach my $module ('headers.load','expires.load') {
                    629:                 unless (-l "/etc/apache2/mods-enabled/$module") {
                    630:                     $fixapache = 1;
                    631:                 }
                    632:             }
                    633:         }
1.1       raeburn   634:     } elsif ($distro =~ /^(?:suse|sles)([\d\.]+)$/) {
                    635:         my $apache = 'apache';
                    636:         if ($1 >= 10) {
1.8       raeburn   637:             $apache = 'apache2';
1.1       raeburn   638:         }
1.9       raeburn   639:         if (!-e "$instdir/sles-suse/default-server.conf") {
1.1       raeburn   640:             $fixapache = 0;
                    641:             print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.9       raeburn   642:         } elsif ((-e "/etc/$apache/default-server.conf") && (-e "$instdir/sles-suse/default-server.conf")) {
                    643:             if (open(PIPE, "diff --brief $instdir/sles-suse/default-server.conf /etc/$apache/default-server.conf |")) {
                    644:                 my $diffres = <PIPE>;
                    645:                 close(PIPE);
                    646:                 chomp($diffres);
                    647:                 unless ($diffres) {
                    648:                     $fixapache = 0;
                    649:                 }
                    650:             }
                    651:         }
                    652:     } elsif ($distro eq 'rhes4') {
                    653:         if (!-e "$instdir/rhes4/httpd.conf") {
                    654:             $fixapache = 0;
                    655:             print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
                    656:         } elsif ((-e "/etc/httpd/conf/httpd.conf") && (-e "$instdir/rhes4/httpd.conf")) {
                    657:             if (open(PIPE, "diff --brief $instdir/rhes4/httpd.conf /etc/httpd/conf/httpd.conf |")) {
1.1       raeburn   658:                 my $diffres = <PIPE>;
                    659:                 close(PIPE);
                    660:                 chomp($diffres);
                    661:                 unless ($diffres) {
                    662:                     $fixapache = 0;
                    663:                 }
                    664:             }
                    665:         }
                    666:     } else {
1.14      raeburn   667:         my $configfile = 'httpd.conf';
                    668:         if ($distro =~ /^(?:centos|rhes|scientific)(\d+)$/) {
                    669:             if ($1 > 5) {
                    670:                 $configfile = 'new/httpd.conf';
                    671:             }
                    672:         } elsif ($distro =~ /^fedora(\d+)$/) {
                    673:             if ($1 > 10) {
1.15      raeburn   674:                 $configfile = 'new/httpd.conf';
1.14      raeburn   675:             }
                    676:         }
                    677:         if (!-e "$instdir/centos-rhes-fedora-sl/$configfile") {
1.1       raeburn   678:             $fixapache = 0;
                    679:             print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.14      raeburn   680:         } elsif ((-e "/etc/httpd/conf/httpd.conf") && (-e "$instdir/centos-rhes-fedora-sl/$configfile")) {
                    681:             if (open(PIPE, "diff --brief $instdir/centos-rhes-fedora-sl/$configfile /etc/httpd/conf/httpd.conf |")) {
1.1       raeburn   682:                 my $diffres = <PIPE>;
                    683:                 close(PIPE);
                    684:                 chomp($diffres);
                    685:                 unless ($diffres) {
                    686:                     $fixapache = 0;
                    687:                 }
                    688:             }
                    689:         }
                    690:     }
                    691:     return $fixapache;
                    692: }
                    693: 
                    694: sub chksrvcs {
                    695:     my ($distro,$tostop) = @_;
                    696:     my %stopsrvcs;
                    697:     if (ref($tostop) eq 'HASH') {
                    698:         %stopsrvcs = %{$tostop};
                    699:     }
1.6       raeburn   700:     foreach my $service ('cups','memcached') {
1.1       raeburn   701:         next if (exists($stopsrvcs{$service}));
                    702:         my $daemon = $service;
                    703:         if ($service eq 'cups') {
                    704:             $daemon = 'cupsd';
                    705:         }
                    706:         my $cmd = "ps -ef |grep '$daemon' |grep -v grep";
                    707:         if (open(PIPE,'-|',$cmd)) {
                    708:             my $daemonrunning = <PIPE>;
                    709:             chomp($daemonrunning);
                    710:             close(PIPE);
                    711:             if ($daemonrunning) {
1.12      raeburn   712:                 if ($service eq 'memcached') {
1.16      raeburn   713:                     my $cmd = '/usr/bin/memcached';
                    714:                     if ($distro =~ /^(suse|sles)/) {
                    715:                         $cmd = '/usr/sbin/memcached';
                    716:                     }
1.12      raeburn   717:                     unless ($daemonrunning =~ m{^www[^/]+\Q$cmd -m 400 -v\E$}) {
1.10      raeburn   718:                         $stopsrvcs{$service} = 1;
                    719:                     }
                    720:                 } else {
                    721:                     $stopsrvcs{$service} = 1;
                    722:                 }
1.1       raeburn   723:             }
                    724:         }
1.10      raeburn   725:     }
1.1       raeburn   726:     return \%stopsrvcs;
                    727: }
                    728: 
                    729: sub need_download {
                    730:     my $needs_download = 1;
                    731:     my ($production,$testing,$stdsizes) = &download_versionslist();
                    732:     my ($rootdir,$localcurrent,$localtesting,%tarball,%localsize,%bymodtime,
                    733:         %bysize,$filetouse,$downloadstatus);
                    734:     $rootdir = '/root';
                    735:     if (opendir(my $dir,"$rootdir")) {
                    736:         my (@lcdownloads,$version);
                    737:         foreach my $file (readdir($dir)) {
                    738:             if ($file =~ /^loncapa\-([\w\-.]+)\.tar\.gz$/) {
                    739:                 $version = $1;
                    740:             } else {
                    741:                 next;
                    742:             }
                    743:             if (ref($stdsizes) eq 'HASH') {
                    744:                 if ($version eq 'current') {
                    745:                     my @stats = stat("$rootdir/$file");
                    746:                     $localcurrent = $stats[7];
1.4       raeburn   747:                     if ($localcurrent == $stdsizes->{$production}) {
1.1       raeburn   748:                         $needs_download = 0;
                    749:                         $filetouse = $file;
                    750:                     }
                    751:                 } elsif ($version eq 'testing') {
                    752:                     my @stats = stat("$rootdir/$file");
                    753:                     $localtesting = $stats[7];
1.4       raeburn   754:                     if ($localtesting == $stdsizes->{$testing}) {
1.1       raeburn   755:                         $needs_download = 0;
                    756:                         $filetouse = $file;
                    757:                     }
                    758:                 }
                    759:             }
                    760:             $tarball{$version} = $file;
                    761:             push(@lcdownloads,$version);
                    762:         }
                    763:         if ($needs_download) {
                    764:             if (@lcdownloads > 0) {
                    765:                 foreach my $version (@lcdownloads) {
                    766:                     my @stats = stat("$rootdir/$tarball{$version}");
                    767:                     my $mtime = $stats[9];
                    768:                     $localsize{$version} = $stats[7];
                    769:                     if ($mtime) {
                    770:                         push(@{$bymodtime{$mtime}},$version);
                    771:                     }
                    772:                     if ($localsize{$version}) {
                    773:                         push(@{$bysize{$localsize{$version}}},$version);
                    774:                     }
                    775:                 }
                    776:                 if ($testing) {
                    777:                     if (exists($localsize{$testing})) {
                    778:                         if ($stdsizes->{$testing} == $localsize{$testing}) {
                    779:                             $needs_download = 0;
                    780:                             $filetouse = 'loncapa-'.$testing.'.tar.gz';
                    781:                         }
                    782:                     }
                    783:                 }
                    784:                 if ($needs_download) { 
                    785:                     if ($production) {
                    786:                         if (exists($localsize{$production})) {
                    787:                             if ($stdsizes->{$production} == $localsize{$production}) {
                    788:                                 $needs_download = 0;
                    789:                                 $filetouse = 'loncapa-'.$production.'.tar.gz';
                    790:                             }
                    791:                         }
                    792:                     }
                    793:                 }
                    794:                 if ($needs_download) {
                    795:                     my @sorted = sort { $b <=> $a } keys(%bymodtime);
                    796:                     my $newest = $sorted[0];
                    797:                     if (ref($bymodtime{$newest}) eq 'ARRAY') {
                    798:                         $downloadstatus = 
                    799:                               "Latest LON-CAPA source download in $rootdir is: ".
                    800:                               join(',',@{$bymodtime{$newest}})." (downloaded ".
                    801:                               localtime($newest).")\n";
                    802:                     }
                    803:                 } else {
                    804:                     $downloadstatus = 
                    805:                         "The $rootdir directory already contains the latest LON-CAPA version:".
                    806:                         "\n".$filetouse."\n"."which can be used for installation.\n";
                    807:                 }
                    808:             } else {
                    809:                 $downloadstatus = "The $rootdir directory does not appear to contain any downloaded LON-CAPA source code files which can be used for installation.\n";
                    810:             }
                    811:         }
                    812:     } else {
                    813:         $downloadstatus = "Could not open $rootdir directory to look for existing downloads of LON-CAPA source code.\n";
                    814:     }
                    815:     return ($needs_download,$downloadstatus,$filetouse,$production,$testing);
                    816: }
                    817: 
                    818: sub check_mysql_setup {
                    819:     my ($instdir,$dsn) = @_;
                    820:     my ($mysqlsetup,$has_pass);
                    821:     my $dbh = DBI->connect($dsn,'root','',{'PrintError'=>0});
                    822:     if ($dbh) {
                    823:         $mysqlsetup = 'noroot'; 
                    824:     } elsif ($DBI::err =~ /1045/) {
                    825:         $has_pass = 1;
                    826:     }
                    827:     if ($has_pass) {
                    828:         print &mt('You have already set a root password for the MySQL database.')."\n";
                    829:         my $currpass = &get_mysql_password(&mt('Please enter the password now'));
                    830:         $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
                    831:         if ($dbh) {
                    832:             $mysqlsetup = 'rootok';
                    833:             print_and_log(&mt('Password accepted.')."\n");
                    834:         } else {
                    835:             $mysqlsetup = 'rootfail';
                    836:             print_and_log(&mt('Problem accessing MySQL.')."\n");
                    837:             if ($DBI::err =~ /1045/) {
                    838:                 print_and_log(&mt('Perhaps the password was incorrect?')."\n");
                    839:                 print &mt('Try again?').' ';
                    840:                 $currpass = &get_mysql_password(&mt('Re-enter password now')); 
                    841:                 $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
                    842:                 if ($dbh) {
                    843:                     $mysqlsetup = 'rootok';
                    844:                     print_and_log(&mt('Password accepted.')."\n");
                    845:                 } else {
                    846:                     if ($DBI::err =~ /1045/) {
                    847:                         print_and_log(&mt('Incorrect password.')."\n");
                    848:                     }
                    849:                 }
                    850:             }
                    851:         }
                    852:      } elsif ($mysqlsetup ne 'noroot') {
                    853:         print_and_log(&mt('Problem accessing MySQL.')."\n");
                    854:         $mysqlsetup = 'rootfail';
                    855:     }
                    856:     return ($mysqlsetup,$has_pass,$dbh);
                    857: }
                    858: 
                    859: sub check_mysql_wwwuser {
                    860:     my $mysql_wwwuser;
1.12      raeburn   861:     my $dbhn = DBI->connect("DBI:mysql:database=information_schema",'www','localhostkey',
                    862:                             {PrintError => +0}) || return;
1.1       raeburn   863:     if ($dbhn) {
                    864:         $mysql_wwwuser = 1;
                    865:         $dbhn->disconnect;
                    866:     }
                    867:     return $mysql_wwwuser;
                    868: }
                    869: 
                    870: sub check_loncapa_mysqldb {
                    871:     my ($dbh) = @_;
                    872:     my $has_lcdb;
                    873:     if (ref($dbh)) {
                    874:         my $sth = $dbh->prepare("SHOW DATABASES");
                    875:         $sth->execute();
                    876:         while (my $dbname = $sth->fetchrow_array) {
                    877:             if ($dbname eq 'loncapa') {
                    878:                 $has_lcdb = 1;
                    879:                 last;
                    880:             }
                    881:         }
                    882:         $sth->finish();
                    883:     }
                    884:     return $has_lcdb;
                    885: }
                    886: 
                    887: sub get_pathto_iptables {
                    888:     my $iptables;
                    889:     if (-e '/sbin/iptables') {
                    890:         $iptables = '/sbin/iptables';
                    891:     } elsif (-e '/usr/sbin/iptables') {
                    892:         $iptables = '/usr/sbin/iptables';
                    893:     } else {
                    894:         print &mt('Unable to find iptables command.')."\n";
                    895:     }
                    896:     return $iptables;
                    897: }
                    898: 
                    899: sub firewall_is_active {
                    900:     if (-e '/proc/net/ip_tables_names') {
                    901:         return 1;
                    902:     } else {
                    903:         return 0;
                    904:     }
                    905: }
                    906: 
                    907: sub get_fw_chains {
1.5       raeburn   908:     my ($iptables,$distro) = @_;
1.1       raeburn   909:     my @fw_chains;
                    910:     my $suse_config = "/etc/sysconfig/SuSEfirewall2";
                    911:     my $ubuntu_config = "/etc/ufw/ufw.conf";
                    912:     if (-e $suse_config) {
                    913:         push(@fw_chains,'input_ext');
                    914:     } else {
                    915:         my @posschains;
                    916:         if (-e $ubuntu_config) {
                    917:             @posschains = ('ufw-user-input','INPUT');
1.5       raeburn   918:         } elsif ($distro =~ /^debian5/) {
                    919:             @posschains = ('INPUT');
1.1       raeburn   920:         } else {
                    921:             @posschains = ('RH-Firewall-1-INPUT','INPUT');
                    922:             if (!-e '/etc/sysconfig/iptables') {
                    923:                 if (!-e '/var/lib/iptables') {
                    924:                     print &mt('Unable to find iptables file containing static definitions.')."\n";
                    925:                 }
                    926:                 push(@fw_chains,'RH-Firewall-1-INPUT');
                    927:             }
                    928:         }
                    929:         if ($iptables eq '') {
                    930:             $iptables = &get_pathto_iptables();
                    931:         }
                    932:         my %counts;
                    933:         if (open(PIPE,"$iptables -L -n |")) {
                    934:             while(<PIPE>) {
                    935:                 foreach my $chain (@posschains) {
                    936:                     if (/(\Q$chain\E)/) {
                    937:                         $counts{$1} ++;
                    938:                     }
                    939:                 }
                    940:             }
                    941:             close(PIPE);
                    942:         }
                    943:         foreach my $fw_chain (@posschains) {
                    944:             if ($counts{$fw_chain}) {
                    945:                 unless(grep(/^\Q$fw_chain\E$/,@fw_chains)) {
                    946:                     push(@fw_chains,$fw_chain);
                    947:                 }
                    948:             }
                    949:         }
                    950:     }
                    951:     return @fw_chains;
                    952: }
                    953: 
                    954: sub firewall_is_port_open {
                    955:     my ($iptables,$fw_chain,$port) = @_;
                    956:     # returns 1 if the firewall port is open, 0 if not.
                    957:     #
                    958:     # check if firewall is active or installed
                    959:     return if (! &firewall_is_active());
                    960:     my $count = 0;
                    961:     if (open(PIPE,"$iptables -L $fw_chain -n |")) {
                    962:         while(<PIPE>) {
                    963:             if (/tcp dpt\:\Q$port\E/) {
                    964:                 $count ++;
                    965:                 last;
                    966:             }
                    967:         }
                    968:         close(PIPE);
                    969:     } else {
                    970:         print &mt('Firewall status not checked: unable to run [_1].','iptables -L')."\n";
                    971:     }
                    972:     return $count;
                    973: }
                    974: 
                    975: sub get_mysql_password {
                    976:     my ($prompt) = @_;
                    977:     local $| = 1;
                    978:     print $prompt.': ';
                    979:     my $newpasswd = '';
                    980:     ReadMode 'raw';
                    981:     my $key;
                    982:     while(ord($key = ReadKey(0)) != 10) {
                    983:         if(ord($key) == 127 || ord($key) == 8) {
                    984:             chop($newpasswd);
                    985:             print "\b \b";
                    986:         } elsif(!ord($key) < 32) {
                    987:             $newpasswd .= $key;
                    988:             print '*';
                    989:         }
                    990:     }
                    991:     ReadMode 'normal';
                    992:     print "\n";
                    993:     return $newpasswd;
                    994: }
                    995: 
                    996: sub check_SuSEfirewall2_setup {
                    997:     my ($instdir) = @_;
                    998:     my $need_override = 1;
1.9       raeburn   999:     if ((-e "/etc/insserv/overrides/SuSEfirewall2_setup") && (-e "$instdir/sles-suse/SuSEfirewall2_setup")) {
                   1000:         if (open(PIPE, "diff --brief $instdir/sles-suse/SuSEfirewall2_setup /etc/insserv/overrides/SuSEfirewall2_setup  |")) {
1.1       raeburn  1001:             my $diffres = <PIPE>;
                   1002:             close(PIPE);
                   1003:             chomp($diffres);
                   1004:             unless ($diffres) {
                   1005:                 $need_override = 0;
                   1006:             }
                   1007:         }
                   1008:     }
                   1009:     return $need_override;
                   1010: }
                   1011: 
                   1012: sub download_versionslist {
                   1013:     my ($production,$testing,%sizes);
                   1014:     if (-e "latest.txt") {
                   1015:          unlink("latest.txt");
                   1016:     }
                   1017:     my $rtncode = system("wget http://install.loncapa.org/versions/latest.txt ".
                   1018:                          "> /dev/null 2>&1");
                   1019:     if (!$rtncode) {
                   1020:         if (open(my $fh,"<latest.txt")) {
                   1021:             my @info = <$fh>;
                   1022:             close($fh);
                   1023:             foreach my $line (@info) {
                   1024:                 chomp();
                   1025:                 if ($line =~ /^\QLATEST-IS: \E([\w\-.]+):(\d+)$/) {
                   1026:                      $production = $1;
                   1027:                      $sizes{$1} = $2;
                   1028:                 } elsif ($line =~ /^LATEST-TESTING-IS: \E([\w\-.]+):(\d+)$/) {
                   1029:                      $testing = $1;
                   1030:                      $sizes{$1} = $2;
                   1031:                 }
                   1032:             }
                   1033:         }
                   1034:     }
                   1035:     return ($production,$testing,\%sizes);
                   1036: }
                   1037: 
                   1038: #
                   1039: # End helper routines.
                   1040: # Main script starts here
                   1041: #
                   1042: 
                   1043: print "
                   1044: ********************************************************************
                   1045: 
                   1046:                     ".&mt('Welcome to LON-CAPA')."
                   1047: 
                   1048: ".&mt('This script will configure your system for installation of LON-CAPA.')."
                   1049: 
                   1050: ********************************************************************
                   1051: 
                   1052: ".&mt('The following actions are available:')."
                   1053: 
1.4       raeburn  1054: ".&mt('1.')." ".&mt('Create the www user/group.')."
1.1       raeburn  1055:    ".&mt('This is the user/group ownership under which Apache child processes run.')."
                   1056:    ".&mt('It also owns most directories within the /home/httpd directory.')." 
                   1057:    ".&mt('This directory is where most LON-CAPA files and directories are stored.')."
1.4       raeburn  1058: ".&mt('2.')." ".&mt('Install the package LON-CAPA uses to authenticate users.')."
                   1059: ".&mt('3.')." ".&mt('Set-up the MySQL database.')."
                   1060: ".&mt('4.')." ".&mt('Set-up MySQL permissions.')."
                   1061: ".&mt('5.')." ".&mt('Configure Apache web server.')."
                   1062: ".&mt('6.')." ".&mt('Configure start-up of services.')."
                   1063: ".&mt('7.')." ".&mt('Check firewall settings.')."
                   1064: ".&mt('8.')." ".&mt('Stop services not used by LON-CAPA,')."
1.1       raeburn  1065:    ".&mt('i.e., services for a print server: [_1] daemon.',"'cups'")."
1.4       raeburn  1066: ".&mt('9.')." ".&mt('Download LON-CAPA source code in readiness for installation.')."
1.1       raeburn  1067: 
                   1068: ".&mt('Typically, you will run this script only once, when you first install LON-CAPA.')." 
                   1069: 
                   1070: ".&mt('The script will analyze your system to determine which actions are recommended.')."
                   1071: ".&mt('The script will then prompt you to choose the actions you would like taken.')."
                   1072: 
                   1073: ".&mt('For each the recommended action will be selected if you hit Enter/Return.')."
                   1074: ".&mt('To override the default, type the lower case option from the two options listed.')."
                   1075: ".&mt('So, if the default is "yes", ~[Y/n~] will be shown -- type n to override.')."
                   1076: ".&mt('Whereas if the default is "no", ~[y/N~] will be shown -- type y to override.')." 
                   1077: 
                   1078: ".&mt('To accept the default, simply hit Enter/Return on your keyboard.')."
                   1079: ".&mt('Otherwise type: y or n then hit the Enter/Return key.')."
                   1080: 
                   1081: ".&mt('Once a choice has been entered for all nine actions, required changes will be made.')."
                   1082: ".&mt('Feedback will be displayed on screen, and also stored in: [_1].','loncapa_install.log')."
                   1083: 
                   1084: ".&mt('Continue? ~[Y/n~] ');
                   1085: 
                   1086: my $go_on = &get_user_selection(1);
                   1087: if (!$go_on) {
                   1088:     exit;
                   1089: }
                   1090: 
                   1091: my $instdir = `pwd`;
                   1092: chomp($instdir);
                   1093: 
                   1094: my %callsub;
                   1095: my @actions = ('wwwuser','pwauth','mysql','mysqlperms','apache',
                   1096:                'runlevels','firewall','stopsrvcs','download');
                   1097: my %prompts = &texthash( 
                   1098:     wwwuser    => "Create the 'www' user?",
                   1099:     pwauth     => 'Install the package LON-CAPA uses to authenticate users?',
                   1100:     mysql      => 'Set-up the MySQL database?',
                   1101:     mysqlperms => 'Set-up MySQL permissions?',
                   1102:     apache     => 'Configure Apache web server?',
                   1103:     runlevels  => 'Set overrides for start-up order of services?',
                   1104:     firewall   => 'Configure firewall settings for Apache',
                   1105:     stopsrvcs  => 'Stop extra services not required on a LON-CAPA server?',
                   1106:     download   => 'Download LON-CAPA source code in readiness for installation?',
                   1107: );
                   1108: 
                   1109: print "\n".&mt('Checking system status ...')."\n";
                   1110: 
                   1111: my $dsn = "DBI:mysql:database=mysql";
1.6       raeburn  1112: my ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,$recommended,
1.1       raeburn  1113:     $dbh,$has_pass,$has_lcdb,$downloadstatus,$filetouse,$production,
1.5       raeburn  1114:     $testing,$apachefw) = &check_required($instdir,$dsn);
1.1       raeburn  1115: if ($distro eq '') {
                   1116:     print "\n".&mt('Linux distribution could not be verified as a supported distribution.')."\n".
                   1117:           &mt('The following are supported: [_1].',
                   1118:               'CentOS, RedHat Enterprise, Fedora, Scientific Linux, '.
                   1119:               'openSuSE, SLES, Ubuntu LTS, Debian')."\n\n".
                   1120:           &mt('Stopping execution.')."\n";
                   1121:     exit;
                   1122: }
1.6       raeburn  1123: if ($localecmd ne '') {
                   1124:     print "\n".&mt('Although the LON-CAPA application itself is localized for a number of different languages, the default locale language for the Linux OS on which it runs should be US English.')."\n";
                   1125:     print "\n".&mt('Run the following command from the command line to set the default language for your OS, and then run this LON-CAPA installation set-up script again.')."\n\n".
                   1126:     $localecmd."\n\n".
                   1127:     &mt('Stopping execution.')."\n";
                   1128:     exit;
                   1129: }
1.1       raeburn  1130: if (!$gotprereqs) {
1.12      raeburn  1131:     print "\n".&mt('The LONCAPA-prerequisites package is not installed.')."\n".
1.1       raeburn  1132:           &mt('The following command can be used to install the package (and dependencies):')."\n\n".
                   1133:           $updatecmd."\n\n";
                   1134:     if ($installnow eq '') {
                   1135:         print &mt('Stopping execution.')."\n";
                   1136:         exit;
                   1137:     } else {
                   1138:         print &mt('Run command? ~[Y/n~]');
                   1139:         my $install_prereq = &get_user_selection(1);
                   1140:         if ($install_prereq) {
                   1141:             if (open(PIPE,'|-',$installnow)) {
                   1142:                 close(PIPE);
                   1143:                 $gotprereqs = &check_prerequisites($packagecmd,$distro);
                   1144:                 if (!$gotprereqs) {
1.12      raeburn  1145:                     print &mt('The LONCAPA-prerequisites package is not installed.')."\n".
1.1       raeburn  1146:                           &mt('Stopping execution.')."\n";
                   1147:                     exit;
                   1148:                 } else {
1.6       raeburn  1149:                     ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,
1.1       raeburn  1150:                      $recommended,$dbh,$has_pass,$has_lcdb,$downloadstatus,
1.5       raeburn  1151:                      $filetouse,$production,$testing,$apachefw) = 
                   1152:                      &check_required($instdir,$dsn);
1.1       raeburn  1153:                 }
                   1154:             } else {
1.12      raeburn  1155:                 print &mt('Failed to run command to install LONCAPA-prerequisites')."\n";
1.1       raeburn  1156:                 exit;
                   1157:             }
                   1158:         } else {
                   1159:             print &mt('Stopping execution.')."\n";
                   1160:             exit;
                   1161:         }
                   1162:     }
                   1163: }
                   1164: unless (ref($recommended) eq 'HASH') {
                   1165:     print "\n".&mt('An error occurred determining which actions are recommended.')."\n\n".
                   1166:           &mt('Stopping execution.')."\n";
                   1167:     exit;
                   1168: }
                   1169: 
                   1170: print "\n";
                   1171: my $num = 0;
                   1172: foreach my $action (@actions) {
                   1173:     $num ++;
                   1174:     my ($yesno,$defaultrun);
                   1175:     if (ref($recommended) eq 'HASH') {
1.4       raeburn  1176:         if (($action eq 'runlevels') || ($action eq 'stopsrvcs')) {
1.1       raeburn  1177:             $yesno = '[y/N]';
                   1178:             if (ref($recommended->{$action}) eq 'HASH') {
                   1179:                 if (keys(%{$recommended->{$action}}) > 0) {
                   1180:                     $yesno = &mt('~[Y/n~]');
                   1181:                     $defaultrun = 1;
                   1182:                 }
                   1183:             }
                   1184:         } else {
                   1185:             if ($action eq 'download') {
                   1186:                 if ($downloadstatus) {
                   1187:                     print "\n$downloadstatus\n";
                   1188:                 }
                   1189:             }
                   1190:             if ($recommended->{$action}) {
                   1191:                 $yesno = mt('~[Y/n~]');
                   1192:                 $defaultrun = 1;
                   1193:             } else {
                   1194:                 $yesno = &mt('~[y/N~]');
                   1195:             }
                   1196:         }
                   1197:         print $num.'. '.$prompts{$action}." $yesno ";
                   1198:         $callsub{$action} = &get_user_selection($defaultrun);
                   1199:     }
                   1200: }
                   1201: 
                   1202: my $lctarball = 'loncapa-current.tar.gz';
                   1203: my $sourcetarball = $lctarball;
                   1204: if ($callsub{'download'}) {
                   1205:     my ($production,$testing,$sizes) = &download_versionslist();
                   1206:     if ($production && $testing) {
                   1207:         if ($production ne $testing) {
                   1208:             print &mt('Two recent LON-CAPA releases are available: ')."\n".
1.3       raeburn  1209:                   &mt('1.').' '.&mt('A production release - version: [_1].',$production)."\n".
                   1210:                   &mt('2.').' '.&mt('A testing release - version: [_1].',$testing)."\n\n".
1.1       raeburn  1211:                   &mt('Download the production release? ~[Y/n~]');
                   1212:             if (&get_user_selection(1)) {
1.4       raeburn  1213:                 $sourcetarball = 'loncapa-'.$production.'.tar.gz';
1.1       raeburn  1214:             } else {
                   1215:                 print "\n".&mt('Download the testing release? ~[Y/n~]');
                   1216:                 if (&get_user_selection(1)) {
1.4       raeburn  1217:                     $sourcetarball = 'loncapa-'.$testing.'.tar.gz';
1.1       raeburn  1218:                 }
                   1219:             }
                   1220:         }
                   1221:     } elsif ($production) {
                   1222:         print &mt('The most recent LON-CAPA release is version: [_1].',$production)."\n".
                   1223:               &mt('Download the production release? ~[Y/n~]');
                   1224:         if (&get_user_selection(1)) {
1.20      raeburn  1225:             $sourcetarball = 'loncapa-'.$production.'.tar.gz';
1.1       raeburn  1226:         }
                   1227:     }
                   1228: } elsif ($filetouse ne '') {
                   1229:     $sourcetarball = $filetouse;
                   1230: }
                   1231: 
                   1232: print_and_log("\n");
                   1233: 
                   1234: # Each action: report if skipping, or perform action and provide feedback. 
                   1235: if ($callsub{'wwwuser'}) {
                   1236:     &setup_www();
                   1237: } else {
                   1238:     &print_and_log(&mt('Skipping creation of user [_1].',"'www'")."\n");
                   1239: }
                   1240: 
                   1241: if ($callsub{'pwauth'}) {
1.4       raeburn  1242:     &build_and_install_mod_auth_external($instdir);
1.1       raeburn  1243: } else {
                   1244:     &print_and_log(&mt('Skipping [_1] installation.',"'pwauth'")."\n");
                   1245: }
                   1246: 
                   1247: if ($callsub{'mysql'}) {
                   1248:     if ($dbh) {
                   1249:         &setup_mysql($callsub{'mysqlperms'},$distro,$dbh,$has_pass,$has_lcdb);
                   1250:     } else {
                   1251:         print &mt('Unable to configure MySQL because access is denied.')."\n";
                   1252:     }
                   1253: } else {
                   1254:     &print_and_log(&mt('Skipping configuration of MySQL.')."\n");
                   1255:     if ($callsub{'mysqlperms'}) {
                   1256:         if ($dbh) {
                   1257:             &setup_mysql_permissions($dbh,$has_pass);
                   1258:         } else {
                   1259:             print &mt('Unable to configure MySQL because access is denied.')."\n";  
                   1260:         }
                   1261:     } else {
                   1262:         &print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
                   1263:     }
                   1264: }
                   1265: 
                   1266: if ($dbh) {
                   1267:     if (!$dbh->disconnect) {
                   1268:         &print_and_log(&mt('Failed to disconnect from MySQL:')."\n".
                   1269:                        $dbh->errstr);
                   1270:     }
                   1271: }
                   1272: 
                   1273: if ($callsub{'apache'}) {
                   1274:     if ($distro =~ /^(suse|sles)/) {
                   1275:         &copy_apache2_suseconf($instdir);
                   1276:     } elsif ($distro =~ /^(debian|ubuntu)/) {
                   1277:         &copy_apache2_debconf($instdir);
                   1278:     } else {
1.14      raeburn  1279:         &copy_httpd_conf($instdir,$distro);
1.1       raeburn  1280:     }
                   1281: } else {
                   1282:     print_and_log(&mt('Skipping configuration of Apache web server.')."\n");
                   1283: }
                   1284: 
                   1285: if ($callsub{'runlevels'}) {
                   1286:     my $count = 0;
                   1287:     if (ref($recommended) eq 'HASH') {
                   1288:         if (ref($recommended->{'runlevels'}) eq 'HASH') {
                   1289:             foreach my $type (keys(%{$recommended->{'runlevels'}})) {
                   1290:                 next if ($type eq 'insserv');
                   1291:                 $count ++;
                   1292:                 my $command = $recommended->{'runlevels'}{$type};
                   1293:                 if ($command ne '') {
                   1294:                     print_and_log(&mt('Runlevel update command run: [_1].',$command)."\n");
                   1295:                     system($command);
                   1296:                 }
                   1297:             }
                   1298:             if (!$count) {
                   1299:                 print_and_log(&mt('No runlevel updates required.')."\n");
                   1300:             }  
                   1301:         }
                   1302:     }
1.11      raeburn  1303:     if ($distro =~ /^(suse|sles)/) {
                   1304:         &update_SuSEfirewall2_setup($instdir);
                   1305:     }
1.1       raeburn  1306: } else {
                   1307:     &print_and_log(&mt('Skipping setting override for start-up order of services.')."\n");
                   1308: }
                   1309: 
                   1310: if ($callsub{'firewall'}) {
                   1311:     if ($distro =~ /^(suse|sles)/) {
1.5       raeburn  1312:         print &mt('Use [_1] to configure the firewall to allow access for [_2].',
                   1313:                   'yast -- Security and Users -> Firewall -> Interfaces',
                   1314:                    'ssh, http, https')."\n";
                   1315:     } elsif ($distro =~ /^(debian|ubuntu)(\d+)/) {
                   1316:         if (($1 eq 'ubuntu') || ($2 > 5)) {
                   1317:             print &mt('Use [_1] to configure the firewall to allow access for [_2].',
                   1318:                       'ufw','ssh, http, https')."\n";
                   1319:         } else {
                   1320:             my $fwadded = &get_iptables_rules($distro,$instdir,$apachefw);
                   1321:             if ($fwadded) {
                   1322:                 print &mt('Enable firewall? ~[Y/n~]');
                   1323:                 my $enable_iptables = &get_user_selection(1);
                   1324:                 if ($enable_iptables) {
                   1325:                     system('/etc/network/if-pre-up.d/iptables');
                   1326:                     print &mt('Firewall enabled using rules defined in [_1].',
                   1327:                               '/etc/iptables.loncapa.rules'); 
                   1328:                 }
                   1329:             }
                   1330:         }
1.11      raeburn  1331:     } elsif ($distro =~ /^scientific/) {
                   1332:         print &mt('Use [_1] to configure the firewall to allow access for [_2].',
                   1333:                   'system-config-firewall-tui -- Customize',
                   1334:                   'ssh, http')."\n";
1.1       raeburn  1335:     } else {
1.5       raeburn  1336:         print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1.11      raeburn  1337:                   'setup -- Firewall configuration -> Customize',
1.5       raeburn  1338:                   'ssh, http, https')."\n";
1.1       raeburn  1339:     }
                   1340: } else {
1.5       raeburn  1341:     &print_and_log(&mt('Skipping Firewall configuration.')."\n");
1.1       raeburn  1342: }
                   1343: 
                   1344: if ($callsub{'stopsrvcs'}) {
                   1345:     &kill_extra_services($distro,$recommended->{'stopsrvcs'});
                   1346: } else {
1.10      raeburn  1347:     &print_and_log(&mt('Skipping stopping unnecessary service ([_1] daemons).',"'cups','memcached'")."\n");
1.1       raeburn  1348: }
                   1349: 
                   1350: my ($have_tarball,$updateshown);
                   1351: if ($callsub{'download'}) {
                   1352:     ($have_tarball,$updateshown) = &download_loncapa($instdir,$sourcetarball);
                   1353: } else {
                   1354:     print_and_log(&mt('Skipping download of LON-CAPA tar file.')."\n\n");
                   1355:     print &mt('LON-CAPA is available for download from: [_1]',
                   1356:               'http://install.loncapa.org/')."\n";
                   1357:     if (!-e '/etc/loncapa-release') {
                   1358:         &print_and_log(&mt('LON-CAPA is not yet installed on your system.'). 
                   1359:                        "\n\n". 
                   1360:                        &mt('You may retrieve the source for LON-CAPA by executing:')."\n".
                   1361:                        "wget http://install.loncapa.org/versions/$lctarball\n");
                   1362:     } else {
                   1363:         my $currentversion;
                   1364:         if (open(my $fh,"</etc/loncapa-release")) {
                   1365:             my $version = <$fh>;
                   1366:             chomp($version);
                   1367:             if ($version =~ /^\QLON-CAPA release \E([\w\-.]+)$/) {
                   1368:                 $currentversion = $1;
                   1369:             }
                   1370:         }
                   1371:         if ($currentversion ne '') {
                   1372:             print &mt('Version of LON-CAPA currently installed on this server is: [_1].',
                   1373:                       $currentversion),"\n";
                   1374:             if ($production) {
                   1375:                 print &mt('The latest production release of LON-CAPA is [_1].',$production)."\n";
                   1376:             }
                   1377:             if ($testing) {
                   1378:                 print &mt('The latest testing release of LON-CAPA is [_1].',$testing)."\n";
                   1379:             }
                   1380:         }
                   1381:     }
                   1382:     if ($filetouse ne '') {
                   1383:         $have_tarball = 1;
                   1384:     }
                   1385: }
                   1386: 
                   1387: print "\n".&mt('Requested configuration complete.')."\n\n";
                   1388: my $apachename;
                   1389: if ($have_tarball && !$updateshown) {
                   1390:     my ($lcdir) = ($sourcetarball =~ /^([\w.\-]+)\.tar.gz$/);
                   1391:     if (!-e '/etc/loncapa-release') {
                   1392:         print &mt('If you are now ready to install LON-CAPA, enter the following commands:')."\n\n";
                   1393:     } else {
                   1394:         print &mt('If you are now ready to update LON-CAPA, enter the following commands:')."\n\n".
                   1395:                   "/etc/init.d/loncontrol stop\n";
                   1396:         if ($distro =~ /^(suse|sles|debian|ubuntu)([\d.]+)/) {
                   1397:             if (($1 eq 'suse') && ($2 < 10)) {
                   1398:                 $apachename = 'apache';
                   1399:             } else {
                   1400:                 $apachename = 'apache2';
                   1401:             }
                   1402:         } else {
                   1403:             $apachename = 'httpd';
                   1404:         }
                   1405:         print "/etc/init.d/$apachename stop\n";
                   1406:     }
                   1407:     print "cd /root\n".
                   1408:           "tar zxf $sourcetarball\n".
                   1409:           "cd $lcdir\n".
                   1410:           "./UPDATE\n";
                   1411:     if (-e '/etc/loncapa-release') {
                   1412:         print "/etc/init.d/loncontrol start\n";
                   1413:         print "/etc/init.d/$apachename start\n";
                   1414:     }
                   1415: }
                   1416: exit;
                   1417: 
                   1418: #
                   1419: # End main script
                   1420: #
                   1421: 
                   1422: #
                   1423: # Routines for the actions
                   1424: #
                   1425:  
                   1426: sub setup_www {
                   1427:     ##
                   1428:     ## Set up www
                   1429:     ##
                   1430:     print_and_log(&mt('Creating user [_1]',"'www'")."\n");
                   1431:     # -- Add group
                   1432: 
                   1433:     my $status = `/usr/sbin/groupadd www`;
                   1434:     if ($status =~ /\QGroup `www' already exists.\E/) {
                   1435:         print &mt('Group [_1] already exists.',"'www'")."\n";
                   1436:     } elsif ($status ne '') {
                   1437:         print &mt('Unable to add group [_1].',"'www'")."\n";
                   1438:     }
                   1439:    
                   1440:     my $gid = getgrnam('www');
                   1441: 
                   1442:     if (open (PIPE, "/usr/sbin/useradd -c LONCAPA -g $gid www 2>&1 |")) {
                   1443:         $status = <PIPE>;
                   1444:         close(PIPE);
                   1445:         chomp($status);
                   1446:         if ($status =~ /\QAccount `www' already exists.\E/) {
                   1447:             print &mt('Account [_1] already exists.',"'www'")."\n";
                   1448:         } elsif ($status ne '') {
                   1449:             print &mt('Unable to add user [_1].',"'www'")."\n";
                   1450:         }
                   1451:     }  else {
                   1452:         print &mt('Unable to run command to add user [_1].',"'www'")."\n";
                   1453:     }
                   1454: 
                   1455:     my $uid = &uid_of_www();
                   1456:     if (($gid ne '') && ($uid ne '')) {
                   1457:         if (!-e '/home/www') {
                   1458:             mkdir('/home/www',0755);
                   1459:             system('chown www:www /home/www');
                   1460:         }
                   1461:     }
                   1462:     writelog ($status);
                   1463: }
                   1464: 
                   1465: sub uid_of_www {
                   1466:     my ($num) = (getpwnam('www'))[2];
                   1467:     return $num;
                   1468: }
                   1469: 
                   1470: sub build_and_install_mod_auth_external {
                   1471:     my ($instdir) = @_;
                   1472:     my $num = &uid_of_www();
                   1473:     # Patch pwauth
                   1474:     print_and_log(&mt('Building authentication system for LON-CAPA users.')."\n");
                   1475:     my $patch = <<"ENDPATCH";
                   1476: 148c148
                   1477: < #define SERVER_UIDS 99		/* user "nobody" */
                   1478: ---
                   1479: > #define SERVER_UIDS $num		/* user "www" */
                   1480: ENDPATCH
                   1481: 
                   1482:     if (! -e "/usr/bin/patch") {
                   1483: 	print_and_log(&mt('You must install the software development tools package: [_1], when installing Linux.',"'patch'")."\n");
                   1484:         print_and_log(&mt('Authentication installation not completed.')."\n");
                   1485:         return;
                   1486:     }
                   1487:     if (&skip_if_nonempty(`cd /tmp; tar zxf $instdir/pwauth-2.2.8.tar.gz`,
                   1488: 		     &mt('Unable to extract pwauth')."\n")) {
                   1489:         return;
                   1490:     }
                   1491:     my $dir = "/tmp/pwauth-2.2.8";
                   1492:     if (open(PATCH,"| patch $dir/config.h")) {
                   1493:         print PATCH $patch;
                   1494:         close(PATCH);
                   1495:         print_and_log("\n");
                   1496:         ##
                   1497:         ## Compile patched pwauth
                   1498:         ##
                   1499:         print_and_log(&mt('Compiling pwauth')."\n");
1.12      raeburn  1500:         my $result = `cd $dir/; make 2>/dev/null `;
1.1       raeburn  1501:         my $expected = <<"END";
                   1502: gcc -g    -c -o pwauth.o pwauth.c
                   1503: gcc -o pwauth -g  pwauth.o -lcrypt
                   1504: END
                   1505:         if ($result eq $expected) {
                   1506:             print_and_log(&mt('Apparent success compiling pwauth:').
                   1507:                           "\n".$result );
                   1508:             # Install patched pwauth
                   1509:             print_and_log(&mt('Copying pwauth to [_1]',' /usr/local/sbin')."\n");
                   1510:             if (copy "$dir/pwauth","/usr/local/sbin/pwauth") {
1.5       raeburn  1511:                 if (chmod(06755, "/usr/local/sbin/pwauth")) {
1.1       raeburn  1512:                     print_and_log(&mt('[_1] copied successfully',"'pwauth'").
                   1513:                                   "\n");
                   1514:                 } else {
                   1515:                     print &mt('Unable to set permissions on [_1].'.
                   1516:                               "/usr/local/sbin/pwauth")."\n";
                   1517:                 }
                   1518:             } else {
                   1519:                 print &mt('Unable to copy [_1] to [_2]',
                   1520:                           "'$dir/pwauth'","/usr/local/sbin/pwauth")."\n$!\n";
                   1521:             }
                   1522:         } else {
                   1523:             print &mt('Unable to compile patched [_1].'."'pwauth'")."\n";
                   1524:         }
                   1525:     } else {
                   1526:         print &mt('Unable to start patch for [_1]',"'pwauth'")."\n";
                   1527:     }
                   1528:     print_and_log("\n");
                   1529: }
                   1530: 
                   1531: sub kill_extra_services {
                   1532:     my ($distro,$stopsrvcs) = @_;
                   1533:     if (ref($stopsrvcs) eq 'HASH') {
                   1534:         my @stopping = sort(keys(%{$stopsrvcs}));
                   1535:         if (@stopping) {
1.6       raeburn  1536:             my $kill_list = join("', '",@stopping);
1.1       raeburn  1537:             if ($kill_list) {
                   1538:                 $kill_list = "'".$kill_list."'";
1.6       raeburn  1539:                 &print_and_log("\n".&mt('Killing unnecessary services ([_1] daemon(s)).',$kill_list)."\n");
                   1540:                 foreach my $service (@stopping) {
                   1541:                     my $daemon = $service;
                   1542:                     if ($service eq 'cups') {
                   1543:                         $daemon = 'cupsd';
                   1544:                         if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
                   1545:                             my $version = $1;
                   1546:                             if (($distro =~ /^ubuntu/) && ($version <= 8)) {
                   1547:                                 $daemon = 'cupsys';
                   1548:                             }
1.12      raeburn  1549:                         } else {
1.8       raeburn  1550:                             $daemon = 'cups';
1.6       raeburn  1551:                         }
                   1552:                     }
1.12      raeburn  1553:                     my $cmd = "ps -ef |grep '$daemon' |grep -v grep";
                   1554:                     if (open(PIPE,'-|',$cmd)) {
                   1555:                         my $daemonrunning = <PIPE>;
                   1556:                         chomp($daemonrunning);
                   1557:                         close(PIPE);
                   1558:                         if ($daemonrunning) {
                   1559:                             &print_and_log(`/etc/init.d/$daemon stop`);
                   1560:                         }
                   1561:                     }
1.1       raeburn  1562: 	            &print_and_log(&mt('Removing [_1] from startup.',$service)."\n");
1.4       raeburn  1563:                     if ($distro =~ /^(debian|ubuntu)/) {
1.6       raeburn  1564:                         &print_and_log(`update-rc.d -f $daemon remove`);
1.1       raeburn  1565:                     } else {
1.12      raeburn  1566: 	                &print_and_log(`/sbin/chkconfig --del $service`);
1.1       raeburn  1567:                     }
                   1568:                 }
                   1569:             }
                   1570:         }
                   1571:     }
                   1572:     return;
                   1573: }
                   1574: 
                   1575: sub setup_mysql {
                   1576:     my ($setup_mysql_permissions,$distro,$dbh,$has_pass,$has_lcdb) = @_;
1.4       raeburn  1577:     my @mysql_lc_commands;
1.1       raeburn  1578:     unless ($has_lcdb) {
1.4       raeburn  1579:         push(@mysql_lc_commands,"CREATE DATABASE loncapa");
1.1       raeburn  1580:     }
1.4       raeburn  1581:     push(@mysql_lc_commands,"USE loncapa");
                   1582:     push(@mysql_lc_commands,qq{
1.18      raeburn  1583: 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, domain TEXT, dependencies TEXT, modifyinguser TEXT, authorspace TEXT, lowestgradelevel TEXT, highestgradelevel TEXT, standards TEXT, count INT, course INT, course_list TEXT, goto INT, goto_list TEXT, comefrom INT, comefrom_list TEXT, sequsage INT, sequsage_list TEXT, stdno INT, stdno_list TEXT, avetries FLOAT, avetries_list TEXT, difficulty FLOAT, difficulty_list TEXT, disc FLOAT, disc_list TEXT, clear FLOAT, technical FLOAT, correct FLOAT, helpful FLOAT, depth FLOAT, hostname 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)) ENGINE=MYISAM
1.4       raeburn  1584: });
1.1       raeburn  1585:     if ($setup_mysql_permissions) {
1.4       raeburn  1586:         &setup_mysql_permissions($dbh,$has_pass,@mysql_lc_commands);
1.1       raeburn  1587:     } else {
                   1588:         print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
                   1589:         if ($dbh) {
1.4       raeburn  1590:             if (@mysql_lc_commands) {
                   1591:                 foreach my $lccmd (@mysql_lc_commands) { 
                   1592:                     $dbh->do($lccmd) || print $dbh->errstr."\n";
                   1593:                 }
                   1594:             }
1.1       raeburn  1595:             print_and_log(&mt('MySQL database set up complete.')."\n");
                   1596:         } else {
                   1597:             print_and_log(&mt('Problem accessing MySQL.')."\n");
                   1598:         }
                   1599:     }
                   1600: }
                   1601: 
                   1602: sub setup_mysql_permissions {
1.4       raeburn  1603:     my ($dbh,$has_pass,@mysql_lc_commands) = @_;
1.1       raeburn  1604:     my $mysqlversion = &get_mysql_version();
1.4       raeburn  1605:     my @mysql_commands = ("INSERT user (Host, User, Password) VALUES('localhost','www',password('localhostkey'));");
1.1       raeburn  1606:     if ($mysqlversion < 4) {
1.4       raeburn  1607:         push (@mysql_commands,"
                   1608: INSERT 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')");
                   1609:     } else {
                   1610:         push (@mysql_commands,"
                   1611: INSERT db (Host,Db,User,Select_priv,Insert_priv,Update_priv,Delete_priv,Create_priv,Drop_priv,Grant_priv,References_priv,Index_priv,Alter_priv,Create_tmp_table_priv,Lock_tables_priv) VALUES('localhost','loncapa','www','Y','Y','Y','Y','Y','Y','N','Y','Y','Y','Y','Y')");
1.1       raeburn  1612:     }
1.4       raeburn  1613:     push(@mysql_commands,"DELETE FROM user WHERE host<>'localhost'");
1.1       raeburn  1614:     if ($has_pass) {
                   1615:         if ($dbh) {
1.4       raeburn  1616:             push(@mysql_commands,"FLUSH PRIVILEGES");
                   1617:             if (@mysql_commands) {
                   1618:                 foreach my $cmd (@mysql_commands) {
                   1619:                     $dbh->do($cmd) || print $dbh->errstr."\n";
                   1620:                 }
                   1621:             }
                   1622:             if (@mysql_lc_commands) {
                   1623:                 foreach my $lccmd (@mysql_lc_commands) {
                   1624:                     $dbh->do($lccmd) || print $dbh->errstr."\n";
                   1625:                 }
                   1626:             }
1.1       raeburn  1627:             print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1]',"'www'")."\n");
                   1628:         } else {
                   1629:             print_and_log(&mt('Problem accessing MySQL.')."\n".
                   1630:                           &mt('Permissions not set.')."\n");
                   1631:         }
                   1632:     } else {
                   1633:         my ($firstpass,$secondpass,$got_passwd,$newmysqlpass);
                   1634:         print &mt('Please enter a root password for the mysql database.')."\n".
                   1635:               &mt('It does not have to match your root account password, but you will need to remember it.')."\n";
                   1636:         my $maxtries = 10;
                   1637:         my $trial = 0;
                   1638:         while ((!$got_passwd) && ($trial < $maxtries)) {
                   1639:             $firstpass = &get_mysql_password(&mt('Enter password'));
                   1640:             if (length($firstpass) > 5) { 
                   1641:                 $secondpass = &get_mysql_password(&mt('Enter password a second time'));
                   1642:                 if ($firstpass eq $secondpass) {
                   1643:                     $got_passwd = 1;
                   1644:                     $newmysqlpass = $firstpass;
                   1645:                 } else {
                   1646:                     print(&mt('Passwords did not match. Please try again.')."\n");
                   1647:                 }
                   1648:                 $trial ++;
                   1649:             } else {
                   1650:                 print(&mt('Password too short.')."\n".
                   1651:                       &mt('Please choose a password with at least six characters.')."\n");
                   1652:             }
                   1653:         }
                   1654:         if ($got_passwd) {
1.4       raeburn  1655:             my (@newpass_cmds) = &new_mysql_rootpasswd($newmysqlpass);
                   1656:             push(@mysql_commands,@newpass_cmds);
1.1       raeburn  1657:         } else {
                   1658:             print_and_log(&mt('Failed to get MySQL root password from user input.')."\n");
                   1659:         }
                   1660:         if ($dbh) {
1.4       raeburn  1661:             if (@mysql_commands) {
                   1662:                 foreach my $cmd (@mysql_commands) {
                   1663:                     $dbh->do($cmd) || print $dbh->errstr."\n";
                   1664: 
                   1665:                 }
                   1666:             }
                   1667:             if (@mysql_lc_commands) {
                   1668:                 foreach my $lccmd (@mysql_lc_commands) {
                   1669:                     $dbh->do($lccmd) || print $dbh->errstr."\n";
                   1670:                 }
                   1671:             }
1.1       raeburn  1672:             if ($got_passwd) {
                   1673:                 print_and_log(&mt('MySQL root password stored.')."\n".
                   1674:                               &mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
                   1675:             } else {
                   1676:                 print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
                   1677:             }
                   1678:         } else {
                   1679:             print_and_log(&mt('Problem accessing MySQL.')."\n".
                   1680:                           &mt('Permissions not set.')."\n");
                   1681:         }
                   1682:     }
                   1683: }
                   1684: 
                   1685: sub new_mysql_rootpasswd {
                   1686:     my ($currmysqlpass) = @_;
1.4       raeburn  1687:     return ("SET PASSWORD FOR 'root'\@'localhost'=PASSWORD('$currmysqlpass')",
                   1688:             "FLUSH PRIVILEGES;");
1.1       raeburn  1689: }
                   1690: 
                   1691: sub get_mysql_version {
                   1692:     my $version;
                   1693:     if (open(PIPE," mysql -V |")) {
                   1694:         my $info = <PIPE>;
                   1695:         chomp($info);
                   1696:         close(PIPE);
                   1697:         ($version) = ($info =~ /(\d+\.\d+)\.\d+,/);  
                   1698:     } else {
                   1699:         print &mt('Could not determine which version of MySQL is installed.').
                   1700:               "\n";
                   1701:     }
                   1702:     return $version;
                   1703: }
                   1704: 
                   1705: ###########################################################
                   1706: ##
                   1707: ## RHEL/CentOS/Fedora/Scientific Linux
                   1708: ## Copy LON-CAPA httpd.conf to /etc/httpd/conf
                   1709: ##
                   1710: ###########################################################
                   1711: 
                   1712: sub copy_httpd_conf {
1.14      raeburn  1713:     my ($instdir,$distro) = @_;
                   1714:     my $configfile = 'httpd.conf';
                   1715:     if ($distro =~ /^(?:centos|rhes|scientific)(\d+)$/) {
                   1716:         if ($1 > 5) {
                   1717:             $configfile = 'new/httpd.conf';
                   1718:         }
                   1719:     } elsif ($distro =~ /^fedora(\d+)$/) {
                   1720:         if ($1 > 10) {
                   1721:             $configfile = 'new/httpd.conf';
                   1722:         }
                   1723:     }
1.1       raeburn  1724:     print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'httpd.conf'",
                   1725:                   "'/etc/httpd/conf/httpd.conf'")."\n");
                   1726:     copy "/etc/httpd/conf/httpd.conf","/etc/httpd/conf/httpd.conf.original";
1.14      raeburn  1727:     copy "$instdir/centos-rhes-fedora-sl/$configfile","/etc/httpd/conf/httpd.conf";
1.5       raeburn  1728:     chmod(0444,"/etc/httpd/conf/httpd.conf");
1.1       raeburn  1729:     print_and_log("\n");
                   1730: }
                   1731: 
                   1732: #########################################################
                   1733: ##
1.17      raeburn  1734: ## Ubuntu/Debian -- copy our loncapa configuration file to
1.1       raeburn  1735: ## sites-available and set the symlink from sites-enabled.
                   1736: ##
                   1737: #########################################################
                   1738: 
                   1739: sub copy_apache2_debconf {
                   1740:     my ($instdir) = @_;
1.4       raeburn  1741:     print_and_log(&mt('Copying loncapa [_1] config file to [_2] and pointing [_3] to it from sites-enabled.',"'apache2'","'/etc/apache2/sites-available'","'000-default symlink'")."\n");
1.6       raeburn  1742:     my $apache2_sites_enabled_dir = '/etc/apache2/sites-enabled';
                   1743:     my $apache2_sites_available_dir = '/etc/apache2/sites-available';
                   1744:     if (-l "$apache2_sites_enabled_dir/000-default") {
                   1745:         unlink("$apache2_sites_enabled_dir/000-default");
                   1746:     }
                   1747:     if (-e "$apache2_sites_available_dir/loncapa") {
                   1748:         copy("$apache2_sites_available_dir/loncapa","$apache2_sites_available_dir/loncapa.original");
                   1749:     }
1.17      raeburn  1750:     copy("$instdir/debian-ubuntu/loncapa","$apache2_sites_available_dir/loncapa");
1.6       raeburn  1751:     chmod(0444,"$apache2_sites_available_dir/loncapa");
                   1752:     symlink("$apache2_sites_available_dir/loncapa","$apache2_sites_enabled_dir/000-default");
                   1753:     my $apache2_mods_enabled_dir = '/etc/apache2/mods-enabled';
                   1754:     my $apache2_mods_available_dir = '/etc/apache2/mods-available';
                   1755:     foreach my $module ('headers.load','expires.load') {
                   1756:         unless (-l "$apache2_mods_enabled_dir/$module") {
                   1757:             symlink("$apache2_mods_available_dir/$module","$apache2_mods_enabled_dir/$module");
                   1758:             print_and_log(&mt('Enabling "[_1]" Apache module.',$module)."\n");
                   1759:         }
                   1760:     }
1.1       raeburn  1761:     print_and_log("\n");
                   1762: }
                   1763: 
                   1764: ###########################################################
                   1765: ##
                   1766: ## openSuSE/SLES Copy apache2 config files:
                   1767: ##   default-server.conf, uid.conf, /etc/sysconfig/apache2 
                   1768: ##   and create symlink from /srv/www/conf to /etc/apache2 
                   1769: ##
                   1770: ###########################################################
                   1771: 
                   1772: sub copy_apache2_suseconf {
                   1773:     my ($instdir) = @_;
                   1774:     print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
                   1775:                   "'default-server.conf'",
                   1776:                   "'/etc/apache2/default-server.conf'")."\n");
                   1777:     if (!-e "/etc/apache2/default-server.conf.original") {
                   1778:         copy "/etc/apache2/default-server.conf","/etc/apache2/default-server.conf.original";
                   1779:     }
1.9       raeburn  1780:     copy "$instdir/sles-suse/default-server.conf","/etc/apache2/default-server.conf";
1.5       raeburn  1781:     chmod(0444,"/etc/apache2/default-server.conf");
1.1       raeburn  1782:     # Make symlink for conf directory (included in loncapa_apache.conf)
                   1783:     my $can_symlink = (eval { symlink('/etc/apache2','/srv/www/conf'); }, $@ eq '');
                   1784:     if ($can_symlink) {
                   1785:         &print_and_log(&mt('Symlink created for [_1] to [_2].',
                   1786:                        "'/srv/www/conf'","'/etc/apache2'")."\n");
                   1787:     } else {
                   1788:         &print_and_log(&mt('Symlink creation failed for [_1] to [_2]. You will need to perform this action from the command line.',"'/srv/www/conf'","'/etc/apache2'")."\n");
                   1789:     }
                   1790:     &copy_apache2_conf_files($instdir);
                   1791:     &copy_sysconfig_apache2_file($instdir); 
                   1792:     print_and_log("\n");
                   1793: }
                   1794: 
                   1795: ###############################################
                   1796: ##
                   1797: ## Modify uid.conf
                   1798: ##
                   1799: ###############################################
                   1800: sub copy_apache2_conf_files {
                   1801:     my ($instdir) = @_;
                   1802:     print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
                   1803:                   "'uid.conf'","'/etc/apache2/uid.conf'")."\n");
                   1804:     if (!-e "/etc/apache2/uid.conf.original") {
                   1805:         copy "/etc/apache2/uid.conf","/etc/apache2/uid.conf.original";
                   1806:     }
1.9       raeburn  1807:     copy "$instdir/sles-suse/uid.conf","/etc/apache2/uid.conf";
1.5       raeburn  1808:     chmod(0444,"/etc/apache2/uid.conf");
1.1       raeburn  1809: }
                   1810: 
                   1811: ###############################################
                   1812: ##
                   1813: ## Modify /etc/sysconfig/apache2  
                   1814: ##
                   1815: ###############################################
                   1816: sub copy_sysconfig_apache2_file {
                   1817:     my ($instdir) = @_;
                   1818:     print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'sysconfig/apache2'","'/etc/sysconfig/apache2'")."\n");
                   1819:     if (!-e "/etc/sysconfig/apache2.original") {
                   1820:         copy "/etc/sysconfig/apache2","/etc/sysconfig/apache2.original";
                   1821:     }
1.9       raeburn  1822:     copy "$instdir/sles-suse/sysconfig_apache2","/etc/sysconfig/apache2";
1.5       raeburn  1823:     chmod(0444,"/etc/sysconfig/apache2");
1.1       raeburn  1824: }
                   1825: 
                   1826: ###############################################
                   1827: ##
                   1828: ## Add/Modify /etc/insserv/overrides
                   1829: ##
                   1830: ###############################################
                   1831: 
                   1832: sub update_SuSEfirewall2_setup {
                   1833:     my ($instdir) = @_;
                   1834:     print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'SuSEfirewall2_setup'","'/etc/insserv/overrides/SuSEfirewall2_setup'")."\n");
                   1835:     if (!-e "/etc/insserv/overrides/SuSEfirewall2_setup") {
                   1836:         if (!-d "/etc/insserv") {
                   1837:             mkdir("/etc/insserv",0755); 
                   1838:         }
                   1839:         if (!-d "/etc/insserv/overrides") {
                   1840:             mkdir("/etc/insserv/overrides",0755);
                   1841:         }
                   1842:     } elsif (!-e  "/etc/insserv/overrides/SuSEfirewall2_setup.original") {
                   1843:         copy "/etc/insserv/overrides/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup.original"
                   1844:     }
1.9       raeburn  1845:     copy "$instdir/sles-suse/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup";
1.5       raeburn  1846:     chmod(0444,"/etc/insserv/overrides/SuSEfirewall2_setup");
                   1847: }
                   1848: 
                   1849: sub get_iptables_rules {
                   1850:     my ($distro,$instdir,$apachefw) = @_;
                   1851:     my (@fwchains,@ports);
                   1852:     if (&firewall_is_active()) {
                   1853:         my $iptables = &get_pathto_iptables();
                   1854:         if ($iptables ne '') {
                   1855:             @fwchains = &get_fw_chains($iptables,$distro);
                   1856:         }
                   1857:     }
                   1858:     if (ref($apachefw) eq 'HASH') {
                   1859:         foreach my $service ('http','https') {
                   1860:             unless ($apachefw->{$service}) {
                   1861:                 push (@ports,$service); 
                   1862:             }
                   1863:         }
                   1864:     } else {
                   1865:         @ports = ('http','https');
                   1866:     }
                   1867:     if (@ports == 0) {
                   1868:         return;
                   1869:     }
                   1870:     my $ask_to_enable;
                   1871:     if (-e "/etc/iptables.loncapa.rules") {
1.9       raeburn  1872:         if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables.loncapa.rules /etc/iptables.loncapa.rules |")) {
1.5       raeburn  1873:             my $diffres = <PIPE>;
                   1874:             close(PIPE);
                   1875:             chomp($diffres);
                   1876:             if ($diffres) {
                   1877:                 print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
                   1878:             }
                   1879:         } else {
                   1880:             print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
                   1881:         }
                   1882:     } else {
1.9       raeburn  1883:         if (-e "$instdir/debian-ubuntu/iptables.loncapa.rules") {
                   1884:             copy "$instdir/debian-ubuntu/iptables.loncapa.rules","/etc/iptables.loncapa.rules";
1.5       raeburn  1885:             chmod(0600,"/etc/iptables.loncapa.rules");
                   1886:         }
                   1887:     }
                   1888:     if (-e "/etc/iptables.loncapa.rules") {
                   1889:         if (-e "/etc/network/if-pre-up.d/iptables") {
1.9       raeburn  1890:             if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables /etc/network/if-pre-up/iptables |")) {
1.5       raeburn  1891:                 my $diffres = <PIPE>;
                   1892:                 close(PIPE);
                   1893:                 chomp($diffres);
                   1894:                 if ($diffres) {
                   1895:                     print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
                   1896:                 }
                   1897:             } else {
                   1898:                 print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
                   1899:             }
                   1900:         } else {
1.9       raeburn  1901:             copy "$instdir/debian-ubuntu/iptables","/etc/network/if-pre-up.d/iptables";
1.5       raeburn  1902:             chmod(0755,"/etc/network/if-pre-up.d/iptables");
                   1903:             print_and_log(&mt('Installed script "[_1]" to add iptables rules to block all ports except 22, 80, and 443 when network is enabled during boot.','/etc/network/if-pre-up.d/iptables'));
                   1904:             $ask_to_enable = 1;
                   1905:         }
                   1906:     }
                   1907:     return $ask_to_enable;
1.1       raeburn  1908: }
                   1909: 
                   1910: sub download_loncapa {
                   1911:     my ($instdir,$lctarball) = @_;
                   1912:     my ($have_tarball,$updateshown);
                   1913:     if (! -e "$instdir/$lctarball") {
                   1914: 	print_and_log(&mt('Retrieving LON-CAPA source files from: [_1]',
                   1915: 		      'http://install.loncapa.org')."\n");
                   1916: 	system("wget http://install.loncapa.org/versions/$lctarball ".
                   1917: 	       "2>/dev/null 1>/dev/null");
                   1918: 	if (! -e "./$lctarball") {
                   1919: 	    print &mt('Unable to retrieve LON-CAPA source files from: [_1].', 
                   1920: 		     "http://install.loncapa.org/versions/$lctarball")."\n";
                   1921: 	} else {
                   1922:             $have_tarball = 1;
                   1923:         }
                   1924: 	print_and_log("\n");
                   1925:     } else {
                   1926:         $have_tarball = 1;
                   1927: 	print_and_log("
                   1928: ------------------------------------------------------------------------
                   1929: 
                   1930: ".&mt('You seem to have a version of loncapa-current.tar.gz in [_1]',$instdir)."\n".
                   1931: &mt('This copy will be used and a new version will NOT be downloaded.')."\n".
                   1932: &mt('If you wish, you may download a new version by executing:')."
                   1933: 
1.2       raeburn  1934: wget http://install.loncapa.org/versions/loncapa-current.tar.gz
1.1       raeburn  1935: 
                   1936: ------------------------------------------------------------------------
                   1937: ");
                   1938:     }
                   1939: 
                   1940:     ##
                   1941:     ## untar loncapa.tar.gz
                   1942:     ##
                   1943:     if ($have_tarball) {
                   1944:         print_and_log(&mt('Extracting LON-CAPA source files')."\n");
                   1945:         writelog(`cd ~root; tar zxf $instdir/$lctarball`);
                   1946:         print_and_log("\n");
                   1947:         print &mt('LON-CAPA source files extracted.')."\n".
                   1948:               &mt('It remains for you to execute the following commands:')."
                   1949: 
                   1950: cd /root/loncapa-N.N     (N.N should correspond to a version number like '0.4')
                   1951: ./UPDATE
                   1952: 
                   1953: ".&mt('If you have any trouble, please see [_1] and [_2]',
                   1954:       'http://install.loncapa.org/','http://help.loncapa.org/')."\n";
                   1955:         $updateshown = 1;
                   1956:     }
                   1957:     return ($have_tarball,$updateshown);
                   1958: }
                   1959: 
                   1960: close LOG;

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