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