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