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