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