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