Annotation of doc/install/linux/install.pl, revision 1.45.2.14
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.14! raeburn 79: print LOG '$Id: install.pl,v 1.45.2.13 2021/03/18 22:00:54 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.45.2.13 raeburn 213: } elsif ($versionstring =~ /CentOS(?:| Linux| Stream) 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.14! 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) {
1.45.2.14! raeburn 1166: if ($priv =~ /unix_socket/) {
1.45.2.9 raeburn 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: }
1.45.2.14! raeburn 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";
1.45.2.13 raeburn 1758: system('firewall-cmd --reload');
1.45.2.1 raeburn 1759: }
1760: if ($current{'http'} || $current{'https'}) {
1761: print &mt('Firewall already configured to allow access for:[_1].',
1762: (($current{'http'})? ' http':'').(($current{'https'})? ' https':''))."\n";
1763: }
1764: unless ($current{'ssh'}) {
1.45.2.13 raeburn 1765: print &mt('If you would like to allow access to ssh from outside, use the commands:')."\n".
1766: "firewall-cmd --permanent --zone=$zone --add-service=ssh\n".
1767: "firewall-cmd --reload\n";
1.45.2.1 raeburn 1768: }
1769: } elsif ($distro =~ /^(suse|sles)/) {
1.5 raeburn 1770: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1771: 'yast -- Security and Users -> Firewall -> Interfaces',
1.45.2.1 raeburn 1772: 'ssh, http, https')."\n";
1.5 raeburn 1773: } elsif ($distro =~ /^(debian|ubuntu)(\d+)/) {
1774: if (($1 eq 'ubuntu') || ($2 > 5)) {
1775: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1776: 'ufw','ssh, http, https')."\n";
1777: } else {
1778: my $fwadded = &get_iptables_rules($distro,$instdir,$apachefw);
1779: if ($fwadded) {
1780: print &mt('Enable firewall? ~[Y/n~]');
1781: my $enable_iptables = &get_user_selection(1);
1782: if ($enable_iptables) {
1783: system('/etc/network/if-pre-up.d/iptables');
1784: print &mt('Firewall enabled using rules defined in [_1].',
1785: '/etc/iptables.loncapa.rules');
1786: }
1787: }
1788: }
1.45.2.3 raeburn 1789: } elsif ($distro =~ /^(scientific|oracle)/) {
1.11 raeburn 1790: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1791: 'system-config-firewall-tui -- Customize',
1792: 'ssh, http')."\n";
1.1 raeburn 1793: } else {
1.45.2.3 raeburn 1794: my $version;
1795: if ($distro =~ /^(redhat|centos)(\d+)$/) {
1796: $version = $1;
1797: }
1798: if ($version > 5) {
1799: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1800: 'system-config-firewall-tui -- Customize',
1801: 'ssh, http')."\n";
1802: } else {
1803: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1804: 'setup -- Firewall configuration -> Customize',
1805: 'ssh, http, https')."\n";
1806: }
1.1 raeburn 1807: }
1808: } else {
1.5 raeburn 1809: &print_and_log(&mt('Skipping Firewall configuration.')."\n");
1.1 raeburn 1810: }
1811:
1812: if ($callsub{'stopsrvcs'}) {
1.45 raeburn 1813: &kill_extra_services($distro,$recommended->{'stopsrvcs'},$uses_systemctl);
1.1 raeburn 1814: } else {
1.10 raeburn 1815: &print_and_log(&mt('Skipping stopping unnecessary service ([_1] daemons).',"'cups','memcached'")."\n");
1.1 raeburn 1816: }
1817:
1818: my ($have_tarball,$updateshown);
1819: if ($callsub{'download'}) {
1820: ($have_tarball,$updateshown) = &download_loncapa($instdir,$sourcetarball);
1821: } else {
1822: print_and_log(&mt('Skipping download of LON-CAPA tar file.')."\n\n");
1823: print &mt('LON-CAPA is available for download from: [_1]',
1824: 'http://install.loncapa.org/')."\n";
1825: if (!-e '/etc/loncapa-release') {
1826: &print_and_log(&mt('LON-CAPA is not yet installed on your system.').
1827: "\n\n".
1828: &mt('You may retrieve the source for LON-CAPA by executing:')."\n".
1829: "wget http://install.loncapa.org/versions/$lctarball\n");
1830: } else {
1831: my $currentversion;
1832: if (open(my $fh,"</etc/loncapa-release")) {
1833: my $version = <$fh>;
1834: chomp($version);
1835: if ($version =~ /^\QLON-CAPA release \E([\w\-.]+)$/) {
1836: $currentversion = $1;
1837: }
1838: }
1839: if ($currentversion ne '') {
1840: print &mt('Version of LON-CAPA currently installed on this server is: [_1].',
1841: $currentversion),"\n";
1842: if ($production) {
1843: print &mt('The latest production release of LON-CAPA is [_1].',$production)."\n";
1844: }
1845: if ($testing) {
1846: print &mt('The latest testing release of LON-CAPA is [_1].',$testing)."\n";
1847: }
1848: }
1849: }
1850: if ($filetouse ne '') {
1851: $have_tarball = 1;
1852: }
1853: }
1854:
1855: print "\n".&mt('Requested configuration complete.')."\n\n";
1856: if ($have_tarball && !$updateshown) {
1857: my ($lcdir) = ($sourcetarball =~ /^([\w.\-]+)\.tar.gz$/);
1.45.2.14! raeburn 1858: my ($apachename,$lc_uses_systemctl,$uses_sudo);
1.45.2.12 raeburn 1859: if ($distro =~ /^(suse|sles|debian|ubuntu)([\d.]+)/) {
1860: if (($1 eq 'suse') && ($2 < 10)) {
1861: $apachename = 'apache';
1862: } else {
1863: $apachename = 'apache2';
1864: }
1865: } else {
1866: $apachename = 'httpd';
1867: }
1868: if ($distro =~ /^oracle(\d+)$/) {
1869: if ($1 > 6) {
1870: $lc_uses_systemctl = 1;
1871: }
1872: } elsif ($distro =~ /^(?:rhes|centos)(\d+)$/) {
1873: if ($1 > 7) {
1874: $lc_uses_systemctl = 1;
1875: }
1876: } elsif ($distro =~ /^ubuntu(\d+)$/) {
1877: if ($1 > 16) {
1878: $lc_uses_systemctl = 1;
1879: }
1880: $uses_sudo = 1;
1881: } elsif ($distro =~ /^sles(\d+)$/) {
1882: if ($1 > 12) {
1883: $lc_uses_systemctl = 1;
1884: }
1885: }
1.1 raeburn 1886: if (!-e '/etc/loncapa-release') {
1887: print &mt('If you are now ready to install LON-CAPA, enter the following commands:')."\n\n";
1888: } else {
1.45.2.12 raeburn 1889: my $lcstop = '/etc/init.d/loncontrol stop';
1890: if ($lc_uses_systemctl) {
1891: $lcstop = 'systemctl stop loncontrol';
1892: }
1893: my $apachestop = "/etc/init.d/$apachename stop";
1894: if ($uses_systemctl) {
1895: $apachestop = "systemctl stop $apachename";
1896: }
1897: if ($uses_sudo) {
1898: $lcstop = 'sudo '.$lcstop;
1899: $apachestop = 'sudo '.$apachestop;
1.1 raeburn 1900: }
1.45.2.12 raeburn 1901: print &mt('If you are now ready to update LON-CAPA, enter the following commands:').
1902: "\n\n$lcstop\n$apachestop\n";
1.1 raeburn 1903: }
1904: print "cd /root\n".
1905: "tar zxf $sourcetarball\n".
1906: "cd $lcdir\n".
1907: "./UPDATE\n";
1908: if (-e '/etc/loncapa-release') {
1.45.2.12 raeburn 1909: my $lcstart = '/etc/init.d/loncontrol start';
1910: if ($lc_uses_systemctl) {
1911: $lcstart = '/home/httpd/perl/loncontrol start';
1912: }
1913: my $apachestart = "/etc/init.d/$apachename start";
1914: if ($uses_systemctl) {
1915: $apachestart = "systemctl start $apachename";
1916: }
1917: if ($uses_sudo) {
1918: $lcstart = 'sudo '.$lcstart;
1919: $apachestart = 'sudo '.$apachestart;
1920: }
1921: print "$lcstart\n";
1922: print "$apachestart\n";
1.1 raeburn 1923: }
1924: }
1925: exit;
1926:
1927: #
1928: # End main script
1929: #
1930:
1931: #
1932: # Routines for the actions
1933: #
1934:
1935: sub setup_www {
1936: ##
1937: ## Set up www
1938: ##
1939: print_and_log(&mt('Creating user [_1]',"'www'")."\n");
1940: # -- Add group
1941:
1942: my $status = `/usr/sbin/groupadd www`;
1943: if ($status =~ /\QGroup `www' already exists.\E/) {
1944: print &mt('Group [_1] already exists.',"'www'")."\n";
1945: } elsif ($status ne '') {
1946: print &mt('Unable to add group [_1].',"'www'")."\n";
1947: }
1948:
1949: my $gid = getgrnam('www');
1950:
1951: if (open (PIPE, "/usr/sbin/useradd -c LONCAPA -g $gid www 2>&1 |")) {
1952: $status = <PIPE>;
1953: close(PIPE);
1954: chomp($status);
1955: if ($status =~ /\QAccount `www' already exists.\E/) {
1956: print &mt('Account [_1] already exists.',"'www'")."\n";
1957: } elsif ($status ne '') {
1958: print &mt('Unable to add user [_1].',"'www'")."\n";
1959: }
1960: } else {
1961: print &mt('Unable to run command to add user [_1].',"'www'")."\n";
1962: }
1963:
1964: my $uid = &uid_of_www();
1965: if (($gid ne '') && ($uid ne '')) {
1966: if (!-e '/home/www') {
1967: mkdir('/home/www',0755);
1968: system('chown www:www /home/www');
1969: }
1970: }
1971: writelog ($status);
1972: }
1973:
1974: sub uid_of_www {
1975: my ($num) = (getpwnam('www'))[2];
1976: return $num;
1977: }
1978:
1979: sub build_and_install_mod_auth_external {
1980: my ($instdir) = @_;
1981: my $num = &uid_of_www();
1982: # Patch pwauth
1983: print_and_log(&mt('Building authentication system for LON-CAPA users.')."\n");
1984: my $patch = <<"ENDPATCH";
1985: 148c148
1986: < #define SERVER_UIDS 99 /* user "nobody" */
1987: ---
1988: > #define SERVER_UIDS $num /* user "www" */
1989: ENDPATCH
1990:
1991: if (! -e "/usr/bin/patch") {
1992: print_and_log(&mt('You must install the software development tools package: [_1], when installing Linux.',"'patch'")."\n");
1993: print_and_log(&mt('Authentication installation not completed.')."\n");
1994: return;
1995: }
1996: if (&skip_if_nonempty(`cd /tmp; tar zxf $instdir/pwauth-2.2.8.tar.gz`,
1997: &mt('Unable to extract pwauth')."\n")) {
1998: return;
1999: }
2000: my $dir = "/tmp/pwauth-2.2.8";
2001: if (open(PATCH,"| patch $dir/config.h")) {
2002: print PATCH $patch;
2003: close(PATCH);
2004: print_and_log("\n");
2005: ##
2006: ## Compile patched pwauth
2007: ##
2008: print_and_log(&mt('Compiling pwauth')."\n");
1.12 raeburn 2009: my $result = `cd $dir/; make 2>/dev/null `;
1.1 raeburn 2010: my $expected = <<"END";
2011: gcc -g -c -o pwauth.o pwauth.c
2012: gcc -o pwauth -g pwauth.o -lcrypt
2013: END
2014: if ($result eq $expected) {
2015: print_and_log(&mt('Apparent success compiling pwauth:').
2016: "\n".$result );
2017: # Install patched pwauth
2018: print_and_log(&mt('Copying pwauth to [_1]',' /usr/local/sbin')."\n");
2019: if (copy "$dir/pwauth","/usr/local/sbin/pwauth") {
1.5 raeburn 2020: if (chmod(06755, "/usr/local/sbin/pwauth")) {
1.1 raeburn 2021: print_and_log(&mt('[_1] copied successfully',"'pwauth'").
2022: "\n");
2023: } else {
2024: print &mt('Unable to set permissions on [_1].'.
2025: "/usr/local/sbin/pwauth")."\n";
2026: }
2027: } else {
2028: print &mt('Unable to copy [_1] to [_2]',
2029: "'$dir/pwauth'","/usr/local/sbin/pwauth")."\n$!\n";
2030: }
2031: } else {
2032: print &mt('Unable to compile patched [_1].'."'pwauth'")."\n";
2033: }
2034: } else {
2035: print &mt('Unable to start patch for [_1]',"'pwauth'")."\n";
2036: }
2037: print_and_log("\n");
2038: }
2039:
2040: sub kill_extra_services {
1.45 raeburn 2041: my ($distro,$stopsrvcs,$uses_systemctl) = @_;
1.1 raeburn 2042: if (ref($stopsrvcs) eq 'HASH') {
2043: my @stopping = sort(keys(%{$stopsrvcs}));
2044: if (@stopping) {
1.6 raeburn 2045: my $kill_list = join("', '",@stopping);
1.1 raeburn 2046: if ($kill_list) {
2047: $kill_list = "'".$kill_list."'";
1.6 raeburn 2048: &print_and_log("\n".&mt('Killing unnecessary services ([_1] daemon(s)).',$kill_list)."\n");
2049: foreach my $service (@stopping) {
2050: my $daemon = $service;
2051: if ($service eq 'cups') {
2052: $daemon = 'cupsd';
2053: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
2054: my $version = $1;
2055: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
2056: $daemon = 'cupsys';
2057: }
1.12 raeburn 2058: } else {
1.8 raeburn 2059: $daemon = 'cups';
1.6 raeburn 2060: }
2061: }
1.12 raeburn 2062: my $cmd = "ps -ef |grep '$daemon' |grep -v grep";
2063: if (open(PIPE,'-|',$cmd)) {
2064: my $daemonrunning = <PIPE>;
2065: chomp($daemonrunning);
2066: close(PIPE);
2067: if ($daemonrunning) {
2068: &print_and_log(`/etc/init.d/$daemon stop`);
2069: }
2070: }
1.1 raeburn 2071: &print_and_log(&mt('Removing [_1] from startup.',$service)."\n");
1.45 raeburn 2072: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
2073: my $version = $1;
2074: if (($distro =~ /^ubuntu/) && ($version > 16)) {
2075: if (ref($uses_systemctl) eq 'HASH') {
2076: if ($uses_systemctl->{$service}) {
2077: if (`systemctl is-enabled $service`) {
2078: &print_and_log(`systemctl disable $service`);
2079: }
2080: }
2081: }
2082: } else {
2083: &print_and_log(`update-rc.d -f $daemon remove`);
2084: }
1.1 raeburn 2085: } else {
1.35 raeburn 2086: if (ref($uses_systemctl) eq 'HASH') {
2087: if ($uses_systemctl->{$service}) {
2088: if (`systemctl is-enabled $service`) {
2089: &print_and_log(`systemctl disable $service`);
2090: }
2091: } else {
2092: &print_and_log(`/sbin/chkconfig --del $service`);
2093: }
2094: } else {
2095: &print_and_log(`/sbin/chkconfig --del $service`);
2096: }
1.1 raeburn 2097: }
2098: }
2099: }
2100: }
2101: }
2102: return;
2103: }
2104:
2105: sub setup_mysql {
1.45.2.9 raeburn 2106: my ($setup_mysql_permissions,$dbh,$has_pass,$mysql_unix_socket,$has_lcdb) = @_;
1.4 raeburn 2107: my @mysql_lc_commands;
1.1 raeburn 2108: unless ($has_lcdb) {
1.4 raeburn 2109: push(@mysql_lc_commands,"CREATE DATABASE loncapa");
1.1 raeburn 2110: }
1.4 raeburn 2111: push(@mysql_lc_commands,"USE loncapa");
2112: push(@mysql_lc_commands,qq{
1.18 raeburn 2113: 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 2114: });
1.1 raeburn 2115: if ($setup_mysql_permissions) {
1.45.2.9 raeburn 2116: &setup_mysql_permissions($dbh,$has_pass,$mysql_unix_socket,@mysql_lc_commands);
1.1 raeburn 2117: } else {
2118: print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
2119: if ($dbh) {
1.4 raeburn 2120: if (@mysql_lc_commands) {
2121: foreach my $lccmd (@mysql_lc_commands) {
2122: $dbh->do($lccmd) || print $dbh->errstr."\n";
2123: }
2124: }
1.1 raeburn 2125: print_and_log(&mt('MySQL database set up complete.')."\n");
2126: } else {
2127: print_and_log(&mt('Problem accessing MySQL.')."\n");
2128: }
2129: }
2130: }
2131:
2132: sub setup_mysql_permissions {
1.45.2.9 raeburn 2133: my ($dbh,$has_pass,$mysql_unix_socket,@mysql_lc_commands) = @_;
1.38 raeburn 2134: my ($mysqlversion,$mysqlsubver,$mysqlname) = &get_mysql_version();
1.45.2.9 raeburn 2135: my ($usescreate,$usesauth,$is_mariadb,$hasauthcol,@mysql_commands);
1.38 raeburn 2136: if ($mysqlname =~ /^MariaDB/i) {
1.45.2.2 raeburn 2137: $is_mariadb = 1;
1.45.2.9 raeburn 2138: if ($mysqlversion >= 10.4) {
2139: $usescreate = 1;
2140: } elsif ($mysqlversion >= 10.2) {
1.38 raeburn 2141: $usesauth = 1;
1.42 raeburn 2142: } elsif ($mysqlversion >= 5.5) {
2143: $hasauthcol = 1;
1.38 raeburn 2144: }
2145: } else {
2146: if (($mysqlversion > 5.7) || (($mysqlversion == 5.7) && ($mysqlsubver > 5))) {
2147: $usesauth = 1;
1.42 raeburn 2148: } elsif (($mysqlversion >= 5.6) || (($mysqlversion == 5.5) && ($mysqlsubver >= 7))) {
2149: $hasauthcol = 1;
1.38 raeburn 2150: }
2151: }
1.45.2.9 raeburn 2152: if ($usescreate) {
2153: @mysql_commands = ("CREATE USER 'www'\@'localhost' IDENTIFIED BY 'localhostkey'");
2154: } elsif ($usesauth) {
1.45.2.2 raeburn 2155: @mysql_commands = ("INSERT user (Host, User, ssl_cipher, x509_issuer, x509_subject, authentication_string) VALUES('localhost','www','','','','')");
2156: if ($is_mariadb) {
2157: push(@mysql_commands,"ALTER USER 'www'\@'localhost' IDENTIFIED BY 'localhostkey'");
2158: } else {
2159: push(@mysql_commands,"ALTER USER 'www'\@'localhost' IDENTIFIED WITH mysql_native_password BY 'localhostkey'");
2160: }
1.42 raeburn 2161: } elsif ($hasauthcol) {
2162: @mysql_commands = ("INSERT user (Host, User, Password, ssl_cipher, x509_issuer, x509_subject, authentication_string) VALUES('localhost','www',password('localhostkey'),'','','','');");
1.36 raeburn 2163: } else {
1.42 raeburn 2164: @mysql_commands = ("INSERT user (Host, User, Password, ssl_cipher, x509_issuer, x509_subject) VALUES('localhost','www',password('localhostkey'),'','','');");
1.36 raeburn 2165: }
1.1 raeburn 2166: if ($mysqlversion < 4) {
1.4 raeburn 2167: push (@mysql_commands,"
2168: 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')");
2169: } else {
2170: push (@mysql_commands,"
2171: 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 2172: }
1.4 raeburn 2173: push(@mysql_commands,"DELETE FROM user WHERE host<>'localhost'");
1.45.2.9 raeburn 2174: if (($has_pass) || ($mysql_unix_socket)) {
1.1 raeburn 2175: if ($dbh) {
1.4 raeburn 2176: push(@mysql_commands,"FLUSH PRIVILEGES");
2177: if (@mysql_commands) {
2178: foreach my $cmd (@mysql_commands) {
2179: $dbh->do($cmd) || print $dbh->errstr."\n";
2180: }
2181: }
2182: if (@mysql_lc_commands) {
2183: foreach my $lccmd (@mysql_lc_commands) {
2184: $dbh->do($lccmd) || print $dbh->errstr."\n";
2185: }
2186: }
1.1 raeburn 2187: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1]',"'www'")."\n");
2188: } else {
2189: print_and_log(&mt('Problem accessing MySQL.')."\n".
2190: &mt('Permissions not set.')."\n");
2191: }
2192: } else {
2193: my ($firstpass,$secondpass,$got_passwd,$newmysqlpass);
2194: print &mt('Please enter a root password for the mysql database.')."\n".
2195: &mt('It does not have to match your root account password, but you will need to remember it.')."\n";
2196: my $maxtries = 10;
2197: my $trial = 0;
2198: while ((!$got_passwd) && ($trial < $maxtries)) {
2199: $firstpass = &get_mysql_password(&mt('Enter password'));
2200: if (length($firstpass) > 5) {
2201: $secondpass = &get_mysql_password(&mt('Enter password a second time'));
2202: if ($firstpass eq $secondpass) {
2203: $got_passwd = 1;
2204: $newmysqlpass = $firstpass;
2205: } else {
2206: print(&mt('Passwords did not match. Please try again.')."\n");
2207: }
2208: $trial ++;
2209: } else {
2210: print(&mt('Password too short.')."\n".
2211: &mt('Please choose a password with at least six characters.')."\n");
2212: }
2213: }
2214: if ($got_passwd) {
1.45.2.2 raeburn 2215: my (@newpass_cmds) = &new_mysql_rootpasswd($newmysqlpass,$usesauth,$is_mariadb);
1.4 raeburn 2216: push(@mysql_commands,@newpass_cmds);
1.1 raeburn 2217: } else {
2218: print_and_log(&mt('Failed to get MySQL root password from user input.')."\n");
2219: }
2220: if ($dbh) {
1.4 raeburn 2221: if (@mysql_commands) {
2222: foreach my $cmd (@mysql_commands) {
2223: $dbh->do($cmd) || print $dbh->errstr."\n";
2224: }
2225: }
2226: if (@mysql_lc_commands) {
2227: foreach my $lccmd (@mysql_lc_commands) {
2228: $dbh->do($lccmd) || print $dbh->errstr."\n";
2229: }
2230: }
1.1 raeburn 2231: if ($got_passwd) {
2232: print_and_log(&mt('MySQL root password stored.')."\n".
2233: &mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
2234: } else {
2235: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
2236: }
2237: } else {
2238: print_and_log(&mt('Problem accessing MySQL.')."\n".
2239: &mt('Permissions not set.')."\n");
2240: }
2241: }
2242: }
2243:
2244: sub new_mysql_rootpasswd {
1.45.2.2 raeburn 2245: my ($currmysqlpass,$usesauth,$is_mariadb) = @_;
1.36 raeburn 2246: if ($usesauth) {
1.45.2.2 raeburn 2247: if ($is_mariadb) {
2248: return ("ALTER USER 'root'\@'localhost' IDENTIFIED BY '$currmysqlpass'",
2249: "FLUSH PRIVILEGES;");
2250: } else {
2251: return ("ALTER USER 'root'\@'localhost' IDENTIFIED WITH mysql_native_password BY '$currmysqlpass'",
2252: "FLUSH PRIVILEGES;");
2253: }
1.36 raeburn 2254: } else {
2255: return ("SET PASSWORD FOR 'root'\@'localhost'=PASSWORD('$currmysqlpass')",
2256: "FLUSH PRIVILEGES;");
2257: }
1.1 raeburn 2258: }
2259:
2260: sub get_mysql_version {
1.38 raeburn 2261: my ($version,$subversion,$name);
1.1 raeburn 2262: if (open(PIPE," mysql -V |")) {
2263: my $info = <PIPE>;
2264: chomp($info);
2265: close(PIPE);
1.45.2.7 raeburn 2266: ($version,$subversion,$name) = ($info =~ /(\d+\.\d+)\.(\d+)(?:\-?(\w*),|)/);
1.1 raeburn 2267: } else {
2268: print &mt('Could not determine which version of MySQL is installed.').
2269: "\n";
2270: }
1.38 raeburn 2271: return ($version,$subversion,$name);
1.1 raeburn 2272: }
2273:
2274: ###########################################################
2275: ##
2276: ## RHEL/CentOS/Fedora/Scientific Linux
2277: ## Copy LON-CAPA httpd.conf to /etc/httpd/conf
2278: ##
2279: ###########################################################
2280:
2281: sub copy_httpd_conf {
1.14 raeburn 2282: my ($instdir,$distro) = @_;
2283: my $configfile = 'httpd.conf';
1.45.2.3 raeburn 2284: if ($distro =~ /^(?:centos|rhes|scientific|oracle)(\d+)$/) {
1.29 raeburn 2285: if ($1 >= 7) {
2286: $configfile = 'apache2.4/httpd.conf';
2287: } elsif ($1 > 5) {
1.14 raeburn 2288: $configfile = 'new/httpd.conf';
2289: }
2290: } elsif ($distro =~ /^fedora(\d+)$/) {
1.29 raeburn 2291: if ($1 > 17) {
2292: $configfile = 'apache2.4/httpd.conf';
2293: } elsif ($1 > 10) {
1.14 raeburn 2294: $configfile = 'new/httpd.conf';
2295: }
2296: }
1.1 raeburn 2297: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'httpd.conf'",
2298: "'/etc/httpd/conf/httpd.conf'")."\n");
2299: copy "/etc/httpd/conf/httpd.conf","/etc/httpd/conf/httpd.conf.original";
1.14 raeburn 2300: copy "$instdir/centos-rhes-fedora-sl/$configfile","/etc/httpd/conf/httpd.conf";
1.5 raeburn 2301: chmod(0444,"/etc/httpd/conf/httpd.conf");
1.1 raeburn 2302: print_and_log("\n");
2303: }
2304:
1.45.2.5 raeburn 2305: ###########################################################
2306: ##
2307: ## RHEL/CentOS/Fedora/Scientific Linux
2308: ## Copy LON-CAPA mpm.conf to /etc/httpd/conf.modules.d/00-mpm.conf
2309: ##
2310: ## The LON-CAPA mpm.conf enables the prefork MPM module in
2311: ## Apache. This is also the default for RHEL/CentOS/Oracle
2312: ## Linux 7 and earlier, and Fedora 26 and earlier. For more
2313: ## recent versions of those distros, the event MPM is enabled
2314: ## by default. After ©_mpm_conf() is run, the prefork MPM
2315: ## module will be enabled instead of the event MPM module.
2316: ##
2317: ###########################################################
2318:
2319: sub copy_mpm_conf {
2320: my ($instdir,$distro) = @_;
2321: my $mpmfile = 'mpm.conf';
2322: if ((-e "/etc/httpd/conf.modules.d/00-mpm.conf") &&
2323: (-e "$instdir/centos-rhes-fedora-sl/$mpmfile")) {
2324: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'mpm.conf'",
2325: "'/etc/httpd/conf.modules.d/00-mpm.conf'")."\n");
2326: copy "$instdir/centos-rhes-fedora-sl/$mpmfile","/etc/httpd/conf.modules.d/00-mpm.conf";
2327: chmod(0644,"/etc/httpd/conf.modules.d/00-mpm.conf");
2328: print_and_log("\n");
2329: } else {
2330: my $logfail;
2331: if ($distro =~ /^(?:centos|rhes|scientific|oracle)(\d+)$/) {
2332: if ($1 > 7) {
2333: $logfail = 1;
2334: }
2335: } elsif ($distro =~ /^fedora(\d+)$/) {
2336: if ($1 > 26) {
2337: $logfail = 1;
2338: }
2339: }
2340: if ($logfail) {
2341: print_and_log(&mt('Warning: copying the LON-CAPA [_1] failed because [_2] and/or [_3] are missing.',
2342: $mpmfile,"'$instdir/centos-rhes-fedora-sl/$mpmfile'",
2343: "'/etc/httpd/conf.modules.d/00-mpm.conf'"));
2344: print_and_log("\n");
2345: }
2346: }
2347: }
2348:
1.1 raeburn 2349: #########################################################
2350: ##
1.17 raeburn 2351: ## Ubuntu/Debian -- copy our loncapa configuration file to
1.1 raeburn 2352: ## sites-available and set the symlink from sites-enabled.
2353: ##
2354: #########################################################
2355:
2356: sub copy_apache2_debconf {
1.28 raeburn 2357: my ($instdir,$distro) = @_;
1.6 raeburn 2358: my $apache2_mods_enabled_dir = '/etc/apache2/mods-enabled';
2359: my $apache2_mods_available_dir = '/etc/apache2/mods-available';
2360: foreach my $module ('headers.load','expires.load') {
2361: unless (-l "$apache2_mods_enabled_dir/$module") {
2362: symlink("$apache2_mods_available_dir/$module","$apache2_mods_enabled_dir/$module");
2363: print_and_log(&mt('Enabling "[_1]" Apache module.',$module)."\n");
2364: }
2365: }
1.28 raeburn 2366: my $apache2_sites_enabled_dir = '/etc/apache2/sites-enabled';
2367: my $apache2_sites_available_dir = '/etc/apache2/sites-available';
2368: my $defaultconfig = "$apache2_sites_enabled_dir/000-default";
1.45.2.10 raeburn 2369: my $defaultsite = "$apache2_sites_enabled_dir/loncapa.conf";
1.28 raeburn 2370: my ($distname,$version);
2371: if ($distro =~ /^(debian|ubuntu)(\d+)$/) {
2372: $distname = $1;
2373: $version = $2;
2374: }
2375: if (($distname eq 'ubuntu') && ($version > 12)) {
2376: $defaultconfig = "$apache2_sites_enabled_dir/000-default.conf";
2377: }
1.45.2.7 raeburn 2378: my ($skipconf,$skipsite,$skipstatus);
1.28 raeburn 2379: if (($distname eq 'ubuntu') && ($version > 12)) {
2380: my $apache2_conf_enabled_dir = '/etc/apache2/conf-enabled';
2381: my $apache2_conf_available_dir = '/etc/apache2/conf-available';
1.33 raeburn 2382: my $defaultconf = $apache2_conf_enabled_dir.'/loncapa.conf';
1.45.2.7 raeburn 2383: if ((-e "$apache2_conf_available_dir/loncapa") && (-e "$instdir/debian-ubuntu/ubuntu14/loncapa_conf")) {
1.45.2.8 raeburn 2384: if (open(PIPE, "diff --brief $apache2_conf_available_dir/loncapa $instdir/debian-ubuntu/ubuntu14/loncapa_conf |")) {
1.45.2.7 raeburn 2385: my $diffres = <PIPE>;
2386: close(PIPE);
2387: chomp($diffres);
2388: if ($diffres) {
1.45.2.10 raeburn 2389: copy("$apache2_conf_available_dir/loncapa","$apache2_conf_available_dir/loncapa.conf.original");
2390: } else {
2391: copy("$apache2_conf_available_dir/loncapa","$apache2_conf_available_dir/loncapa.conf");
1.45.2.11 raeburn 2392: chdir($apache2_conf_enabled_dir);
2393: symlink('../conf-available/loncapa.conf','loncapa.conf');
2394: chdir($instdir);
1.45.2.7 raeburn 2395: }
2396: if (-l $defaultconf) {
2397: my $linkfname = readlink($defaultconf);
1.45.2.11 raeburn 2398: if ($linkfname ne '') {
2399: $linkfname = Cwd::abs_path(File::Spec->rel2abs($linkfname,$apache2_conf_enabled_dir));
2400: }
1.45.2.7 raeburn 2401: if ($linkfname eq "$apache2_conf_available_dir/loncapa") {
1.45.2.10 raeburn 2402: unlink($defaultconf);
2403: }
2404: }
2405: unlink("$apache2_conf_available_dir/loncapa");
2406: }
2407: }
2408: if ((-e "$apache2_conf_available_dir/loncapa.conf") && (-e "$instdir/debian-ubuntu/ubuntu14/loncapa_conf")) {
2409: if (open(PIPE, "diff --brief $apache2_conf_available_dir/loncapa.conf $instdir/debian-ubuntu/ubuntu14/loncapa_conf |")) {
2410: my $diffres = <PIPE>;
2411: close(PIPE);
2412: chomp($diffres);
2413: if ($diffres) {
2414: copy("$apache2_conf_available_dir/loncapa.conf","$apache2_conf_available_dir/loncapa.conf.original");
2415: }
2416: if (-l $defaultconf) {
2417: my $linkfname = readlink($defaultconf);
1.45.2.11 raeburn 2418: if ($linkfname ne '') {
2419: $linkfname = Cwd::abs_path(File::Spec->rel2abs($linkfname,$apache2_conf_enabled_dir));
2420: }
1.45.2.10 raeburn 2421: if ($linkfname eq "$apache2_conf_available_dir/loncapa.conf") {
1.45.2.7 raeburn 2422: unless ($diffres) {
2423: $skipconf = 1;
2424: }
2425: }
2426: }
2427: }
2428: }
2429: unless ($skipconf) {
2430: 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 2431: copy("$instdir/debian-ubuntu/ubuntu14/loncapa_conf","$apache2_conf_available_dir/loncapa.conf");
2432: chmod(0444,"$apache2_conf_available_dir/loncapa.conf");
1.45.2.7 raeburn 2433: if (-l $defaultconf) {
2434: unlink($defaultconf);
2435: }
1.45.2.11 raeburn 2436: chdir($apache2_conf_enabled_dir);
2437: symlink('../conf-available/loncapa.conf','loncapa.conf');
2438: chdir($instdir);
1.45.2.7 raeburn 2439: }
2440: my $stdsite = "$instdir/debian-ubuntu/ubuntu14/loncapa_site";
2441: if ((-e $stdsite) && (-e "$apache2_sites_available_dir/loncapa")) {
2442: if (open(PIPE, "diff --brief $stdsite $apache2_sites_available_dir/loncapa |")) {
2443: my $diffres = <PIPE>;
2444: close(PIPE);
2445: chomp($diffres);
2446: if ($diffres) {
1.45.2.10 raeburn 2447: copy("$apache2_sites_available_dir/loncapa","$apache2_sites_available_dir/loncapa.conf.original");
2448: } else {
2449: copy("$apache2_sites_available_dir/loncapa","$apache2_sites_available_dir/loncapa.conf");
1.45.2.7 raeburn 2450: }
2451: if (-l $defaultconfig) {
2452: my $linkfname = readlink($defaultconfig);
1.45.2.11 raeburn 2453: if ($linkfname ne '') {
2454: $linkfname = Cwd::abs_path(File::Spec->rel2abs($linkfname,$apache2_sites_enabled_dir));
2455: }
1.45.2.7 raeburn 2456: if ($linkfname eq "$apache2_sites_available_dir/loncapa") {
1.45.2.10 raeburn 2457: unlink($defaultconfig);
2458: }
2459: }
2460: unlink("$apache2_sites_available_dir/loncapa");
2461: }
2462: }
2463: if ((-e $stdsite) && (-e "$apache2_sites_available_dir/loncapa.conf")) {
2464: if (open(PIPE, "diff --brief $stdsite $apache2_sites_available_dir/loncapa.conf |")) {
2465: my $diffres = <PIPE>;
2466: close(PIPE);
2467: chomp($diffres);
2468: if ($diffres) {
2469: copy("$apache2_sites_available_dir/loncapa.conf","$apache2_sites_available_dir/loncapa.conf.original");
2470: }
2471: if (-l $defaultsite) {
2472: my $linkfname = readlink($defaultsite);
1.45.2.11 raeburn 2473: if ($linkfname ne '') {
2474: $linkfname = Cwd::abs_path(File::Spec->rel2abs($linkfname,$apache2_sites_enabled_dir));
2475: }
2476: if ($linkfname eq "$apache2_sites_available_dir/loncapa.conf") {
1.45.2.7 raeburn 2477: unless ($diffres) {
2478: $skipsite = 1;
2479: }
2480: }
2481: }
2482: }
2483: }
2484: unless ($skipsite) {
1.45.2.10 raeburn 2485: 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");
2486: copy("$instdir/debian-ubuntu/ubuntu14/loncapa_site","$apache2_sites_available_dir/loncapa.conf");
2487: chmod(0444,"$apache2_sites_available_dir/loncapa.conf");
1.45.2.11 raeburn 2488: chdir($apache2_sites_enabled_dir);
2489: symlink('../sites-available/loncapa.conf','loncapa.conf');
2490: chdir($instdir);
1.45.2.10 raeburn 2491: }
1.45.2.11 raeburn 2492: if (-l $defaultconfig) {
1.45.2.10 raeburn 2493: my $linkfname = readlink($defaultconfig);
1.45.2.11 raeburn 2494: if ($linkfname ne '') {
2495: $linkfname = Cwd::abs_path(File::Spec->rel2abs($linkfname,$apache2_sites_enabled_dir));
2496: }
2497: if ($linkfname eq "$apache2_sites_available_dir/000-default.conf") {
1.45.2.10 raeburn 2498: unlink($defaultconfig);
2499: }
1.45.2.7 raeburn 2500: }
2501: } else {
2502: if ((-e "$instdir/debian-ubuntu/loncapa") && (-e "$apache2_sites_available_dir/loncapa")) {
2503: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/loncapa $apache2_sites_available_dir/loncapa |")) {
2504: my $diffres = <PIPE>;
2505: close(PIPE);
2506: chomp($diffres);
2507: if ($diffres) {
2508: copy("$apache2_sites_available_dir/loncapa","$apache2_sites_available_dir/loncapa.original");
2509: }
2510: if (-l $defaultconfig) {
2511: my $linkfname = readlink($defaultconfig);
2512: if ($linkfname eq "$apache2_sites_available_dir/loncapa") {
2513: unless ($diffres) {
2514: $skipsite = 1;
2515: }
2516: }
2517: }
2518: }
2519: }
2520: unless ($skipsite) {
2521: if (-l $defaultconfig) {
2522: unlink($defaultconfig);
2523: }
2524: 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");
2525: if (-e "$instdir/debian-ubuntu/loncapa") {
2526: copy("$instdir/debian-ubuntu/loncapa","$apache2_sites_available_dir/loncapa");
2527: chmod(0444,"$apache2_sites_available_dir/loncapa");
2528: symlink("$apache2_sites_available_dir/loncapa","$apache2_sites_enabled_dir/000-default");
2529: }
2530: }
2531: }
2532: if ($distname eq 'ubuntu') {
2533: my $sitestatus = "$apache2_mods_available_dir/status.conf";
2534: my $stdstatus = "$instdir/debian-ubuntu/status.conf";
2535: if ((-e $sitestatus) && (-e $stdstatus)) {
2536: if (open(PIPE, "diff --brief $stdstatus $sitestatus |")) {
2537: my $diffres = <PIPE>;
2538: close(PIPE);
2539: chomp($diffres);
2540: if ($diffres) {
2541: copy("$apache2_mods_available_dir/status.conf","$apache2_mods_available_dir/status.conf.original");
2542: } else {
2543: $skipstatus = 1;
2544: }
2545: }
2546: }
2547: unless ($skipstatus) {
2548: if (-e $stdstatus) {
2549: print_and_log(&mt('Copying loncapa [_1] file to [_2],',"'status.conf'","'/etc/apache2/mods-available/status.conf'")."\n");
2550: copy($stdstatus,$sitestatus);
2551: chmod(0644,$sitestatus);
2552: }
2553: }
1.28 raeburn 2554: }
1.1 raeburn 2555: print_and_log("\n");
2556: }
2557:
2558: ###########################################################
2559: ##
2560: ## openSuSE/SLES Copy apache2 config files:
2561: ## default-server.conf, uid.conf, /etc/sysconfig/apache2
2562: ## and create symlink from /srv/www/conf to /etc/apache2
2563: ##
2564: ###########################################################
2565:
2566: sub copy_apache2_suseconf {
1.45.2.1 raeburn 2567: my ($instdir,$distro) = @_;
2568: my ($name,$version) = ($distro =~ /^(suse|sles)([\d\.]+)$/);
2569: my $conf_file = "$instdir/sles-suse/default-server.conf";
2570: if (($name eq 'sles') && ($version >= 12)) {
2571: $conf_file = "$instdir/sles-suse/apache2.4/default-server.conf";
2572: }
1.1 raeburn 2573: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
2574: "'default-server.conf'",
2575: "'/etc/apache2/default-server.conf'")."\n");
2576: if (!-e "/etc/apache2/default-server.conf.original") {
2577: copy "/etc/apache2/default-server.conf","/etc/apache2/default-server.conf.original";
2578: }
1.45.2.1 raeburn 2579: copy $conf_file,"/etc/apache2/default-server.conf";
1.5 raeburn 2580: chmod(0444,"/etc/apache2/default-server.conf");
1.1 raeburn 2581: # Make symlink for conf directory (included in loncapa_apache.conf)
2582: my $can_symlink = (eval { symlink('/etc/apache2','/srv/www/conf'); }, $@ eq '');
2583: if ($can_symlink) {
2584: &print_and_log(&mt('Symlink created for [_1] to [_2].',
2585: "'/srv/www/conf'","'/etc/apache2'")."\n");
2586: } else {
2587: &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");
2588: }
2589: ©_apache2_conf_files($instdir);
1.45.2.1 raeburn 2590: ©_sysconfig_apache2_file($instdir,$name,$version);
1.1 raeburn 2591: print_and_log("\n");
2592: }
2593:
2594: ###############################################
2595: ##
2596: ## Modify uid.conf
2597: ##
2598: ###############################################
2599: sub copy_apache2_conf_files {
2600: my ($instdir) = @_;
2601: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
2602: "'uid.conf'","'/etc/apache2/uid.conf'")."\n");
2603: if (!-e "/etc/apache2/uid.conf.original") {
2604: copy "/etc/apache2/uid.conf","/etc/apache2/uid.conf.original";
2605: }
1.9 raeburn 2606: copy "$instdir/sles-suse/uid.conf","/etc/apache2/uid.conf";
1.5 raeburn 2607: chmod(0444,"/etc/apache2/uid.conf");
1.1 raeburn 2608: }
2609:
2610: ###############################################
2611: ##
2612: ## Modify /etc/sysconfig/apache2
2613: ##
2614: ###############################################
2615: sub copy_sysconfig_apache2_file {
1.45.2.1 raeburn 2616: my ($instdir,$name,$version) = @_;
1.1 raeburn 2617: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'sysconfig/apache2'","'/etc/sysconfig/apache2'")."\n");
2618: if (!-e "/etc/sysconfig/apache2.original") {
2619: copy "/etc/sysconfig/apache2","/etc/sysconfig/apache2.original";
2620: }
1.45.2.1 raeburn 2621: my $sysconf_file = "$instdir/sles-suse/sysconfig_apache2";
2622: if (($name eq 'sles') && ($version >= 12)) {
2623: $sysconf_file = "$instdir/sles-suse/apache2.4/sysconfig_apache2";
2624: }
2625: copy $sysconf_file,"/etc/sysconfig/apache2";
1.5 raeburn 2626: chmod(0444,"/etc/sysconfig/apache2");
1.1 raeburn 2627: }
2628:
2629: ###############################################
2630: ##
2631: ## Add/Modify /etc/insserv/overrides
2632: ##
2633: ###############################################
2634:
2635: sub update_SuSEfirewall2_setup {
2636: my ($instdir) = @_;
2637: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'SuSEfirewall2_setup'","'/etc/insserv/overrides/SuSEfirewall2_setup'")."\n");
2638: if (!-e "/etc/insserv/overrides/SuSEfirewall2_setup") {
2639: if (!-d "/etc/insserv") {
2640: mkdir("/etc/insserv",0755);
2641: }
2642: if (!-d "/etc/insserv/overrides") {
2643: mkdir("/etc/insserv/overrides",0755);
2644: }
2645: } elsif (!-e "/etc/insserv/overrides/SuSEfirewall2_setup.original") {
2646: copy "/etc/insserv/overrides/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup.original"
2647: }
1.9 raeburn 2648: copy "$instdir/sles-suse/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup";
1.5 raeburn 2649: chmod(0444,"/etc/insserv/overrides/SuSEfirewall2_setup");
2650: }
2651:
2652: sub get_iptables_rules {
2653: my ($distro,$instdir,$apachefw) = @_;
2654: my (@fwchains,@ports);
2655: if (&firewall_is_active()) {
2656: my $iptables = &get_pathto_iptables();
2657: if ($iptables ne '') {
2658: @fwchains = &get_fw_chains($iptables,$distro);
2659: }
2660: }
2661: if (ref($apachefw) eq 'HASH') {
2662: foreach my $service ('http','https') {
2663: unless ($apachefw->{$service}) {
2664: push (@ports,$service);
2665: }
2666: }
2667: } else {
2668: @ports = ('http','https');
2669: }
2670: if (@ports == 0) {
2671: return;
2672: }
2673: my $ask_to_enable;
2674: if (-e "/etc/iptables.loncapa.rules") {
1.9 raeburn 2675: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables.loncapa.rules /etc/iptables.loncapa.rules |")) {
1.5 raeburn 2676: my $diffres = <PIPE>;
2677: close(PIPE);
2678: chomp($diffres);
2679: if ($diffres) {
2680: print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
2681: }
2682: } else {
2683: print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
2684: }
2685: } else {
1.9 raeburn 2686: if (-e "$instdir/debian-ubuntu/iptables.loncapa.rules") {
2687: copy "$instdir/debian-ubuntu/iptables.loncapa.rules","/etc/iptables.loncapa.rules";
1.5 raeburn 2688: chmod(0600,"/etc/iptables.loncapa.rules");
2689: }
2690: }
2691: if (-e "/etc/iptables.loncapa.rules") {
2692: if (-e "/etc/network/if-pre-up.d/iptables") {
1.9 raeburn 2693: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables /etc/network/if-pre-up/iptables |")) {
1.5 raeburn 2694: my $diffres = <PIPE>;
2695: close(PIPE);
2696: chomp($diffres);
2697: if ($diffres) {
2698: print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
2699: }
2700: } else {
2701: print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
2702: }
2703: } else {
1.9 raeburn 2704: copy "$instdir/debian-ubuntu/iptables","/etc/network/if-pre-up.d/iptables";
1.5 raeburn 2705: chmod(0755,"/etc/network/if-pre-up.d/iptables");
2706: 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'));
2707: $ask_to_enable = 1;
2708: }
2709: }
2710: return $ask_to_enable;
1.1 raeburn 2711: }
2712:
2713: sub download_loncapa {
2714: my ($instdir,$lctarball) = @_;
2715: my ($have_tarball,$updateshown);
2716: if (! -e "$instdir/$lctarball") {
2717: print_and_log(&mt('Retrieving LON-CAPA source files from: [_1]',
2718: 'http://install.loncapa.org')."\n");
2719: system("wget http://install.loncapa.org/versions/$lctarball ".
2720: "2>/dev/null 1>/dev/null");
2721: if (! -e "./$lctarball") {
2722: print &mt('Unable to retrieve LON-CAPA source files from: [_1].',
2723: "http://install.loncapa.org/versions/$lctarball")."\n";
2724: } else {
2725: $have_tarball = 1;
2726: }
2727: print_and_log("\n");
2728: } else {
2729: $have_tarball = 1;
2730: print_and_log("
2731: ------------------------------------------------------------------------
2732:
2733: ".&mt('You seem to have a version of loncapa-current.tar.gz in [_1]',$instdir)."\n".
2734: &mt('This copy will be used and a new version will NOT be downloaded.')."\n".
2735: &mt('If you wish, you may download a new version by executing:')."
2736:
1.2 raeburn 2737: wget http://install.loncapa.org/versions/loncapa-current.tar.gz
1.1 raeburn 2738:
2739: ------------------------------------------------------------------------
2740: ");
2741: }
2742:
2743: ##
2744: ## untar loncapa.tar.gz
2745: ##
2746: if ($have_tarball) {
2747: print_and_log(&mt('Extracting LON-CAPA source files')."\n");
2748: writelog(`cd ~root; tar zxf $instdir/$lctarball`);
2749: print_and_log("\n");
2750: print &mt('LON-CAPA source files extracted.')."\n".
2751: &mt('It remains for you to execute the following commands:')."
2752:
1.45.2.7 raeburn 2753: cd /root/loncapa-X.Y.Z (X.Y.Z should correspond to a version number like '2.11.3')
1.1 raeburn 2754: ./UPDATE
2755:
2756: ".&mt('If you have any trouble, please see [_1] and [_2]',
2757: 'http://install.loncapa.org/','http://help.loncapa.org/')."\n";
2758: $updateshown = 1;
2759: }
2760: return ($have_tarball,$updateshown);
2761: }
2762:
2763: close LOG;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>