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