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