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