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