Annotation of doc/install/linux/install.pl, revision 1.79
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;
1.47 raeburn 29: use Socket;
1.46 raeburn 30: use Sys::Hostname::FQDN();
1.1 raeburn 31: use DBI;
1.70 raeburn 32: use File::Spec;
1.43 raeburn 33: use Cwd();
34: use File::Basename();
35: use lib File::Basename::dirname(Cwd::abs_path($0));
1.1 raeburn 36: use LCLocalization::localize;
37:
38: # ========================================================= The language handle
39:
40: my %languages = (
41: ar => 'Arabic',
42: de => 'German',
43: en => 'English',
44: es => 'Spanish (Castellan)',
45: fa => 'Persian',
46: fr => 'French',
47: he => 'Hebrew',
48: ja => 'Japanese',
49: pt => 'Portuguese',
50: ru => 'Russian',
51: tr => 'Turkish',
52: zh => 'Chinese Simplified'
53: );
54:
55: use vars qw($lh $lang);
56: $lang = 'en';
57: if (@ARGV > 0) {
58: foreach my $poss (keys(%languages)) {
59: if ($ARGV[0] eq $poss) {
60: $lang = $ARGV[0];
61: }
62: }
63: }
64:
65: &get_language_handle($lang);
66:
67: # Check user has root privs
68: if (0 != $<) {
69: print &mt('This script must be run as root.')."\n".
70: &mt('Stopping execution.')."\n";
71: exit;
72: }
73:
74:
75: # Globals: filehandle LOG is global.
76: if (!open(LOG,">>loncapa_install.log")) {
77: print &mt('Unable to open log file.')."\n".
78: &mt('Stopping execution.')."\n";
79: exit;
80: } else {
1.79 ! raeburn 81: print LOG '$Id: install.pl,v 1.78 2021/07/28 13:37:10 raeburn Exp $'."\n";
1.1 raeburn 82: }
83:
84: #
1.2 raeburn 85: # Helper routines and routines to establish recommended actions
1.1 raeburn 86: #
87:
88: sub get_language_handle {
89: my @languages = @_;
90: $lh=LCLocalization::localize->get_handle(@languages);
91: }
92:
93: sub mt (@) {
94: if ($lh) {
95: if ($_[0] eq '') {
96: if (wantarray) {
97: return @_;
98: } else {
99: return $_[0];
100: }
101: } else {
102: return $lh->maketext(@_);
103: }
104: } else {
105: if (wantarray) {
106: return @_;
107: } else {
108: return $_[0];
109: }
110: }
111: }
112:
113: sub texthash {
114: my (%hash) = @_;
115: foreach (keys(%hash)) {
116: $hash{$_}=&mt($hash{$_});
117: }
118: return %hash;
119: }
120:
121:
122: sub skip_if_nonempty {
123: my ($string,$error)=@_;
124: return if (! defined($error));
125: chomp($string);chomp($error);
126: if ($string ne '') {
127: print_and_log("$error\n".&mt('Stopping execution.')."\n");
128: return 1;
129: }
130: return;
131: }
132:
133: sub writelog {
134: while ($_ = shift) {
135: chomp();
136: print LOG "$_\n";
137: }
138: }
139:
140: sub print_and_log {
141: while ($_=shift) {
142: chomp();
143: print "$_\n";
144: print LOG "$_\n";
145: }
146: }
147:
148: sub get_user_selection {
149: my ($defaultrun) = @_;
150: my $do_action = 0;
151: my $choice = <STDIN>;
152: chomp($choice);
153: $choice =~ s/(^\s+|\s+$)//g;
154: my $yes = &mt('y');
155: if ($defaultrun) {
156: if (($choice eq '') || ($choice =~ /^\Q$yes\E/i)) {
157: $do_action = 1;
158: }
159: } else {
160: if ($choice =~ /^\Q$yes\E/i) {
161: $do_action = 1;
162: }
163: }
164: return $do_action;
165: }
166:
167: sub get_distro {
1.49 raeburn 168: my ($distro,$gotprereqs,$updatecmd,$packagecmd,$installnow,$unknown);
1.1 raeburn 169: $packagecmd = '/bin/rpm -q LONCAPA-prerequisites ';
1.55 raeburn 170: if (-e '/etc/oracle-release') {
171: open(IN,'</etc/oracle-release');
172: my $versionstring=<IN>;
173: chomp($versionstring);
174: close(IN);
175: if ($versionstring =~ /^Oracle Linux Server release (\d+)/) {
176: my $version = $1;
177: $distro = 'oracle'.$1;
178: $updatecmd = 'yum install LONCAPA-prerequisites';
179: $installnow = 'yum -y install LONCAPA-prerequisites';
180: }
181: } elsif (-e '/etc/redhat-release') {
1.1 raeburn 182: open(IN,'</etc/redhat-release');
183: my $versionstring=<IN>;
184: chomp($versionstring);
185: close(IN);
186: if ($versionstring =~ /^Red Hat Linux release ([\d\.]+) /) {
187: my $version = $1;
188: if ($version=~/^7\./) {
189: $distro='redhat7';
190: } elsif ($version=~/^8\./) {
191: $distro='redhat8';
192: } elsif ($version=~/^9/) {
193: $distro='redhat9';
194: }
195: } elsif ($versionstring =~ /Fedora( Core)? release ([\d\.]+) /) {
196: my $version=$2;
197: if ($version - int($version) > .9) {
198: $distro = 'fedora'.(int($version)+1);
199: } else {
200: $distro = 'fedora'.int($version);
201: }
202: $updatecmd = 'yum install LONCAPA-prerequisites';
203: $installnow = 'yum -y install LONCAPA-prerequisites';
204: } elsif ($versionstring =~ /Red Hat Enterprise Linux [AE]S release ([\d\.]+) /) {
205: $distro = 'rhes'.$1;
206: $updatecmd = 'up2date -i LONCAPA-prerequisites';
207: } elsif ($versionstring =~ /Red Hat Enterprise Linux Server release (\d+)/) {
208: $distro = 'rhes'.$1;
209: $updatecmd = 'yum install LONCAPA-prerequisites';
210: $installnow = 'yum -y install LONCAPA-prerequisites';
1.54 raeburn 211: } elsif ($versionstring =~ /Red Hat Enterprise Linux release (\d+)/) {
212: $distro = 'rhes'.$1;
213: $updatecmd = 'dnf install LONCAPA-prerequisites';
214: $installnow = 'dnf -y install LONCAPA-prerequisites';
1.73 raeburn 215: } elsif ($versionstring =~ /CentOS(?:| Linux| Stream) release (\d+)/) {
1.1 raeburn 216: $distro = 'centos'.$1;
217: $updatecmd = 'yum install LONCAPA-prerequisites';
218: $installnow = 'yum -y install LONCAPA-prerequisites';
1.22 raeburn 219: } elsif ($versionstring =~ /Scientific Linux (?:SL )?release ([\d.]+) /) {
1.1 raeburn 220: my $ver = $1;
221: $ver =~ s/\.\d+$//;
222: $distro = 'scientific'.$ver;
223: $updatecmd = 'yum install LONCAPA-prerequisites';
224: $installnow = 'yum -y install LONCAPA-prerequisites';
1.79 ! raeburn 225: } elsif ($versionstring =~ /Rocky Linux release ([\d.]+)/) {
! 226: my $ver = $1;
! 227: $ver =~ s/\.\d+$//;
! 228: $distro = 'rocky'.$ver;
! 229: $updatecmd = 'dnf install LONCAPA-prerequisites';
! 230: $installnow = 'dnf -y install LONCAPA-prerequisites';
! 231: } elsif ($versionstring =~ /AlmaLinux release ([\d.]+) /) {
! 232: my $ver = $1;
! 233: $ver =~ s/\.\d+$//;
! 234: $distro = 'alma'.$ver;
! 235: $updatecmd = 'dnf install LONCAPA-prerequisites';
! 236: $installnow = 'dnf -y install LONCAPA-prerequisites';
1.1 raeburn 237: } else {
238: print &mt('Unable to interpret [_1] to determine system type.',
239: '/etc/redhat-release')."\n";
1.49 raeburn 240: $unknown = 1;
1.1 raeburn 241: }
242: } elsif (-e '/etc/SuSE-release') {
243: open(IN,'</etc/SuSE-release');
244: my $versionstring=<IN>;
245: chomp($versionstring);
246: close(IN);
247: if ($versionstring =~ /^SUSE LINUX Enterprise Server ([\d\.]+) /i) {
248: $distro='sles'.$1;
249: if ($1 >= 10) {
250: $updatecmd = 'zypper install LONCAPA-prerequisites';
251: } else {
252: $updatecmd = 'yast -i LONCAPA-prerequisites';
253: }
254: } elsif ($versionstring =~ /^SuSE Linux ([\d\.]+) /i) {
255: $distro = 'suse'.$1;
1.12 raeburn 256: $updatecmd = 'yast -i LONCAPA-prerequisites';
1.1 raeburn 257: } elsif ($versionstring =~ /^openSUSE ([\d\.]+) /i) {
258: $distro = 'suse'.$1;
259: if ($1 >= 10.3 ) {
260: $updatecmd = 'zypper install LONCAPA-prerequisites';
261: } else {
262: $updatecmd = 'yast -i LONCAPA-prerequisites';
263: }
264: } else {
265: print &mt('Unable to interpret [_1] to determine system type.',
266: '/etc/SuSE-release')."\n";
1.49 raeburn 267: $unknown = 1;
1.1 raeburn 268: }
269: } elsif (-e '/etc/issue') {
270: open(IN,'</etc/issue');
271: my $versionstring=<IN>;
272: chomp($versionstring);
273: close(IN);
274: if ($versionstring =~ /^Ubuntu (\d+)\.\d+/i) {
275: $distro = 'ubuntu'.$1;
276: $updatecmd = 'sudo apt-get install loncapa-prerequisites';
277: } elsif ($versionstring =~ /^Debian\s+GNU\/Linux\s+(\d+)\.\d+/i) {
278: $distro = 'debian'.$1;
1.49 raeburn 279: $updatecmd = 'apt-get install loncapa-prerequisites';
1.1 raeburn 280: } elsif (-e '/etc/debian_version') {
281: open(IN,'</etc/debian_version');
282: my $version=<IN>;
283: chomp($version);
284: close(IN);
285: if ($version =~ /^(\d+)\.\d+\.?\d*/) {
286: $distro='debian'.$1;
1.49 raeburn 287: $updatecmd = 'apt-get install loncapa-prerequisites';
1.1 raeburn 288: } else {
289: print &mt('Unable to interpret [_1] to determine system type.',
290: '/etc/debian_version')."\n";
1.49 raeburn 291: $unknown = 1;
1.1 raeburn 292: }
1.49 raeburn 293: }
294: if ($distro ne '') {
295: $packagecmd = '/usr/bin/dpkg -l loncapa-prerequisites ';
1.1 raeburn 296: }
297: } elsif (-e '/etc/debian_version') {
298: open(IN,'</etc/debian_version');
299: my $version=<IN>;
300: chomp($version);
301: close(IN);
302: if ($version =~ /^(\d+)\.\d+\.?\d*/) {
303: $distro='debian'.$1;
304: $packagecmd = '/usr/bin/dpkg -l loncapa-prerequisites ';
305: $updatecmd = 'apt-get install loncapa-prerequisites';
306: } else {
307: print &mt('Unable to interpret [_1] to determine system type.',
308: '/etc/debian_version')."\n";
1.49 raeburn 309: $unknown = 1;
310: }
311: }
312: if (($distro eq '') && (!$unknown)) {
313: if (-e '/etc/os-release') {
314: if (open(IN,'<','/etc/os-release')) {
315: my ($id,$version);
316: while(<IN>) {
317: chomp();
318: if (/^ID="(\w+)"/) {
319: $id=$1;
320: } elsif (/^VERSION_ID="([\d\.]+)"/) {
321: $version=$1;
322: }
323: }
324: close(IN);
325: if ($id eq 'sles') {
326: my ($major,$minor) = split(/\./,$version);
327: if ($major =~ /^\d+$/) {
328: $distro = $id.$major;
329: $updatecmd = 'zypper install LONCAPA-prerequisites';
330: }
331: }
332: }
333: if ($distro eq '') {
334: print &mt('Unable to interpret [_1] to determine system type.',
335: '/etc/os-release')."\n";
336: $unknown = 1;
337: }
338: } else {
1.55 raeburn 339: print &mt('Unknown installation: expecting a debian, ubuntu, suse, sles, redhat, fedora, scientific linux, or oracle linux system.')."\n";
1.1 raeburn 340: }
341: }
342: return ($distro,$packagecmd,$updatecmd,$installnow);
343: }
344:
1.47 raeburn 345: #
346: # get_hostname() prompts the user to provide the server's hostname.
347: #
348: # If invalid input is provided, the routine is called recursively
349: # until, a valid hostname is provided.
350: #
351:
1.46 raeburn 352: sub get_hostname {
353: my $hostname;
354: print &mt('Enter the hostname of this server, e.g., loncapa.somewhere.edu'."\n");
355: my $choice = <STDIN>;
356: chomp($choice);
357: $choice =~ s/(^\s+|\s+$)//g;
358: if ($choice eq '') {
359: print &mt("Hostname you entered was either blank or contanied only white space.\n");
360: } elsif ($choice =~ /^[\w\.\-]+$/) {
361: $hostname = $choice;
362: } else {
363: print &mt("Hostname you entered was invalid -- a hostname may only contain letters, numbers, - and .\n");
364: }
365: while ($hostname eq '') {
366: $hostname = &get_hostname();
367: }
368: print "\n";
369: return $hostname;
370: }
371:
1.47 raeburn 372: #
1.62 raeburn 373: # get_hostip() prompts the user to provide the server's IPv4 IP address
1.47 raeburn 374: #
375: # If invalid input is provided, the routine is called recursively
376: # until, a valid IPv4 address is provided.
377: #
378:
379: sub get_hostip {
380: my $hostip;
381: print &mt('Enter the IP address of this server, e.g., 192.168.10.24'."\n");
382: my $choice = <STDIN>;
383: chomp($choice);
384: $choice =~ s/(^\s+|\s+$)//g;
385: my $badformat = 1;
386: if ($choice eq '') {
387: print &mt("IP address you entered was either blank or contained only white space.\n");
388: } else {
389: if ($choice =~ /^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/) {
390: if (($1<=255) && ($2<=255) && ($3<=255) && ($4<=255)) {
391: $badformat = 0;
392: }
393: }
394: if ($badformat) {
395: print &mt('Host IP you entered was invalid -- a host IP has the format d.d.d.d where each d is an integer between 0 and 255')."\n";
396: } else {
397: $hostip = $choice;
398: }
399: }
400: while ($hostip eq '') {
401: $hostip = &get_hostip();
402: }
403: print "\n";
404: return $hostip;
405: }
406:
1.1 raeburn 407: sub check_prerequisites {
408: my ($packagecmd,$distro) = @_;
409: my $gotprereqs;
410: if ($packagecmd ne '') {
411: if (open(PIPE,"$packagecmd|")) {
412: if ($distro =~ /^(debian|ubuntu)/) {
413: my @lines = <PIPE>;
414: chomp(@lines);
415: foreach my $line (@lines) {
416: if ($line =~ /^ii\s+loncapa-prerequisites\s+([\w\.]+)/) {
417: $gotprereqs = $1;
418: }
419: }
420: } else {
421: my $line = <PIPE>;
422: chomp($line);
1.8 raeburn 423: if ($line =~ /^LONCAPA\-prerequisites\-([\d\-]+)\.(?:[.\w]+)$/) {
1.1 raeburn 424: $gotprereqs = $1;
425: }
426: }
427: close(PIPE);
428: } else {
429: print &mt('Error: could not determine if LONCAPA-prerequisites package is installed')."\n";
430: }
431: }
432: return $gotprereqs;
433: }
434:
1.6 raeburn 435: sub check_locale {
436: my ($distro) = @_;
1.63 raeburn 437: my ($fh,$langvar,$command,$earlyout);
1.8 raeburn 438: $langvar = 'LANG';
1.6 raeburn 439: if ($distro =~ /^(ubuntu|debian)/) {
440: if (!open($fh,"</etc/default/locale")) {
441: print &mt('Failed to open: [_1], default locale not checked.',
442: '/etc/default/locale');
1.63 raeburn 443: $earlyout = 1;
1.6 raeburn 444: }
1.49 raeburn 445: } elsif ($distro =~ /^(suse|sles)(\d+)/) {
446: if (($1 eq 'sles') && ($2 >= 15)) {
447: if (!open($fh,"</etc/locale.conf")) {
448: print &mt('Failed to open: [_1], default locale not checked.',
449: '/etc/locale.conf');
1.63 raeburn 450: $earlyout = 1;
1.49 raeburn 451: }
452: } else {
453: if (!open($fh,"</etc/sysconfig/language")) {
454: print &mt('Failed to open: [_1], default locale not checked.',
455: '/etc/sysconfig/language');
1.63 raeburn 456: $earlyout = 1;
1.49 raeburn 457: }
458: $langvar = 'RC_LANG';
1.8 raeburn 459: }
1.24 raeburn 460: } elsif ($distro =~ /^fedora(\d+)/) {
461: if ($1 >= 18) {
462: if (!open($fh,"</etc/locale.conf")) {
463: print &mt('Failed to open: [_1], default locale not checked.',
464: '/etc/locale.conf');
1.63 raeburn 465: $earlyout = 1;
1.24 raeburn 466: }
467: } elsif (!open($fh,"</etc/sysconfig/i18n")) {
468: print &mt('Failed to open: [_1], default locale not checked.',
469: '/etc/sysconfig/i18n');
1.66 raeburn 470: $earlyout = 1;
1.24 raeburn 471: }
1.56 raeburn 472: } elsif ($distro =~ /^(?:rhes|centos|scientific|oracle)(\d+)/) {
1.29 raeburn 473: if ($1 >= 7) {
474: if (!open($fh,"</etc/locale.conf")) {
475: print &mt('Failed to open: [_1], default locale not checked.',
476: '/etc/locale.conf');
1.63 raeburn 477: $earlyout = 1;
1.29 raeburn 478: }
479: } elsif (!open($fh,"</etc/sysconfig/i18n")) {
480: print &mt('Failed to open: [_1], default locale not checked.',
481: '/etc/sysconfig/i18n');
1.63 raeburn 482: $earlyout = 1;
1.29 raeburn 483: }
1.6 raeburn 484: } else {
485: if (!open($fh,"</etc/sysconfig/i18n")) {
486: print &mt('Failed to open: [_1], default locale not checked.',
487: '/etc/sysconfig/i18n');
1.63 raeburn 488: $earlyout = 1;
1.6 raeburn 489: }
490: }
1.63 raeburn 491: return if ($earlyout);
1.6 raeburn 492: my @data = <$fh>;
493: chomp(@data);
494: foreach my $item (@data) {
1.25 raeburn 495: if ($item =~ /^\Q$langvar\E=\"?([^\"]*)\"?/) {
1.6 raeburn 496: my $default = $1;
497: if ($default ne 'en_US.UTF-8') {
498: if ($distro =~ /^debian/) {
1.25 raeburn 499: $command = 'locale-gen en_US.UTF-8'."\n".
500: 'update-locale LANG=en_US.UTF-8';
1.6 raeburn 501: } elsif ($distro =~ /^ubuntu/) {
1.25 raeburn 502: $command = 'sudo locale-gen en_US.UTF-8'."\n".
503: 'sudo update-locale LANG=en_US.UTF-8';
1.7 raeburn 504: } elsif ($distro =~ /^(suse|sles)/) {
1.57 raeburn 505: $command = 'yast language';
1.54 raeburn 506: } elsif (-e '/usr/bin/system-config-language') {
507: $command = 'system-config-language';
508: } elsif (-e '/usr/bin/localectl') {
1.58 raeburn 509: $command = '/usr/bin/localectl set-locale LANG=en_US.UTF-8';
1.6 raeburn 510: } else {
1.54 raeburn 511: $command = 'No standard command found';
1.6 raeburn 512: }
513: }
514: last;
515: }
516: }
517: close($fh);
518: return $command;
519: }
520:
1.1 raeburn 521: sub check_required {
522: my ($instdir,$dsn) = @_;
523: my ($distro,$packagecmd,$updatecmd,$installnow) = &get_distro();
524: if ($distro eq '') {
525: return;
526: }
527: my $gotprereqs = &check_prerequisites($packagecmd,$distro);
528: if ($gotprereqs eq '') {
1.22 raeburn 529: return ($distro,$gotprereqs,'',$packagecmd,$updatecmd);
1.6 raeburn 530: }
531: my $localecmd = &check_locale($distro);
532: unless ($localecmd eq '') {
533: return ($distro,$gotprereqs,$localecmd);
1.1 raeburn 534: }
1.68 raeburn 535: my ($mysqlon,$mysqlsetup,$mysqlrestart,$dbh,$has_pass,$mysql_unix_socket,$has_lcdb,
536: %recommended,$downloadstatus,$filetouse,$production,$testing,$apachefw,
1.71 raeburn 537: $tostop,$uses_systemctl,$mysql_has_wwwuser,$hostname,$hostip);
1.1 raeburn 538: my $wwwuid = &uid_of_www();
539: my $wwwgid = getgrnam('www');
540: if (($wwwuid eq '') || ($wwwgid eq '')) {
541: $recommended{'wwwuser'} = 1;
542: }
543: unless( -e "/usr/local/sbin/pwauth") {
544: $recommended{'pwauth'} = 1;
545: }
1.47 raeburn 546: $hostname = Sys::Hostname::FQDN::fqdn();
1.46 raeburn 547: if ($hostname eq '') {
548: $hostname =&get_hostname();
549: } else {
550: print &mt("Hostname detected: $hostname. Is that correct? ~[Y/n~]");
551: if (!&get_user_selection(1)) {
552: $hostname =&get_hostname();
553: }
554: }
1.47 raeburn 555: $hostip = Socket::inet_ntoa(scalar(gethostbyname($hostname)) || 'localhost');
556: if ($hostip eq '') {
557: $hostip=&get_hostip();
558: } else {
559: print &mt("Host IP address detected: $hostip. Is that correct? ~[Y/n~]");
560: if (!&get_user_selection(1)) {
561: $hostip=&get_hostip();
562: }
563: }
564: print_and_log("\n".&mt('Hostname is [_1] and IP address is [_2]',$hostname,$hostip)."\n");
1.1 raeburn 565: $mysqlon = &check_mysql_running($distro);
566: if ($mysqlon) {
1.68 raeburn 567: ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser,$mysql_unix_socket) =
1.71 raeburn 568: &check_mysql_setup($instdir,$dsn,$distro);
1.34 raeburn 569: if ($mysqlsetup eq 'needsrestart') {
570: $mysqlrestart = '';
571: if ($distro eq 'ubuntu') {
572: $mysqlrestart = 'sudo ';
573: }
574: $mysqlrestart .= 'service mysql restart';
575: return ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,$mysqlrestart);
1.1 raeburn 576: } else {
1.34 raeburn 577: if ($mysqlsetup eq 'noroot') {
1.1 raeburn 578: $recommended{'mysqlperms'} = 1;
1.34 raeburn 579: } else {
580: unless ($mysql_has_wwwuser) {
581: $recommended{'mysqlperms'} = 1;
582: }
583: }
584: if ($dbh) {
585: $has_lcdb = &check_loncapa_mysqldb($dbh);
586: }
587: unless ($has_lcdb) {
588: $recommended{'mysql'} = 1;
1.1 raeburn 589: }
590: }
591: }
1.47 raeburn 592: my ($sslhostsfilesref,$has_std,$has_int,$rewritenum,$nochgstd,$nochgint);
1.5 raeburn 593: ($recommended{'firewall'},$apachefw) = &chkfirewall($distro);
1.35 raeburn 594: ($recommended{'runlevels'},$tostop,$uses_systemctl) = &chkconfig($distro,$instdir);
1.1 raeburn 595: $recommended{'apache'} = &chkapache($distro,$instdir);
1.47 raeburn 596: ($recommended{'apachessl'},$sslhostsfilesref,$has_std,$has_int,$rewritenum,
597: $nochgstd,$nochgint) = &chkapachessl($distro,$instdir,$hostname,$hostip);
1.1 raeburn 598: $recommended{'stopsrvcs'} = &chksrvcs($distro,$tostop);
599: ($recommended{'download'},$downloadstatus,$filetouse,$production,$testing)
1.77 raeburn 600: = &need_download($distro,$instdir);
1.6 raeburn 601: return ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,
1.68 raeburn 602: $mysqlrestart,\%recommended,$dbh,$has_pass,$mysql_unix_socket,
603: $has_lcdb,$downloadstatus,$filetouse,$production,$testing,$apachefw,
604: $uses_systemctl,$hostname,$hostip,$sslhostsfilesref,$has_std,$has_int,
605: $rewritenum,$nochgstd,$nochgint);
1.1 raeburn 606: }
607:
608: sub check_mysql_running {
609: my ($distro) = @_;
1.23 raeburn 610: my $use_systemctl;
1.1 raeburn 611: my $mysqldaemon ='mysqld';
612: if ($distro =~ /^(suse|sles|debian|ubuntu)/) {
613: $mysqldaemon = 'mysql';
614: }
1.6 raeburn 615: my $process = 'mysqld_safe';
616: my $proc_owner = 'root';
617: if ($distro =~ /^ubuntu(\w+)/) {
618: if ($1 >= 10) {
619: $process = 'mysqld';
620: $proc_owner = 'mysql';
621: }
1.35 raeburn 622: } elsif ($distro =~ /^fedora(\d+)/) {
1.23 raeburn 623: if ($1 >= 16) {
624: $process = 'mysqld';
625: $proc_owner = 'mysql';
626: $use_systemctl = 1;
627: }
1.39 raeburn 628: if ($1 >= 19) {
1.37 raeburn 629: $mysqldaemon ='mariadb';
630: }
1.78 raeburn 631: if ($1 >= 34) {
632: $process = 'mariadb';
633: }
1.79 ! raeburn 634: } elsif ($distro =~ /^(?:centos|rhes|scientific|oracle|rocky|alma)(\d+)/) {
1.29 raeburn 635: if ($1 >= 7) {
636: $mysqldaemon ='mariadb';
637: $process = 'mysqld';
638: $proc_owner = 'mysql';
639: $use_systemctl = 1;
640: }
1.35 raeburn 641: } elsif ($distro =~ /^sles(\d+)/) {
642: if ($1 >= 12) {
643: $use_systemctl = 1;
1.42 raeburn 644: $proc_owner = 'mysql';
645: $process = 'mysqld';
1.35 raeburn 646: }
1.49 raeburn 647: if ($1 >= 15) {
648: $mysqldaemon ='mariadb';
649: }
1.35 raeburn 650: } elsif ($distro =~ /^suse(\d+)/) {
651: if ($1 >= 13) {
652: $use_systemctl = 1;
653: }
1.29 raeburn 654: }
1.35 raeburn 655: if (open(PIPE,"ps -ef |grep $process |grep ^$proc_owner |grep -v grep 2>&1 |")) {
1.1 raeburn 656: my $status = <PIPE>;
657: close(PIPE);
658: chomp($status);
1.6 raeburn 659: if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
1.1 raeburn 660: print_and_log(&mt('MySQL is running.')."\n");
661: return 1;
662: } else {
1.23 raeburn 663: if ($use_systemctl) {
664: system("/bin/systemctl start $mysqldaemon.service >/dev/null 2>&1 ");
665: } else {
666: system("/etc/init.d/$mysqldaemon start >/dev/null 2>&1 ");
667: }
1.1 raeburn 668: print_and_log(&mt('Waiting for MySQL to start.')."\n");
669: sleep 5;
1.12 raeburn 670: if (open(PIPE,"ps -ef |grep $process |grep -v grep 2>&1 |")) {
671: $status = <PIPE>;
1.1 raeburn 672: close(PIPE);
673: chomp($status);
1.12 raeburn 674: if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
1.1 raeburn 675: print_and_log(&mt('MySQL is running.')."\n");
676: return 1;
677: } else {
1.12 raeburn 678: print_and_log(&mt('Still waiting for MySQL to start.')."\n");
679: sleep 5;
680: if (open(PIPE,"ps -ef |grep $process |grep -v grep 2>&1 |")) {
681: $status = <PIPE>;
682: close(PIPE);
683: chomp($status);
684: if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
685: print_and_log(&mt('MySQL is running.')."\n");
686: return 1;
687: } else {
688: print_and_log(&mt('Given up waiting for MySQL to start.')."\n");
689: }
690: }
1.1 raeburn 691: }
692: }
693: }
694: } else {
695: print &mt('Could not determine if MySQL is running.')."\n";
696: }
697: return;
698: }
699:
700: sub chkconfig {
1.8 raeburn 701: my ($distro,$instdir) = @_;
1.23 raeburn 702: my (%needfix,%tostop,%uses_systemctl);
1.1 raeburn 703: my $checker_bin = '/sbin/chkconfig';
1.23 raeburn 704: my $sysctl_bin = '/bin/systemctl';
1.6 raeburn 705: my %daemon = (
706: mysql => 'mysqld',
707: apache => 'httpd',
708: cups => 'cups',
709: ntp => 'ntpd',
710: memcached => 'memcached',
711: );
1.1 raeburn 712: my @runlevels = qw/3 4 5/;
713: my @norunlevels = qw/0 1 6/;
714: if ($distro =~ /^(suse|sles)/) {
715: @runlevels = qw/3 5/;
716: @norunlevels = qw/0 2 1 6/;
1.6 raeburn 717: $daemon{'mysql'} = 'mysql';
718: $daemon{'apache'} = 'apache2';
1.8 raeburn 719: $daemon{'ntp'} = 'ntp';
1.1 raeburn 720: if ($distro =~ /^(suse|sles)9/) {
1.6 raeburn 721: $daemon{'apache'} = 'apache';
1.1 raeburn 722: }
1.35 raeburn 723: if ($distro =~ /^(suse|sles)([\d\.]+)/) {
724: my $name = $1;
725: my $num = $2;
726: if ($num > 11) {
1.26 raeburn 727: $uses_systemctl{'apache'} = 1;
1.35 raeburn 728: if (($name eq 'sles') || ($name eq 'suse' && $num >= 13.2)) {
729: $uses_systemctl{'mysql'} = 1;
730: $uses_systemctl{'ntp'} = 1;
731: $uses_systemctl{'cups'} = 1;
732: $uses_systemctl{'memcached'} = 1;
1.49 raeburn 733: if (($name eq 'sles') && ($num >= 15)) {
734: $daemon{'ntp'} = 'chronyd';
735: $daemon{'mysql'} = 'mariadb';
736: } else {
737: $daemon{'ntp'} = 'ntpd';
738: }
1.35 raeburn 739: }
1.26 raeburn 740: }
741: }
1.6 raeburn 742: } elsif ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
743: my $version = $1;
1.1 raeburn 744: @runlevels = qw/2 3 4 5/;
745: @norunlevels = qw/0 1 6/;
1.44 raeburn 746: if (($distro =~ /^ubuntu/) && ($version <= 16)) {
747: $checker_bin = '/usr/sbin/sysv-rc-conf';
748: } else {
749: $uses_systemctl{'ntp'} = 1;
750: $uses_systemctl{'mysql'} = 1;
751: $uses_systemctl{'apache'} = 1;
752: $uses_systemctl{'memcached'} = 1;
753: $uses_systemctl{'cups'} = 1;
754: }
1.6 raeburn 755: $daemon{'mysql'} = 'mysql';
756: $daemon{'apache'} = 'apache2';
757: $daemon{'ntp'} = 'ntp';
758: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
759: $daemon{'cups'} = 'cupsys';
760: }
1.61 raeburn 761: if (($distro =~ /^ubuntu/) && ($version >= 18)) {
762: $daemon{'ntp'} = 'chrony';
763: }
1.26 raeburn 764: } elsif ($distro =~ /^fedora(\d+)/) {
1.23 raeburn 765: my $version = $1;
766: if ($version >= 15) {
767: $uses_systemctl{'ntp'} = 1;
768: }
769: if ($version >= 16) {
770: $uses_systemctl{'mysql'} = 1;
771: $uses_systemctl{'apache'} = 1;
1.35 raeburn 772: $uses_systemctl{'memcached'} = 1;
773: $uses_systemctl{'cups'} = 1;
1.23 raeburn 774: }
1.39 raeburn 775: if ($version >= 19) {
1.37 raeburn 776: $daemon{'mysql'} = 'mariadb';
777: }
1.59 raeburn 778: if ($version >= 26) {
779: $daemon{'ntp'} = 'chronyd';
780: }
1.79 ! raeburn 781: } elsif ($distro =~ /^(?:centos|rhes|scientific|oracle|rocky|alma)(\d+)/) {
1.29 raeburn 782: my $version = $1;
783: if ($version >= 7) {
784: $uses_systemctl{'ntp'} = 1;
785: $uses_systemctl{'mysql'} = 1;
786: $uses_systemctl{'apache'} = 1;
1.35 raeburn 787: $uses_systemctl{'memcached'} = 1;
788: $uses_systemctl{'cups'} = 1;
1.30 raeburn 789: $daemon{'mysql'} = 'mariadb';
1.29 raeburn 790: }
1.56 raeburn 791: if (($version >= 8) || ($distro eq 'oracle7')) {
1.54 raeburn 792: $daemon{'ntp'} = 'chronyd';
793: }
1.1 raeburn 794: }
1.23 raeburn 795: my $nocheck;
1.1 raeburn 796: if (! -x $checker_bin) {
1.23 raeburn 797: if ($uses_systemctl{'mysql'} && $uses_systemctl{'apache'}) {
798: if (! -x $sysctl_bin) {
799: $nocheck = 1;
800: }
801: } else {
802: $nocheck = 1;
803: }
804: }
805: if ($nocheck) {
1.6 raeburn 806: print &mt('Could not check runlevel status for MySQL or Apache')."\n";
1.1 raeburn 807: return;
808: }
809: my $rlstr = join('',@runlevels);
810: my $nrlstr = join('',@norunlevels);
1.23 raeburn 811:
1.6 raeburn 812: foreach my $type ('apache','mysql','ntp','cups','memcached') {
813: my $service = $daemon{$type};
1.23 raeburn 814: if ($uses_systemctl{$type}) {
1.35 raeburn 815: if (($type eq 'memcached') || ($type eq 'cups')) {
816: if (-l "/etc/systemd/system/multi-user.target.wants/$service.service") {
817: $tostop{$type} = 1;
818: }
819: } else {
820: if (!-l "/etc/systemd/system/multi-user.target.wants/$service.service") {
821: $needfix{$type} = "systemctl enable $service.service";
822: }
1.23 raeburn 823: }
824: } else {
825: my $command = $checker_bin.' --list '.$service.' 2>/dev/null';
1.35 raeburn 826: if ($type eq 'cups') {
1.23 raeburn 827: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
828: my $version = $1;
829: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
830: $command = $checker_bin.' --list cupsys 2>/dev/null';
1.19 raeburn 831: }
832: }
833: }
1.23 raeburn 834: my $results = `$command`;
835: my $tofix;
836: if ($results eq '') {
837: if (($type eq 'apache') || ($type eq 'mysql') || ($type eq 'ntp')) {
838: if ($distro =~ /^(debian|ubuntu)/) {
839: $tofix = "update-rc.d $type defaults";
840: } else {
841: $tofix = "$checker_bin --add $service\n";
842: }
1.6 raeburn 843: }
1.23 raeburn 844: } else {
845: my %curr_runlevels;
846: for (my $rl=0; $rl<=6; $rl++) {
847: if ($results =~ /$rl:on/) { $curr_runlevels{$rl}++; }
848: }
849: if (($type eq 'apache') || ($type eq 'mysql') || ($type eq 'ntp')) {
850: my $warning;
851: foreach my $rl (@runlevels) {
852: if (!exists($curr_runlevels{$rl})) {
853: $warning = 1;
854: }
855: }
856: if ($warning) {
857: $tofix = "$checker_bin --level $rlstr $service on\n";
858: }
859: } elsif (keys(%curr_runlevels) > 0) {
860: $tostop{$type} = 1;
1.1 raeburn 861: }
862: }
1.23 raeburn 863: if ($tofix) {
864: $needfix{$type} = $tofix;
1.1 raeburn 865: }
1.5 raeburn 866: }
1.1 raeburn 867: }
868: if ($distro =~ /^(suse|sles)([\d\.]+)$/) {
869: my $name = $1;
870: my $version = $2;
871: my ($major,$minor);
872: if ($name eq 'suse') {
873: ($major,$minor) = split(/\./,$version);
874: } else {
875: $major = $version;
876: }
1.49 raeburn 877: if (($major > 10) && ($major <= 13)) {
1.8 raeburn 878: if (&check_SuSEfirewall2_setup($instdir)) {
879: $needfix{'insserv'} = 1;
880: }
1.1 raeburn 881: }
882: }
1.35 raeburn 883: return (\%needfix,\%tostop,\%uses_systemctl);
1.1 raeburn 884: }
885:
1.49 raeburn 886: sub uses_firewalld {
887: my ($distro) = @_;
1.53 raeburn 888: my ($inuse,$checkfirewalld,$zone);
1.49 raeburn 889: if ($distro =~ /^(suse|sles)([\d\.]+)$/) {
890: if (($1 eq 'sles') && ($2 >= 15)) {
891: $checkfirewalld = 1;
892: }
893: } elsif ($distro =~ /^fedora(\d+)$/) {
894: if ($1 >= 18) {
895: $checkfirewalld = 1;
896: }
1.79 ! raeburn 897: } elsif ($distro =~ /^(?:centos|rhes|scientific|oracle|rocky|alma)(\d+)/) {
1.49 raeburn 898: if ($1 >= 7) {
899: $checkfirewalld = 1;
900: }
901: }
902: if ($checkfirewalld) {
903: my ($loaded,$active);
1.75 raeburn 904: if (open(PIPE,"systemctl status firewalld 2>/dev/null |")) {
1.49 raeburn 905: while (<PIPE>) {
906: chomp();
907: if (/^\s*Loaded:\s+(\w+)/) {
908: $loaded = $1;
909: }
1.75 raeburn 910: if (/^\s*Active:\s+(\w+)/) {
1.49 raeburn 911: $active = $1;
912: }
913: }
914: close(PIPE);
915: }
916: if (($loaded eq 'loaded') || ($active eq 'active')) {
917: $inuse = 1;
1.53 raeburn 918: my $cmd = 'firewall-cmd --get-default-zone';
919: if (open(PIPE,"$cmd |")) {
920: my $result = <PIPE>;
921: chomp($result);
922: close(PIPE);
923: if ($result =~ /^\w+$/) {
924: $zone = $result;
925: }
926: }
1.49 raeburn 927: }
928: }
1.53 raeburn 929: return ($inuse,$zone);
1.49 raeburn 930: }
931:
1.1 raeburn 932: sub chkfirewall {
1.5 raeburn 933: my ($distro) = @_;
1.1 raeburn 934: my $configfirewall = 1;
935: my %ports = (
936: http => 80,
937: https => 443,
938: );
1.5 raeburn 939: my %activefw;
1.53 raeburn 940: my ($firewalld,$zone) = &uses_firewalld($distro);
941: if ($firewalld) {
942: my %current;
943: if (open(PIPE,'firewall-cmd --permanent --zone='.$zone.' --list-services |')) {
944: my $svc = <PIPE>;
945: close(PIPE);
946: chomp($svc);
947: map { $current{$_} = 1; } (split(/\s+/,$svc));
948: }
949: if ($current{'http'} && $current{'https'}) {
950: $configfirewall = 0;
951: }
952: } else {
953: if (&firewall_is_active()) {
1.49 raeburn 954: my $iptables = &get_pathto_iptables();
955: if ($iptables eq '') {
956: print &mt('Firewall not checked as path to iptables not determined.')."\n";
957: } else {
958: my @fwchains = &get_fw_chains($iptables,$distro);
959: if (@fwchains) {
960: foreach my $service ('http','https') {
961: foreach my $fwchain (@fwchains) {
962: if (&firewall_is_port_open($iptables,$fwchain,$ports{$service})) {
963: $activefw{$service} = 1;
964: last;
965: }
1.1 raeburn 966: }
967: }
1.49 raeburn 968: if ($activefw{'http'}) {
969: $configfirewall = 0;
970: }
971: } else {
972: print &mt('Firewall not checked as iptables Chains not identified.')."\n";
1.1 raeburn 973: }
974: }
1.53 raeburn 975: } else {
976: print &mt('Firewall not enabled.')."\n";
1.1 raeburn 977: }
978: }
1.5 raeburn 979: return ($configfirewall,\%activefw);
1.1 raeburn 980: }
981:
982: sub chkapache {
983: my ($distro,$instdir) = @_;
984: my $fixapache = 1;
1.28 raeburn 985: if ($distro =~ /^(debian|ubuntu)(\d+)$/) {
986: my $distname = $1;
987: my $version = $2;
1.33 raeburn 988: my ($stdconf,$stdsite);
989: if (($distname eq 'ubuntu') && ($version > 12)) {
990: $stdconf = "$instdir/debian-ubuntu/ubuntu14/loncapa_conf";
991: $stdsite = "$instdir/debian-ubuntu/ubuntu14/loncapa_sites";
992: } else {
993: $stdconf = "$instdir/debian-ubuntu/loncapa";
994: }
995: if (!-e $stdconf) {
1.1 raeburn 996: $fixapache = 0;
997: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.28 raeburn 998: } else {
1.33 raeburn 999: my ($configfile,$sitefile);
1.28 raeburn 1000: if (($distname eq 'ubuntu') && ($version > 12)) {
1.69 raeburn 1001: $sitefile = '/etc/apache2/sites-available/loncapa.conf';
1002: $configfile = '/etc/apache2/conf-available/loncapa.conf';
1.33 raeburn 1003: } else {
1.69 raeburn 1004: $configfile = '/etc/apache2/sites-available/loncapa';
1.28 raeburn 1005: }
1.33 raeburn 1006: if (($configfile ne '') && (-e $configfile) && (-e $stdconf)) {
1007: if (open(PIPE, "diff --brief $stdconf $configfile |")) {
1.28 raeburn 1008: my $diffres = <PIPE>;
1009: close(PIPE);
1010: chomp($diffres);
1011: unless ($diffres) {
1012: $fixapache = 0;
1013: }
1.1 raeburn 1014: }
1015: }
1.33 raeburn 1016: if ((!$fixapache) && ($distname eq 'ubuntu') && ($version > 12)) {
1017: if (($sitefile ne '') && (-e $sitefile) && (-e $stdsite)) {
1018: if (open(PIPE, "diff --brief $stdsite $sitefile |")) {
1019: my $diffres = <PIPE>;
1020: close(PIPE);
1021: chomp($diffres);
1022: unless ($diffres) {
1023: $fixapache = 0;
1024: }
1025: }
1026: }
1027: }
1.1 raeburn 1028: }
1.6 raeburn 1029: if (!$fixapache) {
1030: foreach my $module ('headers.load','expires.load') {
1031: unless (-l "/etc/apache2/mods-enabled/$module") {
1032: $fixapache = 1;
1033: }
1034: }
1035: }
1.64 raeburn 1036: if ((!$fixapache) && ($distname eq 'ubuntu')) {
1037: my $sitestatus = "/etc/apache2/mods-available/status.conf";
1038: my $stdstatus = "$instdir/debian-ubuntu/status.conf";
1039: if ((-e $stdstatus) && (-e $sitestatus)) {
1040: if (open(PIPE, "diff --brief $stdstatus $sitestatus |")) {
1041: my $diffres = <PIPE>;
1042: close(PIPE);
1043: chomp($diffres);
1044: if ($diffres) {
1045: $fixapache = 1;
1046: }
1047: }
1048: }
1049: }
1.49 raeburn 1050: } elsif ($distro =~ /^(suse|sles)([\d\.]+)$/) {
1051: my ($name,$version) = ($1,$2);
1.1 raeburn 1052: my $apache = 'apache';
1.57 raeburn 1053: my $conf_file = "$instdir/sles-suse/default-server.conf";
1.49 raeburn 1054: if ($version >= 10) {
1.8 raeburn 1055: $apache = 'apache2';
1.1 raeburn 1056: }
1.49 raeburn 1057: if (($name eq 'sles') && ($version >= 12)) {
1058: $conf_file = "$instdir/sles-suse/apache2.4/default-server.conf";
1059: }
1.57 raeburn 1060: if (!-e $conf_file) {
1.1 raeburn 1061: $fixapache = 0;
1062: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.49 raeburn 1063: } elsif (-e "/etc/$apache/default-server.conf") {
1064: if (open(PIPE, "diff --brief $conf_file /etc/$apache/default-server.conf |")) {
1.9 raeburn 1065: my $diffres = <PIPE>;
1066: close(PIPE);
1067: chomp($diffres);
1068: unless ($diffres) {
1069: $fixapache = 0;
1070: }
1071: }
1072: }
1073: } elsif ($distro eq 'rhes4') {
1074: if (!-e "$instdir/rhes4/httpd.conf") {
1075: $fixapache = 0;
1076: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1077: } elsif ((-e "/etc/httpd/conf/httpd.conf") && (-e "$instdir/rhes4/httpd.conf")) {
1078: if (open(PIPE, "diff --brief $instdir/rhes4/httpd.conf /etc/httpd/conf/httpd.conf |")) {
1.1 raeburn 1079: my $diffres = <PIPE>;
1080: close(PIPE);
1081: chomp($diffres);
1082: unless ($diffres) {
1083: $fixapache = 0;
1084: }
1085: }
1086: }
1087: } else {
1.14 raeburn 1088: my $configfile = 'httpd.conf';
1.59 raeburn 1089: my $mpmfile = 'mpm.conf';
1.79 ! raeburn 1090: if ($distro =~ /^(?:centos|rhes|scientific|oracle|rocky|alma)(\d+)$/) {
1.29 raeburn 1091: if ($1 >= 7) {
1092: $configfile = 'apache2.4/httpd.conf';
1093: } elsif ($1 > 5) {
1.14 raeburn 1094: $configfile = 'new/httpd.conf';
1095: }
1096: } elsif ($distro =~ /^fedora(\d+)$/) {
1.29 raeburn 1097: if ($1 > 17) {
1.59 raeburn 1098: $configfile = 'apache2.4/httpd.conf';
1.29 raeburn 1099: } elsif ($1 > 10) {
1.15 raeburn 1100: $configfile = 'new/httpd.conf';
1.14 raeburn 1101: }
1102: }
1103: if (!-e "$instdir/centos-rhes-fedora-sl/$configfile") {
1.1 raeburn 1104: $fixapache = 0;
1105: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.14 raeburn 1106: } elsif ((-e "/etc/httpd/conf/httpd.conf") && (-e "$instdir/centos-rhes-fedora-sl/$configfile")) {
1107: if (open(PIPE, "diff --brief $instdir/centos-rhes-fedora-sl/$configfile /etc/httpd/conf/httpd.conf |")) {
1.1 raeburn 1108: my $diffres = <PIPE>;
1109: close(PIPE);
1110: chomp($diffres);
1111: unless ($diffres) {
1112: $fixapache = 0;
1113: }
1114: }
1115: }
1.59 raeburn 1116: if (-e "/etc/httpd/conf.modules.d/00-mpm.conf") {
1117: if (!-e "$instdir/centos-rhes-fedora-sl/$mpmfile") {
1118: print &mt('Warning: No LON-CAPA Apache MPM configuration file found for installation check.')."\n";
1119: } elsif ((-e "/etc/httpd/conf.modules.d/00-mpm.conf") && (-e "$instdir/centos-rhes-fedora-sl/$mpmfile")) {
1120: if (open(PIPE, "diff --brief $instdir/centos-rhes-fedora-sl/$mpmfile /etc/httpd/conf.modules.d/00-mpm.conf |")) {
1121: my $diffres = <PIPE>;
1122: close(PIPE);
1123: chomp($diffres);
1124: if ($diffres) {
1125: $fixapache = 1;
1126: }
1127: }
1128: }
1129: }
1.1 raeburn 1130: }
1131: return $fixapache;
1132: }
1133:
1.47 raeburn 1134: #
1135: # chkapachessl() determines whether a server's Apache SSL configuration
1136: # needs updating to support LON-CAPA.
1137: #
1138: # LON-CAPA uses VirtualHosts for port 443, and requires that they are
1139: # defined in one Apache configuration file containing two VirtualHost
1140: # blocks, in order:
1141: #
1142: # (1) a block with no ServerName, or with ServerName set to the
1143: # server's hostname. This block should contain:
1144: #
1145: # <IfModule mod_rewrite.c>
1146: # LON-CAPA rewrite rules defined in sslrewrite.conf
1147: # </IfModule>
1148: #
1149: # (2) a block with ServerName set to internal-$hostname
1150: # (where $hostname is server's hostname).
1151: # This block should contain the config and rewrite rules
1152: # found in loncapassl.conf.
1153: #
1154: # chkapachessl() retrieves the names of .conf files in
1155: # the directory appropriate for the particular Linux distro,
1156: # and then checks to see which .conf file is the best candidate as
1157: # the single file containing VirtualHosts definitions and
1158: # <IfModule mod_rewrite.c> </IfModule> rewrite blocks.
1159: #
1160: # The best candidate is the one containing a block:
1161: # <VirtualHost ????? :443>
1162: # (where ????? might be _default_ or * or an IP address)
1163: # <IfModule mod_rewrite.c>
1164: # </IfModule>
1165: # </VirtualHost>
1166: # with the fewest differences between the contents of the
1167: # IfModule block and the expected contents (from sslrewrite.conf)
1168: #
1169: # If there are no files with rewrite blocks, then a candidate file
1170: # is chosen from the .conf files containing VirtualHosts definitions.
1171: #
1172: # If the user includes "Configure SSL for Apache web server" as
1173: # one of the actions to take to prepare the server for LON-CAPA
1174: # installation, then the output from &chkapachessl() will be
1175: # used to determined which file will contain VirtualHost configs.
1176: #
1177: # If there are no files containing VirtualHosts definitions, then
1178: # <VirtualHost *:443> </VirtualHost> blocks will be appended to
1179: # the standard Apache SSL config for the particular distro:
1180: # ssl.conf for RHEL/CentOS/Scientific/Fedora, vhost-ssl.conf
1181: # for SuSE/SLES, and default-ssl.conf for Ubuntu.
1182: #
1183: # Once a file is selected, the contents of sslrewrite.conf and
1184: # loncapassl.conf are compared with appropriate blocks in the file
1185: # and the user will be prompted to agree to insertion of missing
1186: # lines and/or deletion of surplus lines.
1187: #
1188:
1.46 raeburn 1189: sub chkapachessl {
1.47 raeburn 1190: my ($distro,$instdir,$hostname,$hostip) = @_;
1.46 raeburn 1191: my $fixapachessl = 1;
1.47 raeburn 1192: my $sslintconf = "$instdir/loncapassl.conf";
1193: my $sslrewriteconf = "$instdir/sslrewrite.conf";
1194: my (%sslfiles,%rewrites,%vhostonly,$has_std,$has_int,$rewritenum,$nochgint,$nochgstd);
1195: $nochgstd = 0;
1196: $nochgint = 0;
1197: if (!-e $sslintconf) {
1198: $fixapachessl = 0;
1199: print &mt('Warning: LON-CAPA SSL Apache configuration file [_1] needed for installation check.',$sslintconf)."\n";
1200: } elsif (!-e $sslrewriteconf) {
1.46 raeburn 1201: $fixapachessl = 0;
1.47 raeburn 1202: print &mt('Warning: LON-CAPA SSL Apache configuration file [_1] needed for installation check is missing.',$sslrewriteconf)."\n";
1.46 raeburn 1203: } else {
1.47 raeburn 1204: my $ssldir;
1.46 raeburn 1205: if ($distro =~ /^(debian|ubuntu)(\d+)$/) {
1.47 raeburn 1206: $ssldir = '/etc/apache2/sites-available';
1.46 raeburn 1207: } elsif ($distro =~ /(suse|sles)/) {
1.47 raeburn 1208: $ssldir = '/etc/apache2/vhosts.d';
1.46 raeburn 1209: } else {
1.47 raeburn 1210: $ssldir = '/etc/httpd/conf.d';
1211: }
1212: my @rewritessl = ();
1213: if (open(my $fh,'<',$sslrewriteconf)) {
1214: my $skipnext = 0;
1215: while (<$fh>) {
1216: chomp();
1217: s/(^\s+|\s+$)//g;
1218: next if ($_ eq '');
1219: next if ($_ eq '<IfModule mod_rewrite.c>');
1220: next if ($_ eq '</IfModule>');
1221: if ($_ eq 'RewriteCond %{REMOTE_ADDR} {[[[[HostIP]]]]}') {
1222: if (($hostip ne '') && ($hostip ne '127.0.0.1')) {
1223: push(@rewritessl,'RewriteCond %{REMOTE_ADDR} '.$hostip);
1224: next;
1225: } else {
1226: $skipnext = 1;
1227: }
1228: } elsif (($_ eq 'RewriteRule (.*) - [L]') && ($skipnext)) {
1229: $skipnext = 0;
1230: next;
1231: }
1232: push(@rewritessl,$_);
1233: }
1.46 raeburn 1234: }
1.47 raeburn 1235: my @intssl = ();
1236: if (open(my $fh,'<',$sslintconf)) {
1237: while(<$fh>) {
1238: chomp();
1239: s/(^\s+|\s+$)//g;
1240: next if ($_ eq '');
1241: if ($_ eq 'ServerName internal-{[[[[Hostname]]]]}') {
1242: if ($hostname ne '') {
1243: push(@intssl,'ServerName internal-'.$hostname);
1244: next;
1245: }
1246: }
1247: next if ($_ eq '<VirtualHost *:443>');
1248: next if ($_ eq '</VirtualHost>');
1249: push(@intssl,$_);
1250: }
1251: }
1252: if (-d $ssldir) {
1253: my @actualint = ();
1254: if (opendir(my $dir,$ssldir)) {
1255: my @sslconf_files;
1256: foreach my $file (grep(!/^\.+/,readdir($dir))) {
1257: next if (($distro =~ /(suse|sles)/) && ($file =~ /\.template$/));
1258: next if ($file =~ /\.rpmnew$/);
1259: if (open(my $fh,'<',"$ssldir/$file")) {
1260: while (<$fh>) {
1261: if (/^\s*<VirtualHost\s+[^:]*\:443>\s*$/) {
1262: push(@sslconf_files,$file);
1263: last;
1264: }
1265: }
1266: close($fh);
1267: }
1268: }
1269: closedir($dir);
1270: if (@sslconf_files) {
1271: foreach my $file (@sslconf_files) {
1272: if (open(my $fh,'<',"$ssldir/$file")) {
1273: my ($virtualhost,$rewrite,$num) = (0,0,0);
1274: my ($currname,$has_rewrite);
1275: while (<$fh>) {
1276: chomp();
1277: next if (/^\s*$/);
1278: if ($virtualhost) {
1279: if (/^\s*<\/VirtualHost>/) {
1280: if ($currname !~ /^\Qinternal-$hostname\E/) {
1281: if ($has_rewrite) {
1282: delete($vhostonly{$file});
1283: } else {
1284: $vhostonly{$file} = 1;
1285: }
1286: }
1287: $sslfiles{$currname}{$file} = 1;
1288: $virtualhost = 0;
1289: $currname = '';
1290: $has_rewrite = '';
1291: next;
1292: } elsif (/^\s*ServerName\s+([^\s]+)\s*$/) {
1293: $currname = $1;
1294: }
1295: if ($currname =~ /^\Qinternal-$hostname\E/) {
1296: s/(^\s+|\s+$)//g;
1297: push(@actualint,$_);
1298: $has_int = $file;
1299: } else {
1300: if ($rewrite) {
1301: if (/^\s*<\/IfModule>/) {
1302: $rewrite = 0;
1303: $num ++;
1304: } else {
1305: s/(^\s+|\s+$)//g;
1306: push(@{$rewrites{$file}[$num]},$_);
1307: }
1308: } elsif (/^\s*<IfModule\s+mod_rewrite\.c>/) {
1309: $rewrite = 1;
1310: $has_rewrite = 1;
1311: if ($currname eq '') {
1312: $currname = $hostname;
1313: }
1314: $rewrites{$file}[$num] = [];
1315: }
1316: }
1317: } elsif (/^\s*<VirtualHost\s+[^:]*\:443>\s*$/) {
1318: $virtualhost = 1;
1319: }
1320: }
1321: close($fh);
1322: }
1323: }
1324: }
1325: if (keys(%rewrites)) {
1326: my $mindiffsall;
1327: foreach my $file (sort(keys(%rewrites))) {
1328: if (ref($rewrites{$file}) eq 'ARRAY') {
1329: my $mindiffs;
1330: for (my $i=0; $i<@{$rewrites{$file}}; $i++) {
1331: if (ref($rewrites{$file}[$i]) eq 'ARRAY') {
1332: my @diffs = &compare_arrays($rewrites{$file}[$i],\@rewritessl);
1333: if (@diffs == 0) {
1334: $fixapachessl = 0;
1335: $mindiffs = 0;
1336: $rewritenum = 1+$i;
1337: last;
1338: } else {
1339: if ($mindiffs eq '') {
1340: $mindiffs = scalar(@diffs);
1341: $rewritenum = 1+$i;
1342: } elsif (scalar(@diffs) <= $mindiffs) {
1343: $mindiffs = scalar(@diffs);
1344: $rewritenum = 1+$i;
1345: }
1346: }
1347: }
1348: }
1349: if ($mindiffsall eq '') {
1350: $mindiffsall = $mindiffs;
1351: $has_std = $file;
1352: } elsif ($mindiffs <= $mindiffsall) {
1353: $mindiffsall = $mindiffs;
1354: $has_std = $file;
1355: }
1356: if ($mindiffsall == 0) {
1357: $nochgstd = 1;
1358: }
1359: }
1360: }
1361: } elsif (keys(%vhostonly) > 0) {
1362: if (($has_int ne '') && (exists($vhostonly{$has_int}))) {
1363: $has_std = $has_int;
1364: }
1365: }
1366: if (@actualint) {
1367: my @diffs = &compare_arrays(\@actualint,\@intssl);
1368: if (@diffs) {
1369: $fixapachessl = 1;
1370: } else {
1371: $nochgint = 1;
1372: }
1373: } else {
1374: $fixapachessl = 1;
1.46 raeburn 1375: }
1376: }
1377: }
1378: unless ($fixapachessl) {
1379: if ($distro =~ /^(debian|ubuntu)(\d+)$/) {
1.47 raeburn 1380: my $enabled_dir = '/etc/apache2/sites-enabled';
1381: if (keys(%sslfiles)) {
1382: foreach my $key (sort(keys(%sslfiles))) {
1383: if (ref($sslfiles{$key}) eq 'HASH') {
1384: foreach my $file (sort(keys(%{$sslfiles{$key}}))) {
1385: unless ((-l "$enabled_dir/$file") &&
1386: (readlink("$enabled_dir/$file") eq "$ssldir/$file")) {
1387: print_and_log(&mt("Warning, use: 'sudo a2ensite $file' to activate LON-CAPA SSL Apache config\n"));
1388: }
1389: }
1390: }
1391: }
1.46 raeburn 1392: }
1393: }
1394: }
1395: }
1.47 raeburn 1396: return ($fixapachessl,\%sslfiles,$has_std,$has_int,$rewritenum,$nochgstd,$nochgint);
1397: }
1398:
1399: #
1400: # compare_arrays() expects two refs to arrays as args.
1401: #
1402: # The contents of the two arrays are compared, and if they
1403: # are different, and array of the differences is returned.
1404: #
1405:
1406: sub compare_arrays {
1407: my ($arrayref1,$arrayref2) = @_;
1408: my (@difference,%count);
1409: @difference = ();
1410: %count = ();
1411: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
1412: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
1413: foreach my $element (keys(%count)) {
1414: if ($count{$element} == 1) {
1415: push(@difference,$element);
1416: }
1417: }
1418: }
1419: return @difference;
1.46 raeburn 1420: }
1421:
1.1 raeburn 1422: sub chksrvcs {
1423: my ($distro,$tostop) = @_;
1424: my %stopsrvcs;
1425: if (ref($tostop) eq 'HASH') {
1426: %stopsrvcs = %{$tostop};
1427: }
1.6 raeburn 1428: foreach my $service ('cups','memcached') {
1.1 raeburn 1429: next if (exists($stopsrvcs{$service}));
1430: my $daemon = $service;
1431: if ($service eq 'cups') {
1432: $daemon = 'cupsd';
1433: }
1434: my $cmd = "ps -ef |grep '$daemon' |grep -v grep";
1435: if (open(PIPE,'-|',$cmd)) {
1436: my $daemonrunning = <PIPE>;
1437: chomp($daemonrunning);
1438: close(PIPE);
1439: if ($daemonrunning) {
1.12 raeburn 1440: if ($service eq 'memcached') {
1.16 raeburn 1441: my $cmd = '/usr/bin/memcached';
1442: if ($distro =~ /^(suse|sles)/) {
1443: $cmd = '/usr/sbin/memcached';
1444: }
1.12 raeburn 1445: unless ($daemonrunning =~ m{^www[^/]+\Q$cmd -m 400 -v\E$}) {
1.10 raeburn 1446: $stopsrvcs{$service} = 1;
1447: }
1448: } else {
1449: $stopsrvcs{$service} = 1;
1450: }
1.1 raeburn 1451: }
1452: }
1.10 raeburn 1453: }
1.1 raeburn 1454: return \%stopsrvcs;
1455: }
1456:
1457: sub need_download {
1.77 raeburn 1458: my ($distro,$instdir) = @_;
1.1 raeburn 1459: my $needs_download = 1;
1460: my ($production,$testing,$stdsizes) = &download_versionslist();
1.77 raeburn 1461: my ($localcurrent,$localtesting,%tarball,%localsize,%bymodtime,
1.1 raeburn 1462: %bysize,$filetouse,$downloadstatus);
1.77 raeburn 1463: if (opendir(my $dir,$instdir)) {
1.1 raeburn 1464: my (@lcdownloads,$version);
1465: foreach my $file (readdir($dir)) {
1466: if ($file =~ /^loncapa\-([\w\-.]+)\.tar\.gz$/) {
1467: $version = $1;
1468: } else {
1469: next;
1470: }
1471: if (ref($stdsizes) eq 'HASH') {
1472: if ($version eq 'current') {
1.77 raeburn 1473: my @stats = stat("$instdir/$file");
1.1 raeburn 1474: $localcurrent = $stats[7];
1.4 raeburn 1475: if ($localcurrent == $stdsizes->{$production}) {
1.1 raeburn 1476: $needs_download = 0;
1477: $filetouse = $file;
1478: }
1479: } elsif ($version eq 'testing') {
1.77 raeburn 1480: my @stats = stat("$instdir/$file");
1.1 raeburn 1481: $localtesting = $stats[7];
1.4 raeburn 1482: if ($localtesting == $stdsizes->{$testing}) {
1.1 raeburn 1483: $needs_download = 0;
1484: $filetouse = $file;
1485: }
1486: }
1487: }
1488: $tarball{$version} = $file;
1489: push(@lcdownloads,$version);
1490: }
1491: if ($needs_download) {
1492: if (@lcdownloads > 0) {
1493: foreach my $version (@lcdownloads) {
1.77 raeburn 1494: my @stats = stat("$instdir/$tarball{$version}");
1.1 raeburn 1495: my $mtime = $stats[9];
1496: $localsize{$version} = $stats[7];
1497: if ($mtime) {
1498: push(@{$bymodtime{$mtime}},$version);
1499: }
1500: if ($localsize{$version}) {
1501: push(@{$bysize{$localsize{$version}}},$version);
1502: }
1503: }
1504: if ($testing) {
1505: if (exists($localsize{$testing})) {
1506: if ($stdsizes->{$testing} == $localsize{$testing}) {
1507: $needs_download = 0;
1508: $filetouse = 'loncapa-'.$testing.'.tar.gz';
1509: }
1510: }
1511: }
1512: if ($needs_download) {
1513: if ($production) {
1514: if (exists($localsize{$production})) {
1515: if ($stdsizes->{$production} == $localsize{$production}) {
1516: $needs_download = 0;
1517: $filetouse = 'loncapa-'.$production.'.tar.gz';
1518: }
1519: }
1520: }
1521: }
1522: if ($needs_download) {
1523: my @sorted = sort { $b <=> $a } keys(%bymodtime);
1524: my $newest = $sorted[0];
1525: if (ref($bymodtime{$newest}) eq 'ARRAY') {
1526: $downloadstatus =
1.77 raeburn 1527: "Latest LON-CAPA source download in $instdir is: ".
1.1 raeburn 1528: join(',',@{$bymodtime{$newest}})." (downloaded ".
1529: localtime($newest).")\n";
1530: }
1531: } else {
1532: $downloadstatus =
1.77 raeburn 1533: "The $instdir directory already contains the latest LON-CAPA version:".
1.1 raeburn 1534: "\n".$filetouse."\n"."which can be used for installation.\n";
1535: }
1536: } else {
1.77 raeburn 1537: $downloadstatus = "The $instdir directory does not appear to contain any downloaded LON-CAPA source code files which can be used for installation.\n";
1.1 raeburn 1538: }
1539: }
1540: } else {
1.77 raeburn 1541: $downloadstatus = "Could not open $instdir directory to look for existing downloads of LON-CAPA source code.\n";
1.1 raeburn 1542: }
1543: return ($needs_download,$downloadstatus,$filetouse,$production,$testing);
1544: }
1545:
1546: sub check_mysql_setup {
1.71 raeburn 1547: my ($instdir,$dsn,$distro) = @_;
1548: my ($mysqlsetup,$has_pass,$mysql_unix_socket,$mysql_has_wwwuser);
1.1 raeburn 1549: my $dbh = DBI->connect($dsn,'root','',{'PrintError'=>0});
1.68 raeburn 1550: my ($mysqlversion,$mysqlsubver,$mysqlname) = &get_mysql_version();
1551: if (($mysqlname =~ /^MariaDB/i) && ($mysqlversion >= 10.4)) {
1552: if ($dbh) {
1553: my $sth = $dbh->prepare("SELECT Priv FROM mysql.global_priv WHERE (User = 'root' AND Host ='localhost')");
1554: $sth->execute();
1555: while (my $priv = $sth->fetchrow_array) {
1556: if ($priv =~ /unix_socket/) {
1557: $mysql_unix_socket = 1;
1558: last;
1559: }
1560: }
1561: $sth->finish();
1562: if ($mysql_unix_socket) {
1563: print_and_log(&mt('MariaDB using unix_socket for root access from localhost.')."\n");
1564: $mysqlsetup = 'rootok';
1.71 raeburn 1565: $mysql_has_wwwuser = &check_mysql_wwwuser($dbh);
1.68 raeburn 1566: return ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser,$mysql_unix_socket);
1567: }
1568: }
1569: }
1.1 raeburn 1570: if ($dbh) {
1.71 raeburn 1571: $mysqlsetup = 'noroot';
1572: if (($mysqlname !~ /^MariaDB/i) && ($mysqlversion >= 5.7)) {
1573: my $sth = $dbh->prepare("SELECT plugin from mysql.user where User='root'");
1574: $sth->execute();
1575: while (my $priv = $sth->fetchrow_array) {
1576: if ($priv =~ /auth_socket/) {
1577: $mysql_unix_socket = 1;
1578: last;
1579: }
1580: }
1581: $sth->finish();
1582: if ($mysql_unix_socket) {
1583: print_and_log(&mt('MySQL using unix_socket for root access from localhost.')."\n");
1584: $mysqlsetup = 'rootok';
1585: $mysql_has_wwwuser = &check_mysql_wwwuser($dbh);
1586: return ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser,$mysql_unix_socket);
1587: }
1588: }
1.1 raeburn 1589: } elsif ($DBI::err =~ /1045/) {
1590: $has_pass = 1;
1.34 raeburn 1591: } elsif ($distro =~ /^ubuntu(\d+)$/) {
1592: my $version = $1;
1593: if ($1 > 12) {
1594: print_and_log(&mt('Restarting mysql, please be patient')."\n");
1595: if (open (PIPE, "service mysql restart 2>&1 |")) {
1596: while (<PIPE>) {
1597: print $_;
1598: }
1599: close(PIPE);
1600: }
1601: $dbh = DBI->connect($dsn,'root','',{'PrintError'=>0});
1602: if ($dbh) {
1603: $mysqlsetup = 'noroot';
1.71 raeburn 1604: $mysql_has_wwwuser = &check_mysql_wwwuser($dbh);
1.34 raeburn 1605: } elsif ($DBI::err =~ /1045/) {
1606: $has_pass = 1;
1607: } else {
1608: $mysqlsetup = 'needsrestart';
1.71 raeburn 1609: $mysql_has_wwwuser = &check_mysql_wwwuser();
1.34 raeburn 1610: return ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser);
1611: }
1612: }
1.1 raeburn 1613: }
1614: if ($has_pass) {
1615: print &mt('You have already set a root password for the MySQL database.')."\n";
1616: my $currpass = &get_mysql_password(&mt('Please enter the password now'));
1617: $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
1618: if ($dbh) {
1619: $mysqlsetup = 'rootok';
1620: print_and_log(&mt('Password accepted.')."\n");
1.71 raeburn 1621: $mysql_has_wwwuser = &check_mysql_wwwuser($dbh);
1.1 raeburn 1622: } else {
1623: $mysqlsetup = 'rootfail';
1624: print_and_log(&mt('Problem accessing MySQL.')."\n");
1625: if ($DBI::err =~ /1045/) {
1626: print_and_log(&mt('Perhaps the password was incorrect?')."\n");
1627: print &mt('Try again?').' ';
1628: $currpass = &get_mysql_password(&mt('Re-enter password now'));
1629: $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
1630: if ($dbh) {
1631: $mysqlsetup = 'rootok';
1632: print_and_log(&mt('Password accepted.')."\n");
1.71 raeburn 1633: $mysql_has_wwwuser = &check_mysql_wwwuser($dbh);
1.1 raeburn 1634: } else {
1635: if ($DBI::err =~ /1045/) {
1636: print_and_log(&mt('Incorrect password.')."\n");
1637: }
1.71 raeburn 1638: $mysql_has_wwwuser = &check_mysql_wwwuser();
1.1 raeburn 1639: }
1640: }
1641: }
1.34 raeburn 1642: } elsif ($mysqlsetup ne 'noroot') {
1.1 raeburn 1643: print_and_log(&mt('Problem accessing MySQL.')."\n");
1644: $mysqlsetup = 'rootfail';
1.71 raeburn 1645: $mysql_has_wwwuser = &check_mysql_wwwuser();
1.1 raeburn 1646: }
1.34 raeburn 1647: return ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser);
1.1 raeburn 1648: }
1649:
1650: sub check_mysql_wwwuser {
1.71 raeburn 1651: my ($dbh) = @_;
1.1 raeburn 1652: my $mysql_wwwuser;
1.71 raeburn 1653: if ($dbh) {
1654: $mysql_wwwuser = $dbh->selectrow_array("SELECT COUNT(User) FROM mysql.user WHERE (User = 'www' AND Host ='localhost')");
1655: } else {
1656: my $dbhn = DBI->connect("DBI:mysql:database=information_schema",'www','localhostkey',
1657: {PrintError => +0}) || return;
1658: if ($dbhn) {
1659: $mysql_wwwuser = 1;
1660: $dbhn->disconnect;
1661: }
1.1 raeburn 1662: }
1663: return $mysql_wwwuser;
1664: }
1665:
1666: sub check_loncapa_mysqldb {
1667: my ($dbh) = @_;
1668: my $has_lcdb;
1669: if (ref($dbh)) {
1670: my $sth = $dbh->prepare("SHOW DATABASES");
1671: $sth->execute();
1672: while (my $dbname = $sth->fetchrow_array) {
1673: if ($dbname eq 'loncapa') {
1674: $has_lcdb = 1;
1675: last;
1676: }
1677: }
1678: $sth->finish();
1679: }
1680: return $has_lcdb;
1681: }
1682:
1683: sub get_pathto_iptables {
1684: my $iptables;
1685: if (-e '/sbin/iptables') {
1686: $iptables = '/sbin/iptables';
1687: } elsif (-e '/usr/sbin/iptables') {
1688: $iptables = '/usr/sbin/iptables';
1689: } else {
1690: print &mt('Unable to find iptables command.')."\n";
1691: }
1692: return $iptables;
1693: }
1694:
1695: sub firewall_is_active {
1696: if (-e '/proc/net/ip_tables_names') {
1.49 raeburn 1697: if (open(PIPE,'cat /proc/net/ip_tables_names |grep filter |')) {
1698: my $status = <PIPE>;
1699: close(PIPE);
1700: chomp($status);
1701: if ($status eq 'filter') {
1702: return 1;
1703: }
1704: }
1.1 raeburn 1705: }
1.49 raeburn 1706: return 0;
1.1 raeburn 1707: }
1708:
1709: sub get_fw_chains {
1.5 raeburn 1710: my ($iptables,$distro) = @_;
1.1 raeburn 1711: my @fw_chains;
1712: my $suse_config = "/etc/sysconfig/SuSEfirewall2";
1713: my $ubuntu_config = "/etc/ufw/ufw.conf";
1714: if (-e $suse_config) {
1715: push(@fw_chains,'input_ext');
1716: } else {
1717: my @posschains;
1718: if (-e $ubuntu_config) {
1719: @posschains = ('ufw-user-input','INPUT');
1.5 raeburn 1720: } elsif ($distro =~ /^debian5/) {
1721: @posschains = ('INPUT');
1.49 raeburn 1722: } elsif ($distro =~ /^(suse|sles)(\d+)/) {
1723: @posschains = ('IN_public');
1.1 raeburn 1724: } else {
1725: @posschains = ('RH-Firewall-1-INPUT','INPUT');
1726: if (!-e '/etc/sysconfig/iptables') {
1727: if (!-e '/var/lib/iptables') {
1728: print &mt('Unable to find iptables file containing static definitions.')."\n";
1729: }
1730: push(@fw_chains,'RH-Firewall-1-INPUT');
1731: }
1732: }
1733: if ($iptables eq '') {
1734: $iptables = &get_pathto_iptables();
1735: }
1736: my %counts;
1737: if (open(PIPE,"$iptables -L -n |")) {
1738: while(<PIPE>) {
1739: foreach my $chain (@posschains) {
1740: if (/(\Q$chain\E)/) {
1741: $counts{$1} ++;
1742: }
1743: }
1744: }
1745: close(PIPE);
1746: }
1747: foreach my $fw_chain (@posschains) {
1748: if ($counts{$fw_chain}) {
1749: unless(grep(/^\Q$fw_chain\E$/,@fw_chains)) {
1750: push(@fw_chains,$fw_chain);
1751: }
1752: }
1753: }
1754: }
1755: return @fw_chains;
1756: }
1757:
1758: sub firewall_is_port_open {
1759: my ($iptables,$fw_chain,$port) = @_;
1760: # returns 1 if the firewall port is open, 0 if not.
1761: #
1762: # check if firewall is active or installed
1763: return if (! &firewall_is_active());
1764: my $count = 0;
1765: if (open(PIPE,"$iptables -L $fw_chain -n |")) {
1766: while(<PIPE>) {
1767: if (/tcp dpt\:\Q$port\E/) {
1768: $count ++;
1769: last;
1770: }
1771: }
1772: close(PIPE);
1773: } else {
1774: print &mt('Firewall status not checked: unable to run [_1].','iptables -L')."\n";
1775: }
1776: return $count;
1777: }
1778:
1779: sub get_mysql_password {
1780: my ($prompt) = @_;
1781: local $| = 1;
1782: print $prompt.': ';
1783: my $newpasswd = '';
1784: ReadMode 'raw';
1785: my $key;
1786: while(ord($key = ReadKey(0)) != 10) {
1787: if(ord($key) == 127 || ord($key) == 8) {
1788: chop($newpasswd);
1789: print "\b \b";
1790: } elsif(!ord($key) < 32) {
1791: $newpasswd .= $key;
1792: print '*';
1793: }
1794: }
1795: ReadMode 'normal';
1796: print "\n";
1797: return $newpasswd;
1798: }
1799:
1800: sub check_SuSEfirewall2_setup {
1801: my ($instdir) = @_;
1802: my $need_override = 1;
1.9 raeburn 1803: if ((-e "/etc/insserv/overrides/SuSEfirewall2_setup") && (-e "$instdir/sles-suse/SuSEfirewall2_setup")) {
1804: if (open(PIPE, "diff --brief $instdir/sles-suse/SuSEfirewall2_setup /etc/insserv/overrides/SuSEfirewall2_setup |")) {
1.1 raeburn 1805: my $diffres = <PIPE>;
1806: close(PIPE);
1807: chomp($diffres);
1808: unless ($diffres) {
1809: $need_override = 0;
1810: }
1811: }
1812: }
1813: return $need_override;
1814: }
1815:
1816: sub download_versionslist {
1817: my ($production,$testing,%sizes);
1818: if (-e "latest.txt") {
1819: unlink("latest.txt");
1820: }
1821: my $rtncode = system("wget http://install.loncapa.org/versions/latest.txt ".
1822: "> /dev/null 2>&1");
1823: if (!$rtncode) {
1824: if (open(my $fh,"<latest.txt")) {
1825: my @info = <$fh>;
1826: close($fh);
1827: foreach my $line (@info) {
1828: chomp();
1829: if ($line =~ /^\QLATEST-IS: \E([\w\-.]+):(\d+)$/) {
1830: $production = $1;
1831: $sizes{$1} = $2;
1832: } elsif ($line =~ /^LATEST-TESTING-IS: \E([\w\-.]+):(\d+)$/) {
1833: $testing = $1;
1834: $sizes{$1} = $2;
1835: }
1836: }
1837: }
1838: }
1839: return ($production,$testing,\%sizes);
1840: }
1841:
1842: #
1843: # End helper routines.
1844: # Main script starts here
1845: #
1846:
1847: print "
1848: ********************************************************************
1849:
1850: ".&mt('Welcome to LON-CAPA')."
1851:
1852: ".&mt('This script will configure your system for installation of LON-CAPA.')."
1853:
1854: ********************************************************************
1855:
1856: ".&mt('The following actions are available:')."
1857:
1.4 raeburn 1858: ".&mt('1.')." ".&mt('Create the www user/group.')."
1.1 raeburn 1859: ".&mt('This is the user/group ownership under which Apache child processes run.')."
1860: ".&mt('It also owns most directories within the /home/httpd directory.')."
1861: ".&mt('This directory is where most LON-CAPA files and directories are stored.')."
1.4 raeburn 1862: ".&mt('2.')." ".&mt('Install the package LON-CAPA uses to authenticate users.')."
1863: ".&mt('3.')." ".&mt('Set-up the MySQL database.')."
1864: ".&mt('4.')." ".&mt('Set-up MySQL permissions.')."
1865: ".&mt('5.')." ".&mt('Configure Apache web server.')."
1.46 raeburn 1866: ".&mt('6.')." ".&mt('Configure SSL for Apache web server.')."
1867: ".&mt('7.')." ".&mt('Configure start-up of services.')."
1868: ".&mt('8.')." ".&mt('Check firewall settings.')."
1869: ".&mt('9.')." ".&mt('Stop services not used by LON-CAPA,')."
1.1 raeburn 1870: ".&mt('i.e., services for a print server: [_1] daemon.',"'cups'")."
1.46 raeburn 1871: ".&mt('10.')." ".&mt('Download LON-CAPA source code in readiness for installation.')."
1.1 raeburn 1872:
1873: ".&mt('Typically, you will run this script only once, when you first install LON-CAPA.')."
1874:
1875: ".&mt('The script will analyze your system to determine which actions are recommended.')."
1876: ".&mt('The script will then prompt you to choose the actions you would like taken.')."
1877:
1878: ".&mt('For each the recommended action will be selected if you hit Enter/Return.')."
1879: ".&mt('To override the default, type the lower case option from the two options listed.')."
1880: ".&mt('So, if the default is "yes", ~[Y/n~] will be shown -- type n to override.')."
1881: ".&mt('Whereas if the default is "no", ~[y/N~] will be shown -- type y to override.')."
1882:
1883: ".&mt('To accept the default, simply hit Enter/Return on your keyboard.')."
1884: ".&mt('Otherwise type: y or n then hit the Enter/Return key.')."
1885:
1886: ".&mt('Once a choice has been entered for all nine actions, required changes will be made.')."
1887: ".&mt('Feedback will be displayed on screen, and also stored in: [_1].','loncapa_install.log')."
1888:
1889: ".&mt('Continue? ~[Y/n~] ');
1890:
1891: my $go_on = &get_user_selection(1);
1892: if (!$go_on) {
1893: exit;
1894: }
1895:
1896: my $instdir = `pwd`;
1897: chomp($instdir);
1898:
1899: my %callsub;
1900: my @actions = ('wwwuser','pwauth','mysql','mysqlperms','apache',
1.46 raeburn 1901: 'apachessl','runlevels','firewall','stopsrvcs','download');
1.1 raeburn 1902: my %prompts = &texthash(
1903: wwwuser => "Create the 'www' user?",
1904: pwauth => 'Install the package LON-CAPA uses to authenticate users?',
1905: mysql => 'Set-up the MySQL database?',
1906: mysqlperms => 'Set-up MySQL permissions?',
1907: apache => 'Configure Apache web server?',
1.46 raeburn 1908: apachessl => 'Configure SSL for Apache web server?',
1.1 raeburn 1909: runlevels => 'Set overrides for start-up order of services?',
1910: firewall => 'Configure firewall settings for Apache',
1911: stopsrvcs => 'Stop extra services not required on a LON-CAPA server?',
1912: download => 'Download LON-CAPA source code in readiness for installation?',
1913: );
1914:
1.46 raeburn 1915: print "\n".&mt('Checking system status ...')."\n\n";
1.1 raeburn 1916:
1917: my $dsn = "DBI:mysql:database=mysql";
1.34 raeburn 1918: my ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,$mysqlrestart,
1.68 raeburn 1919: $recommended,$dbh,$has_pass,$mysql_unix_socket,$has_lcdb,$downloadstatus,
1920: $filetouse,$production,$testing,$apachefw,$uses_systemctl,$hostname,$hostip,
1921: $sslhostsfiles,$has_std,$has_int,$rewritenum,$nochgstd,$nochgint) =
1922: &check_required($instdir,$dsn);
1.1 raeburn 1923: if ($distro eq '') {
1924: print "\n".&mt('Linux distribution could not be verified as a supported distribution.')."\n".
1925: &mt('The following are supported: [_1].',
1926: 'CentOS, RedHat Enterprise, Fedora, Scientific Linux, '.
1.56 raeburn 1927: 'Oracle Linux, openSuSE, SLES, Ubuntu LTS, Debian')."\n\n".
1.1 raeburn 1928: &mt('Stopping execution.')."\n";
1929: exit;
1930: }
1.34 raeburn 1931: if ($mysqlrestart) {
1932: print "\n".&mt('The mysql daemon needs to be restarted using the following command:')."\n".
1933: $mysqlrestart."\n\n".
1934: &mt('Stopping execution of install.pl script.')."\n".
1935: &mt('Please run the install.pl script again, once you have restarted mysql.')."\n";
1936: exit;
1937: }
1.6 raeburn 1938: if ($localecmd ne '') {
1939: 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";
1940: 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".
1941: $localecmd."\n\n".
1942: &mt('Stopping execution.')."\n";
1943: exit;
1944: }
1.1 raeburn 1945: if (!$gotprereqs) {
1.12 raeburn 1946: print "\n".&mt('The LONCAPA-prerequisites package is not installed.')."\n".
1.1 raeburn 1947: &mt('The following command can be used to install the package (and dependencies):')."\n\n".
1948: $updatecmd."\n\n";
1949: if ($installnow eq '') {
1950: exit;
1951: } else {
1952: print &mt('Run command? ~[Y/n~]');
1953: my $install_prereq = &get_user_selection(1);
1954: if ($install_prereq) {
1955: if (open(PIPE,'|-',$installnow)) {
1956: close(PIPE);
1957: $gotprereqs = &check_prerequisites($packagecmd,$distro);
1958: if (!$gotprereqs) {
1.12 raeburn 1959: print &mt('The LONCAPA-prerequisites package is not installed.')."\n".
1.1 raeburn 1960: &mt('Stopping execution.')."\n";
1961: exit;
1962: } else {
1.6 raeburn 1963: ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,
1.68 raeburn 1964: $mysqlrestart,$recommended,$dbh,$has_pass,$mysql_unix_socket,
1965: $has_lcdb,$downloadstatus,$filetouse,$production,$testing,$apachefw,
1966: $uses_systemctl,$hostname,$hostip,$sslhostsfiles,$has_std,$has_int,
1967: $rewritenum,$nochgstd,$nochgint) = &check_required($instdir,$dsn);
1.1 raeburn 1968: }
1969: } else {
1.12 raeburn 1970: print &mt('Failed to run command to install LONCAPA-prerequisites')."\n";
1.1 raeburn 1971: exit;
1972: }
1973: } else {
1974: print &mt('Stopping execution.')."\n";
1975: exit;
1976: }
1977: }
1978: }
1979: unless (ref($recommended) eq 'HASH') {
1980: print "\n".&mt('An error occurred determining which actions are recommended.')."\n\n".
1981: &mt('Stopping execution.')."\n";
1982: exit;
1983: }
1984:
1985: print "\n";
1986: my $num = 0;
1987: foreach my $action (@actions) {
1988: $num ++;
1989: my ($yesno,$defaultrun);
1990: if (ref($recommended) eq 'HASH') {
1.4 raeburn 1991: if (($action eq 'runlevels') || ($action eq 'stopsrvcs')) {
1.1 raeburn 1992: $yesno = '[y/N]';
1993: if (ref($recommended->{$action}) eq 'HASH') {
1994: if (keys(%{$recommended->{$action}}) > 0) {
1995: $yesno = &mt('~[Y/n~]');
1996: $defaultrun = 1;
1997: }
1998: }
1999: } else {
2000: if ($action eq 'download') {
2001: if ($downloadstatus) {
2002: print "\n$downloadstatus\n";
2003: }
2004: }
2005: if ($recommended->{$action}) {
2006: $yesno = mt('~[Y/n~]');
2007: $defaultrun = 1;
2008: } else {
2009: $yesno = &mt('~[y/N~]');
2010: }
2011: }
2012: print $num.'. '.$prompts{$action}." $yesno ";
2013: $callsub{$action} = &get_user_selection($defaultrun);
2014: }
2015: }
2016:
2017: my $lctarball = 'loncapa-current.tar.gz';
2018: my $sourcetarball = $lctarball;
2019: if ($callsub{'download'}) {
2020: my ($production,$testing,$sizes) = &download_versionslist();
1.77 raeburn 2021: my $homedir = '/root';
2022: if ($distro =~ /^ubuntu/) {
2023: if ($instdir ne $homedir) {
2024: ($homedir) = ($instdir =~ m{^(.*)/[^/]+$});
2025: }
2026: }
1.1 raeburn 2027: if ($production && $testing) {
2028: if ($production ne $testing) {
2029: print &mt('Two recent LON-CAPA releases are available: ')."\n".
1.3 raeburn 2030: &mt('1.').' '.&mt('A production release - version: [_1].',$production)."\n".
2031: &mt('2.').' '.&mt('A testing release - version: [_1].',$testing)."\n\n".
1.77 raeburn 2032: &mt("After download, the tar.gz file will be extracted into $homedir")."\n\n".
2033: &mt("Download the production release into $instdir? ~[Y/n~]");
1.1 raeburn 2034: if (&get_user_selection(1)) {
1.4 raeburn 2035: $sourcetarball = 'loncapa-'.$production.'.tar.gz';
1.77 raeburn 2036: print "$sourcetarball will be downloaded into $instdir\n";
1.1 raeburn 2037: } else {
2038: print "\n".&mt('Download the testing release? ~[Y/n~]');
2039: if (&get_user_selection(1)) {
1.4 raeburn 2040: $sourcetarball = 'loncapa-'.$testing.'.tar.gz';
1.77 raeburn 2041: print "$sourcetarball will be downloaded into $instdir\n";
2042: } else {
2043: $callsub{'download'} = 0;
1.1 raeburn 2044: }
2045: }
2046: }
2047: } elsif ($production) {
2048: print &mt('The most recent LON-CAPA release is version: [_1].',$production)."\n".
1.77 raeburn 2049: &mt("After download, the tar.gz file will be extracted into $homedir")."\n\n".
2050: &mt("Download the production release into $instdir? ~[Y/n~]");
1.1 raeburn 2051: if (&get_user_selection(1)) {
1.20 raeburn 2052: $sourcetarball = 'loncapa-'.$production.'.tar.gz';
1.77 raeburn 2053: print "$sourcetarball will be downloaded into $instdir\n";
2054: } else {
2055: $callsub{'download'} = 0;
1.1 raeburn 2056: }
2057: }
2058: } elsif ($filetouse ne '') {
2059: $sourcetarball = $filetouse;
2060: }
2061:
2062: print_and_log("\n");
2063:
2064: # Each action: report if skipping, or perform action and provide feedback.
2065: if ($callsub{'wwwuser'}) {
2066: &setup_www();
2067: } else {
2068: &print_and_log(&mt('Skipping creation of user [_1].',"'www'")."\n");
2069: }
2070:
2071: if ($callsub{'pwauth'}) {
1.4 raeburn 2072: &build_and_install_mod_auth_external($instdir);
1.1 raeburn 2073: } else {
2074: &print_and_log(&mt('Skipping [_1] installation.',"'pwauth'")."\n");
2075: }
2076:
2077: if ($callsub{'mysql'}) {
2078: if ($dbh) {
1.68 raeburn 2079: &setup_mysql($callsub{'mysqlperms'},$dbh,$has_pass,
1.74 raeburn 2080: $mysql_unix_socket,$has_lcdb,$distro);
1.1 raeburn 2081: } else {
2082: print &mt('Unable to configure MySQL because access is denied.')."\n";
2083: }
2084: } else {
2085: &print_and_log(&mt('Skipping configuration of MySQL.')."\n");
2086: if ($callsub{'mysqlperms'}) {
2087: if ($dbh) {
1.68 raeburn 2088: &setup_mysql_permissions($dbh,$has_pass,$mysql_unix_socket);
1.1 raeburn 2089: } else {
2090: print &mt('Unable to configure MySQL because access is denied.')."\n";
2091: }
2092: } else {
2093: &print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
2094: }
2095: }
2096:
2097: if ($dbh) {
2098: if (!$dbh->disconnect) {
2099: &print_and_log(&mt('Failed to disconnect from MySQL:')."\n".
2100: $dbh->errstr);
2101: }
2102: }
2103:
2104: if ($callsub{'apache'}) {
2105: if ($distro =~ /^(suse|sles)/) {
1.49 raeburn 2106: ©_apache2_suseconf($instdir,$hostname,$distro);
1.1 raeburn 2107: } elsif ($distro =~ /^(debian|ubuntu)/) {
1.46 raeburn 2108: ©_apache2_debconf($instdir,$distro,$hostname);
1.1 raeburn 2109: } else {
1.46 raeburn 2110: ©_httpd_conf($instdir,$distro,$hostname);
1.59 raeburn 2111: ©_mpm_conf($instdir,$distro);
1.1 raeburn 2112: }
2113: } else {
2114: print_and_log(&mt('Skipping configuration of Apache web server.')."\n");
2115: }
2116:
1.46 raeburn 2117: if ($callsub{'apachessl'}) {
1.47 raeburn 2118: my $targetdir = '/etc/httpd/conf.d';
1.46 raeburn 2119: if ($distro =~ /^(suse|sles)/) {
1.47 raeburn 2120: $targetdir = '/etc/apache2/vhosts.d';
1.46 raeburn 2121: } elsif ($distro =~ /^(debian|ubuntu)/) {
1.47 raeburn 2122: $targetdir = '/etc/apache2/sites-available';
2123: }
2124: my ($new_rewrite,$new_int) =
2125: ©_apache_sslconf_files($distro,$hostname,$hostip,$instdir,$targetdir,$sslhostsfiles,
2126: $has_std,$has_int,$rewritenum,$nochgstd,$nochgint);
2127: if ($distro =~ /^(debian|ubuntu)/) {
2128: my $apache2_sites_enabled_dir = '/etc/apache2/sites-enabled';
2129: if (-d $apache2_sites_enabled_dir) {
2130: if ($has_std ne '') {
2131: unless ((-l "$apache2_sites_enabled_dir/$has_std") && (readlink(("$apache2_sites_enabled_dir/$has_std") eq "$targetdir/$has_std"))) {
2132: my $made_symlink = eval { symlink("$targetdir/$has_std","$apache2_sites_enabled_dir/$has_std"); 1};
2133: if ($made_symlink) {
2134: print_and_log(&mt('Enabling "[_1]" Apache SSL configuration.',$has_std)."\n");
2135: }
2136: }
2137: }
2138: if (($has_int ne '') && ($has_int ne $has_std)) {
2139: unless ((-l "$apache2_sites_enabled_dir/$has_int") && (readlink("$apache2_sites_enabled_dir/$has_int") eq "$targetdir/$has_int")) {
2140: my $made_symlink = eval { symlink("$targetdir/$has_int","$apache2_sites_enabled_dir/$has_int"); 1 };
2141: if ($made_symlink) {
2142: print_and_log(&mt('Enabling "[_1]" Apache SSL configuration.',$has_int)."\n");
2143: }
2144: }
1.46 raeburn 2145: }
2146: }
2147: }
2148: print_and_log("\n");
2149: } else {
2150: print_and_log(&mt('Skipping configuration of SSL for Apache web server.')."\n");
2151: }
2152:
1.1 raeburn 2153: if ($callsub{'runlevels'}) {
2154: my $count = 0;
2155: if (ref($recommended) eq 'HASH') {
2156: if (ref($recommended->{'runlevels'}) eq 'HASH') {
2157: foreach my $type (keys(%{$recommended->{'runlevels'}})) {
2158: next if ($type eq 'insserv');
2159: $count ++;
2160: my $command = $recommended->{'runlevels'}{$type};
2161: if ($command ne '') {
2162: print_and_log(&mt('Runlevel update command run: [_1].',$command)."\n");
2163: system($command);
2164: }
2165: }
2166: if (!$count) {
2167: print_and_log(&mt('No runlevel updates required.')."\n");
2168: }
2169: }
2170: }
1.49 raeburn 2171: if ($distro =~ /^(suse|sles)(\d+)/) {
2172: unless(($1 eq 'sles') && ($2 >= 15)) {
2173: &update_SuSEfirewall2_setup($instdir);
2174: }
1.11 raeburn 2175: }
1.1 raeburn 2176: } else {
2177: &print_and_log(&mt('Skipping setting override for start-up order of services.')."\n");
2178: }
2179:
2180: if ($callsub{'firewall'}) {
1.53 raeburn 2181: my ($firewalld,$zone) = &uses_firewalld($distro);
2182: if ($firewalld) {
1.49 raeburn 2183: my (%current,%added);
1.53 raeburn 2184: if (open(PIPE,"firewall-cmd --permanent --zone=$zone --list-services |")) {
1.49 raeburn 2185: my $svc = <PIPE>;
2186: close(PIPE);
2187: chomp($svc);
2188: map { $current{$_} = 1; } (split(/\s+/,$svc));
2189: }
2190: foreach my $service ('http','https') {
2191: unless ($current{$service}) {
1.53 raeburn 2192: if (open(PIPE,"firewall-cmd --permanent --zone=$zone --add-service=$service |")) {
1.49 raeburn 2193: my $result = <PIPE>;
2194: if ($result =~ /^success/) {
2195: $added{$service} = 1;
2196: }
2197: }
2198: }
2199: }
2200: if (keys(%added) > 0) {
2201: print &mt('Firewall configured to allow access for: [_1].',
2202: join(', ',sort(keys(%added))))."\n";
1.77 raeburn 2203: system('firewall-cmd --reload');
1.49 raeburn 2204: }
2205: if ($current{'http'} || $current{'https'}) {
2206: print &mt('Firewall already configured to allow access for:[_1].',
2207: (($current{'http'})? ' http':'').(($current{'https'})? ' https':''))."\n";
2208: }
2209: unless ($current{'ssh'}) {
1.72 raeburn 2210: print &mt('If you would like to allow access to ssh from outside, use the commands:')."\n".
2211: "firewall-cmd --permanent --zone=$zone --add-service=ssh\n".
2212: "firewall-cmd --reload\n";
1.49 raeburn 2213: }
2214: } elsif ($distro =~ /^(suse|sles)/) {
1.5 raeburn 2215: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
2216: 'yast -- Security and Users -> Firewall -> Interfaces',
1.49 raeburn 2217: 'ssh, http, https')."\n";
1.5 raeburn 2218: } elsif ($distro =~ /^(debian|ubuntu)(\d+)/) {
2219: if (($1 eq 'ubuntu') || ($2 > 5)) {
2220: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
2221: 'ufw','ssh, http, https')."\n";
2222: } else {
2223: my $fwadded = &get_iptables_rules($distro,$instdir,$apachefw);
2224: if ($fwadded) {
2225: print &mt('Enable firewall? ~[Y/n~]');
2226: my $enable_iptables = &get_user_selection(1);
2227: if ($enable_iptables) {
2228: system('/etc/network/if-pre-up.d/iptables');
2229: print &mt('Firewall enabled using rules defined in [_1].',
2230: '/etc/iptables.loncapa.rules');
2231: }
2232: }
2233: }
1.57 raeburn 2234: } elsif ($distro =~ /^(scientific|oracle)/) {
1.11 raeburn 2235: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
2236: 'system-config-firewall-tui -- Customize',
2237: 'ssh, http')."\n";
1.1 raeburn 2238: } else {
1.53 raeburn 2239: my $version;
2240: if ($distro =~ /^(redhat|centos)(\d+)$/) {
2241: $version = $1;
2242: }
2243: if ($version > 5) {
2244: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
2245: 'system-config-firewall-tui -- Customize',
2246: 'ssh, http')."\n";
2247: } else {
2248: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
2249: 'setup -- Firewall configuration -> Customize',
2250: 'ssh, http, https')."\n";
2251: }
1.1 raeburn 2252: }
2253: } else {
1.5 raeburn 2254: &print_and_log(&mt('Skipping Firewall configuration.')."\n");
1.1 raeburn 2255: }
2256:
2257: if ($callsub{'stopsrvcs'}) {
1.45 raeburn 2258: &kill_extra_services($distro,$recommended->{'stopsrvcs'},$uses_systemctl);
1.1 raeburn 2259: } else {
1.10 raeburn 2260: &print_and_log(&mt('Skipping stopping unnecessary service ([_1] daemons).',"'cups','memcached'")."\n");
1.1 raeburn 2261: }
2262:
2263: my ($have_tarball,$updateshown);
2264: if ($callsub{'download'}) {
2265: ($have_tarball,$updateshown) = &download_loncapa($instdir,$sourcetarball);
2266: } else {
2267: print_and_log(&mt('Skipping download of LON-CAPA tar file.')."\n\n");
2268: print &mt('LON-CAPA is available for download from: [_1]',
2269: 'http://install.loncapa.org/')."\n";
2270: if (!-e '/etc/loncapa-release') {
1.77 raeburn 2271: &print_and_log(&mt('LON-CAPA is not yet installed on your system.')."\n\n";
2272: unless ($filetouse) {
2273: &print_and_log(&mt('You may retrieve the source for LON-CAPA by executing:')."\n".
2274: "wget http://install.loncapa.org/versions/$lctarball\n");
2275: }
1.1 raeburn 2276: } else {
2277: my $currentversion;
2278: if (open(my $fh,"</etc/loncapa-release")) {
2279: my $version = <$fh>;
2280: chomp($version);
2281: if ($version =~ /^\QLON-CAPA release \E([\w\-.]+)$/) {
2282: $currentversion = $1;
2283: }
2284: }
2285: if ($currentversion ne '') {
2286: print &mt('Version of LON-CAPA currently installed on this server is: [_1].',
2287: $currentversion),"\n";
2288: if ($production) {
2289: print &mt('The latest production release of LON-CAPA is [_1].',$production)."\n";
2290: }
2291: if ($testing) {
2292: print &mt('The latest testing release of LON-CAPA is [_1].',$testing)."\n";
2293: }
2294: }
2295: }
2296: if ($filetouse ne '') {
2297: $have_tarball = 1;
2298: }
2299: }
2300:
2301: print "\n".&mt('Requested configuration complete.')."\n\n";
2302: if ($have_tarball && !$updateshown) {
2303: my ($lcdir) = ($sourcetarball =~ /^([\w.\-]+)\.tar.gz$/);
1.77 raeburn 2304: if ($lcdir eq 'loncapa-current') {
2305: $lcdir = "loncapa-X.Y.Z (X.Y.Z should correspond to a version number like '2.11.3')";
2306: }
1.71 raeburn 2307: my ($apachename,$lc_uses_systemctl,$uses_sudo);
2308: if ($distro =~ /^(suse|sles|debian|ubuntu)([\d.]+)/) {
2309: if (($1 eq 'suse') && ($2 < 10)) {
2310: $apachename = 'apache';
2311: } else {
2312: $apachename = 'apache2';
2313: }
2314: } else {
2315: $apachename = 'httpd';
2316: }
2317: if ($distro =~ /^oracle(\d+)$/) {
2318: if ($1 > 6) {
2319: $lc_uses_systemctl = 1;
2320: }
1.79 ! raeburn 2321: } elsif ($distro =~ /^(?:rhes|centos|rocky|alma)(\d+)$/) {
1.71 raeburn 2322: if ($1 > 7) {
2323: $lc_uses_systemctl = 1;
2324: }
2325: } elsif ($distro =~ /^ubuntu(\d+)$/) {
2326: if ($1 > 16) {
2327: $lc_uses_systemctl = 1;
2328: }
2329: $uses_sudo = 1;
2330: } elsif ($distro =~ /^sles(\d+)$/) {
2331: if ($1 > 12) {
2332: $lc_uses_systemctl = 1;
2333: }
2334: }
1.1 raeburn 2335: if (!-e '/etc/loncapa-release') {
2336: print &mt('If you are now ready to install LON-CAPA, enter the following commands:')."\n\n";
2337: } else {
1.71 raeburn 2338: my $lcstop = '/etc/init.d/loncontrol stop';
2339: if ($lc_uses_systemctl) {
2340: $lcstop = 'systemctl stop loncontrol';
2341: }
2342: my $apachestop = "/etc/init.d/$apachename stop";
2343: if ($uses_systemctl) {
2344: $apachestop = "systemctl stop $apachename";
2345: }
2346: if ($uses_sudo) {
2347: $lcstop = 'sudo '.$lcstop;
2348: $apachestop = 'sudo '.$apachestop;
1.1 raeburn 2349: }
1.71 raeburn 2350: print &mt('If you are now ready to update LON-CAPA, enter the following commands:').
1.77 raeburn 2351: "\n\n$lcstop\n$apachestop\n";
1.1 raeburn 2352: }
1.77 raeburn 2353: my ($extract,$update);
2354: my $homedir = '/root';
2355: if ($uses_sudo) {
2356: $extract = 'sudo ';
2357: $update = 'sudo ';
2358: if ($instdir ne $homedir) {
2359: ($homedir) = ($instdir =~ m{^(.*)/[^/]+$});
2360: }
2361: }
2362: $extract .= "tar zxf $sourcetarball --directory $homedir";
2363: $update .= './UPDATE';
2364: print "$extract\n".
2365: "cd $homedir/$lcdir\n".
2366: "$update\n";
1.1 raeburn 2367: if (-e '/etc/loncapa-release') {
1.71 raeburn 2368: my $lcstart = '/etc/init.d/loncontrol start';
2369: if ($lc_uses_systemctl) {
2370: $lcstart = '/home/httpd/perl/loncontrol start';
2371: }
2372: my $apachestart = "/etc/init.d/$apachename start";
2373: if ($uses_systemctl) {
2374: $apachestart = "systemctl start $apachename";
2375: }
2376: if ($uses_sudo) {
2377: $lcstart = 'sudo '.$lcstart;
2378: $apachestart = 'sudo '.$apachestart;
2379: }
2380: print "$lcstart\n";
2381: print "$apachestart\n";
1.1 raeburn 2382: }
2383: }
2384: exit;
2385:
2386: #
2387: # End main script
2388: #
2389:
2390: #
2391: # Routines for the actions
2392: #
2393:
2394: sub setup_www {
2395: ##
2396: ## Set up www
2397: ##
2398: print_and_log(&mt('Creating user [_1]',"'www'")."\n");
2399: # -- Add group
2400:
2401: my $status = `/usr/sbin/groupadd www`;
2402: if ($status =~ /\QGroup `www' already exists.\E/) {
2403: print &mt('Group [_1] already exists.',"'www'")."\n";
2404: } elsif ($status ne '') {
2405: print &mt('Unable to add group [_1].',"'www'")."\n";
2406: }
2407:
2408: my $gid = getgrnam('www');
2409:
2410: if (open (PIPE, "/usr/sbin/useradd -c LONCAPA -g $gid www 2>&1 |")) {
2411: $status = <PIPE>;
2412: close(PIPE);
2413: chomp($status);
2414: if ($status =~ /\QAccount `www' already exists.\E/) {
2415: print &mt('Account [_1] already exists.',"'www'")."\n";
2416: } elsif ($status ne '') {
2417: print &mt('Unable to add user [_1].',"'www'")."\n";
2418: }
2419: } else {
2420: print &mt('Unable to run command to add user [_1].',"'www'")."\n";
2421: }
2422:
2423: my $uid = &uid_of_www();
2424: if (($gid ne '') && ($uid ne '')) {
2425: if (!-e '/home/www') {
2426: mkdir('/home/www',0755);
2427: system('chown www:www /home/www');
2428: }
2429: }
2430: writelog ($status);
2431: }
2432:
2433: sub uid_of_www {
2434: my ($num) = (getpwnam('www'))[2];
2435: return $num;
2436: }
2437:
2438: sub build_and_install_mod_auth_external {
2439: my ($instdir) = @_;
2440: my $num = &uid_of_www();
2441: # Patch pwauth
2442: print_and_log(&mt('Building authentication system for LON-CAPA users.')."\n");
2443: my $patch = <<"ENDPATCH";
2444: 148c148
2445: < #define SERVER_UIDS 99 /* user "nobody" */
2446: ---
2447: > #define SERVER_UIDS $num /* user "www" */
2448: ENDPATCH
2449:
2450: if (! -e "/usr/bin/patch") {
2451: print_and_log(&mt('You must install the software development tools package: [_1], when installing Linux.',"'patch'")."\n");
2452: print_and_log(&mt('Authentication installation not completed.')."\n");
2453: return;
2454: }
2455: if (&skip_if_nonempty(`cd /tmp; tar zxf $instdir/pwauth-2.2.8.tar.gz`,
2456: &mt('Unable to extract pwauth')."\n")) {
2457: return;
2458: }
2459: my $dir = "/tmp/pwauth-2.2.8";
2460: if (open(PATCH,"| patch $dir/config.h")) {
2461: print PATCH $patch;
2462: close(PATCH);
2463: print_and_log("\n");
2464: ##
2465: ## Compile patched pwauth
2466: ##
2467: print_and_log(&mt('Compiling pwauth')."\n");
1.12 raeburn 2468: my $result = `cd $dir/; make 2>/dev/null `;
1.1 raeburn 2469: my $expected = <<"END";
2470: gcc -g -c -o pwauth.o pwauth.c
2471: gcc -o pwauth -g pwauth.o -lcrypt
2472: END
2473: if ($result eq $expected) {
2474: print_and_log(&mt('Apparent success compiling pwauth:').
2475: "\n".$result );
2476: # Install patched pwauth
2477: print_and_log(&mt('Copying pwauth to [_1]',' /usr/local/sbin')."\n");
2478: if (copy "$dir/pwauth","/usr/local/sbin/pwauth") {
1.5 raeburn 2479: if (chmod(06755, "/usr/local/sbin/pwauth")) {
1.1 raeburn 2480: print_and_log(&mt('[_1] copied successfully',"'pwauth'").
2481: "\n");
2482: } else {
2483: print &mt('Unable to set permissions on [_1].'.
2484: "/usr/local/sbin/pwauth")."\n";
2485: }
2486: } else {
2487: print &mt('Unable to copy [_1] to [_2]',
2488: "'$dir/pwauth'","/usr/local/sbin/pwauth")."\n$!\n";
2489: }
2490: } else {
2491: print &mt('Unable to compile patched [_1].'."'pwauth'")."\n";
2492: }
2493: } else {
2494: print &mt('Unable to start patch for [_1]',"'pwauth'")."\n";
2495: }
2496: print_and_log("\n");
2497: }
2498:
2499: sub kill_extra_services {
1.45 raeburn 2500: my ($distro,$stopsrvcs,$uses_systemctl) = @_;
1.1 raeburn 2501: if (ref($stopsrvcs) eq 'HASH') {
2502: my @stopping = sort(keys(%{$stopsrvcs}));
2503: if (@stopping) {
1.6 raeburn 2504: my $kill_list = join("', '",@stopping);
1.1 raeburn 2505: if ($kill_list) {
2506: $kill_list = "'".$kill_list."'";
1.6 raeburn 2507: &print_and_log("\n".&mt('Killing unnecessary services ([_1] daemon(s)).',$kill_list)."\n");
2508: foreach my $service (@stopping) {
2509: my $daemon = $service;
2510: if ($service eq 'cups') {
2511: $daemon = 'cupsd';
2512: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
2513: my $version = $1;
2514: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
2515: $daemon = 'cupsys';
2516: }
1.12 raeburn 2517: } else {
1.8 raeburn 2518: $daemon = 'cups';
1.6 raeburn 2519: }
2520: }
1.12 raeburn 2521: my $cmd = "ps -ef |grep '$daemon' |grep -v grep";
2522: if (open(PIPE,'-|',$cmd)) {
2523: my $daemonrunning = <PIPE>;
2524: chomp($daemonrunning);
2525: close(PIPE);
2526: if ($daemonrunning) {
2527: &print_and_log(`/etc/init.d/$daemon stop`);
2528: }
2529: }
1.1 raeburn 2530: &print_and_log(&mt('Removing [_1] from startup.',$service)."\n");
1.45 raeburn 2531: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
2532: my $version = $1;
2533: if (($distro =~ /^ubuntu/) && ($version > 16)) {
2534: if (ref($uses_systemctl) eq 'HASH') {
2535: if ($uses_systemctl->{$service}) {
2536: if (`systemctl is-enabled $service`) {
2537: &print_and_log(`systemctl disable $service`);
2538: }
2539: }
2540: }
2541: } else {
2542: &print_and_log(`update-rc.d -f $daemon remove`);
2543: }
1.1 raeburn 2544: } else {
1.35 raeburn 2545: if (ref($uses_systemctl) eq 'HASH') {
2546: if ($uses_systemctl->{$service}) {
2547: if (`systemctl is-enabled $service`) {
2548: &print_and_log(`systemctl disable $service`);
2549: }
2550: } else {
2551: &print_and_log(`/sbin/chkconfig --del $service`);
2552: }
2553: } else {
2554: &print_and_log(`/sbin/chkconfig --del $service`);
2555: }
1.1 raeburn 2556: }
2557: }
2558: }
2559: }
2560: }
2561: return;
2562: }
2563:
2564: sub setup_mysql {
1.74 raeburn 2565: my ($setup_mysql_permissions,$dbh,$has_pass,$mysql_unix_socket,$has_lcdb,$distro) = @_;
1.4 raeburn 2566: my @mysql_lc_commands;
1.1 raeburn 2567: unless ($has_lcdb) {
1.74 raeburn 2568: my $createcmd = 'CREATE DATABASE loncapa';
2569: if ($distro =~ /^sles(\d+)/) {
2570: if ($1 > 11) {
2571: $createcmd .= ' CHARACTER SET utf8 COLLATE utf8_general_ci';
2572: }
2573: } elsif ($distro =~ /^ubuntu(\d+)/) {
2574: if ($1 > 16) {
2575: $createcmd .= ' CHARACTER SET latin1 COLLATE latin1_swedish_ci';
2576: }
2577: }
2578: push(@mysql_lc_commands,$createcmd);
1.1 raeburn 2579: }
1.4 raeburn 2580: push(@mysql_lc_commands,"USE loncapa");
2581: push(@mysql_lc_commands,qq{
1.18 raeburn 2582: 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 2583: });
1.1 raeburn 2584: if ($setup_mysql_permissions) {
1.68 raeburn 2585: &setup_mysql_permissions($dbh,$has_pass,$mysql_unix_socket,@mysql_lc_commands);
1.1 raeburn 2586: } else {
2587: print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
2588: if ($dbh) {
1.4 raeburn 2589: if (@mysql_lc_commands) {
2590: foreach my $lccmd (@mysql_lc_commands) {
2591: $dbh->do($lccmd) || print $dbh->errstr."\n";
2592: }
2593: }
1.1 raeburn 2594: print_and_log(&mt('MySQL database set up complete.')."\n");
2595: } else {
2596: print_and_log(&mt('Problem accessing MySQL.')."\n");
2597: }
2598: }
2599: }
2600:
2601: sub setup_mysql_permissions {
1.68 raeburn 2602: my ($dbh,$has_pass,$mysql_unix_socket,@mysql_lc_commands) = @_;
1.38 raeburn 2603: my ($mysqlversion,$mysqlsubver,$mysqlname) = &get_mysql_version();
1.68 raeburn 2604: my ($usescreate,$usesauth,$is_mariadb,$hasauthcol,@mysql_commands);
1.38 raeburn 2605: if ($mysqlname =~ /^MariaDB/i) {
1.50 raeburn 2606: $is_mariadb = 1;
1.68 raeburn 2607: if ($mysqlversion >= 10.4) {
2608: $usescreate = 1;
2609: } elsif ($mysqlversion >= 10.2) {
1.38 raeburn 2610: $usesauth = 1;
1.42 raeburn 2611: } elsif ($mysqlversion >= 5.5) {
2612: $hasauthcol = 1;
1.38 raeburn 2613: }
2614: } else {
2615: if (($mysqlversion > 5.7) || (($mysqlversion == 5.7) && ($mysqlsubver > 5))) {
2616: $usesauth = 1;
1.42 raeburn 2617: } elsif (($mysqlversion >= 5.6) || (($mysqlversion == 5.5) && ($mysqlsubver >= 7))) {
2618: $hasauthcol = 1;
1.38 raeburn 2619: }
2620: }
1.68 raeburn 2621: if ($usescreate) {
2622: @mysql_commands = ("CREATE USER 'www'\@'localhost' IDENTIFIED BY 'localhostkey'");
2623: } elsif ($usesauth) {
1.76 raeburn 2624: @mysql_commands = ("INSERT user (Host, User, ssl_cipher, x509_issuer, x509_subject, authentication_string) VALUES('localhost','www','','','','')",
2625: "FLUSH PRIVILEGES");
1.50 raeburn 2626: if ($is_mariadb) {
1.52 raeburn 2627: push(@mysql_commands,"ALTER USER 'www'\@'localhost' IDENTIFIED BY 'localhostkey'");
1.50 raeburn 2628: } else {
1.52 raeburn 2629: push(@mysql_commands,"ALTER USER 'www'\@'localhost' IDENTIFIED WITH mysql_native_password BY 'localhostkey'");
1.50 raeburn 2630: }
1.42 raeburn 2631: } elsif ($hasauthcol) {
2632: @mysql_commands = ("INSERT user (Host, User, Password, ssl_cipher, x509_issuer, x509_subject, authentication_string) VALUES('localhost','www',password('localhostkey'),'','','','');");
1.36 raeburn 2633: } else {
1.42 raeburn 2634: @mysql_commands = ("INSERT user (Host, User, Password, ssl_cipher, x509_issuer, x509_subject) VALUES('localhost','www',password('localhostkey'),'','','');");
1.36 raeburn 2635: }
1.1 raeburn 2636: if ($mysqlversion < 4) {
1.4 raeburn 2637: push (@mysql_commands,"
2638: 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')");
2639: } else {
2640: push (@mysql_commands,"
2641: 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 2642: }
1.4 raeburn 2643: push(@mysql_commands,"DELETE FROM user WHERE host<>'localhost'");
1.68 raeburn 2644: if (($has_pass) || ($mysql_unix_socket)) {
1.1 raeburn 2645: if ($dbh) {
1.4 raeburn 2646: push(@mysql_commands,"FLUSH PRIVILEGES");
2647: if (@mysql_commands) {
2648: foreach my $cmd (@mysql_commands) {
2649: $dbh->do($cmd) || print $dbh->errstr."\n";
2650: }
2651: }
2652: if (@mysql_lc_commands) {
2653: foreach my $lccmd (@mysql_lc_commands) {
2654: $dbh->do($lccmd) || print $dbh->errstr."\n";
2655: }
2656: }
1.1 raeburn 2657: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1]',"'www'")."\n");
2658: } else {
2659: print_and_log(&mt('Problem accessing MySQL.')."\n".
2660: &mt('Permissions not set.')."\n");
2661: }
2662: } else {
2663: my ($firstpass,$secondpass,$got_passwd,$newmysqlpass);
2664: print &mt('Please enter a root password for the mysql database.')."\n".
2665: &mt('It does not have to match your root account password, but you will need to remember it.')."\n";
2666: my $maxtries = 10;
2667: my $trial = 0;
2668: while ((!$got_passwd) && ($trial < $maxtries)) {
2669: $firstpass = &get_mysql_password(&mt('Enter password'));
2670: if (length($firstpass) > 5) {
2671: $secondpass = &get_mysql_password(&mt('Enter password a second time'));
2672: if ($firstpass eq $secondpass) {
2673: $got_passwd = 1;
2674: $newmysqlpass = $firstpass;
2675: } else {
2676: print(&mt('Passwords did not match. Please try again.')."\n");
2677: }
2678: $trial ++;
2679: } else {
2680: print(&mt('Password too short.')."\n".
2681: &mt('Please choose a password with at least six characters.')."\n");
2682: }
2683: }
2684: if ($got_passwd) {
1.50 raeburn 2685: my (@newpass_cmds) = &new_mysql_rootpasswd($newmysqlpass,$usesauth,$is_mariadb);
1.4 raeburn 2686: push(@mysql_commands,@newpass_cmds);
1.1 raeburn 2687: } else {
2688: print_and_log(&mt('Failed to get MySQL root password from user input.')."\n");
2689: }
2690: if ($dbh) {
1.4 raeburn 2691: if (@mysql_commands) {
2692: foreach my $cmd (@mysql_commands) {
2693: $dbh->do($cmd) || print $dbh->errstr."\n";
2694: }
2695: }
2696: if (@mysql_lc_commands) {
2697: foreach my $lccmd (@mysql_lc_commands) {
2698: $dbh->do($lccmd) || print $dbh->errstr."\n";
2699: }
2700: }
1.1 raeburn 2701: if ($got_passwd) {
2702: print_and_log(&mt('MySQL root password stored.')."\n".
2703: &mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
2704: } else {
2705: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
2706: }
2707: } else {
2708: print_and_log(&mt('Problem accessing MySQL.')."\n".
2709: &mt('Permissions not set.')."\n");
2710: }
2711: }
2712: }
2713:
2714: sub new_mysql_rootpasswd {
1.50 raeburn 2715: my ($currmysqlpass,$usesauth,$is_mariadb) = @_;
1.36 raeburn 2716: if ($usesauth) {
1.50 raeburn 2717: if ($is_mariadb) {
1.51 raeburn 2718: return ("ALTER USER 'root'\@'localhost' IDENTIFIED BY '$currmysqlpass'",
1.50 raeburn 2719: "FLUSH PRIVILEGES;");
2720: } else {
1.51 raeburn 2721: return ("ALTER USER 'root'\@'localhost' IDENTIFIED WITH mysql_native_password BY '$currmysqlpass'",
1.50 raeburn 2722: "FLUSH PRIVILEGES;");
2723: }
1.36 raeburn 2724: } else {
2725: return ("SET PASSWORD FOR 'root'\@'localhost'=PASSWORD('$currmysqlpass')",
2726: "FLUSH PRIVILEGES;");
2727: }
1.1 raeburn 2728: }
2729:
2730: sub get_mysql_version {
1.38 raeburn 2731: my ($version,$subversion,$name);
1.1 raeburn 2732: if (open(PIPE," mysql -V |")) {
2733: my $info = <PIPE>;
2734: chomp($info);
2735: close(PIPE);
1.65 raeburn 2736: ($version,$subversion,$name) = ($info =~ /(\d+\.\d+)\.(\d+)(?:\-?(\w*),|)/);
1.1 raeburn 2737: } else {
2738: print &mt('Could not determine which version of MySQL is installed.').
2739: "\n";
2740: }
1.38 raeburn 2741: return ($version,$subversion,$name);
1.1 raeburn 2742: }
2743:
2744: ###########################################################
2745: ##
2746: ## RHEL/CentOS/Fedora/Scientific Linux
2747: ## Copy LON-CAPA httpd.conf to /etc/httpd/conf
2748: ##
2749: ###########################################################
2750:
2751: sub copy_httpd_conf {
1.46 raeburn 2752: my ($instdir,$distro,$hostname) = @_;
1.14 raeburn 2753: my $configfile = 'httpd.conf';
1.79 ! raeburn 2754: if ($distro =~ /^(?:centos|rhes|scientific|oracle|rocky|alma)(\d+)$/) {
1.29 raeburn 2755: if ($1 >= 7) {
2756: $configfile = 'apache2.4/httpd.conf';
2757: } elsif ($1 > 5) {
1.14 raeburn 2758: $configfile = 'new/httpd.conf';
2759: }
2760: } elsif ($distro =~ /^fedora(\d+)$/) {
1.29 raeburn 2761: if ($1 > 17) {
2762: $configfile = 'apache2.4/httpd.conf';
2763: } elsif ($1 > 10) {
1.14 raeburn 2764: $configfile = 'new/httpd.conf';
2765: }
2766: }
1.1 raeburn 2767: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'httpd.conf'",
2768: "'/etc/httpd/conf/httpd.conf'")."\n");
2769: copy "/etc/httpd/conf/httpd.conf","/etc/httpd/conf/httpd.conf.original";
1.14 raeburn 2770: copy "$instdir/centos-rhes-fedora-sl/$configfile","/etc/httpd/conf/httpd.conf";
1.5 raeburn 2771: chmod(0444,"/etc/httpd/conf/httpd.conf");
1.1 raeburn 2772: print_and_log("\n");
2773: }
2774:
1.59 raeburn 2775: ###########################################################
2776: ##
2777: ## RHEL/CentOS/Fedora/Scientific Linux
2778: ## Copy LON-CAPA mpm.conf to /etc/httpd/conf.modules.d/00-mpm.conf
2779: ##
2780: ## The LON-CAPA mpm.conf enables the prefork MPM module in
2781: ## Apache. This is also the default for RHEL/CentOS/Oracle
1.60 raeburn 2782: ## Linux 7 and earlier, and Fedora 26 and earlier. For more
1.59 raeburn 2783: ## recent versions of those distros, the event MPM is enabled
2784: ## by default. After ©_mpm_conf() is run, the prefork MPM
2785: ## module will be enabled instead of the event MPM module.
2786: ##
2787: ###########################################################
2788:
2789: sub copy_mpm_conf {
2790: my ($instdir,$distro) = @_;
2791: my $mpmfile = 'mpm.conf';
2792: if ((-e "/etc/httpd/conf.modules.d/00-mpm.conf") &&
2793: (-e "$instdir/centos-rhes-fedora-sl/$mpmfile")) {
2794: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'mpm.conf'",
2795: "'/etc/httpd/conf.modules.d/00-mpm.conf'")."\n");
2796: copy "$instdir/centos-rhes-fedora-sl/$mpmfile","/etc/httpd/conf.modules.d/00-mpm.conf";
2797: chmod(0644,"/etc/httpd/conf.modules.d/00-mpm.conf");
2798: print_and_log("\n");
2799: } else {
2800: my $logfail;
1.79 ! raeburn 2801: if ($distro =~ /^(?:centos|rhes|scientific|oracle|rocky|alma)(\d+)$/) {
1.59 raeburn 2802: if ($1 > 7) {
2803: $logfail = 1;
2804: }
2805: } elsif ($distro =~ /^fedora(\d+)$/) {
2806: if ($1 > 26) {
2807: $logfail = 1;
2808: }
2809: }
2810: if ($logfail) {
2811: print_and_log(&mt('Warning: copying the LON-CAPA [_1] failed because [_2] and/or [_3] are missing.',
2812: $mpmfile,"'$instdir/centos-rhes-fedora-sl/$mpmfile'",
2813: "'/etc/httpd/conf.modules.d/00-mpm.conf'"));
2814: print_and_log("\n");
2815: }
2816: }
2817: }
2818:
1.46 raeburn 2819: ###############################################
2820: ##
1.47 raeburn 2821: ## Copy loncapassl.conf and sslrewrite.conf
1.46 raeburn 2822: ##
2823: ###############################################
2824:
1.47 raeburn 2825: #
2826: # The Apache SSL configuration used by LON-CAPA is contained in
2827: # two files: sslrewrite.conf and loncapassl.conf.
2828: #
2829: # Starting with LON-CAPA 2.12, name-based virtual hosts are used
2830: # with port 443. The default virtual host (i.e., the one listed
2831: # first) is for the server's standard hostname, and that is the one
2832: # which will respond to client browser requests for https:// pages.
2833: #
2834: # Accordingly, a system administrator will need to edit the config
2835: # config file to include paths to a signed SSL certificate (public),
2836: # chain (public) and key (private) pem files. The certificate should
2837: # have been signed by a recognized certificate authority ((e.g.,
2838: # InCommon or Let's Encrypt).
2839: #
2840: # The sslrewrite.conf file contains the rewrite configuration for
2841: # the default virtual host. The rewrite rules defined are used to
2842: # allow internal HEAD requests to /cgi-bin/mimetex.cgi to be served
2843: # http://, in order to support vertical alignment of mimetex images
2844: # (one of the options for rendering Math content); (b) allow requests
2845: # for certain URLs (external resource, and syllabus, if external URL
2846: # used) to be served http:// to accommodate the use of iframes which
2847: # would otherwise result in browser blocking of mixed active content.
2848: #
2849: # The loncapassl.conf file contains the configuration for the
2850: # "internal" virtual host, which will respond to requests for https://
2851: # pages from other LON-CAPA servers in the network to which the node
2852: # belongs. The ServerName is internal-<hostname> where <hostname>
2853: # is the server's hostname. There is no need to create a DNS entry
2854: # for internal-<hostname>, as LON-CAPA 2.12 automatically performs
2855: # the required hostname to IP mapping.
2856: #
2857: # Requests to /raw on the "internal" virtual host require a valid
2858: # SSL client certificate, signed by the certificate authority
2859: # for the LON-CAPA network to which the node belongs.
2860: #
2861: # The configuration file to which the contents of sslrewrite.conf
2862: # and loncapassl.conf will be written will have either been identified
2863: # when &chkapachessl() was run, or if no files were found with
2864: # existing rewrite blocks, then a candidate file will be chosen
2865: # from the .conf files containing VirtualHosts definitions.
2866: # If there is more than one suitable candidate file, the system
2867: # administrator will be prompted to select from the available files.
2868: #
2869: # If there are no files containing VirtualHosts definitions, then
2870: # <VirtualHost *:443> </VirtualHost> blocks will be appended to
2871: # the standard Apache SSL config for the particular distro:
2872: # ssl.conf for RHEL/CentOS/Scientific/Fedora, vhost-ssl.conf
2873: # for SuSE/SLES, and default-ssl.conf for Ubuntu.
2874: #
2875: # Once a file is selected, the contents of sslrewrite.conf and
2876: # loncapassl.conf are compared with appropriate blocks in the file
2877: # and the user will be prompted to agree to insertion of missing lines
2878: # and/or deletion of surplus lines.
2879: #
2880:
2881: sub copy_apache_sslconf_files {
2882: my ($distro,$hostname,$hostip,$instdir,$targetdir,$targetfilesref,
2883: $has_std,$has_int,$rewritenum,$nochgstd,$nochgint) = @_;
2884: my ($new_std,$new_int);
2885: my (@internal,@standard,%int_by_linenum,%int_by_linetext,
2886: %rule_by_linenum,%rule_by_linetext,%foundint);
1.46 raeburn 2887: if (-e "$instdir/loncapassl.conf") {
2888: if (open(my $fh,'<',"$instdir/loncapassl.conf")) {
1.47 raeburn 2889: my $num = 1;
2890: while (<$fh>) {
2891: chomp();
2892: if (/^ServerName/) {
2893: s/(\Qinternal-{[[[[Hostname]]]]}\E)/internal-$hostname/;
2894: }
2895: push(@internal,$_);
2896: $int_by_linenum{$num} = $_;
2897: s/(^\s+|\s+$)//g;
2898: push(@{$int_by_linetext{$_}},$num);
2899: $num ++;
2900: }
2901: close($fh);
2902: }
2903: }
2904: if (-e "$instdir/sslrewrite.conf") {
2905: if (open(my $fh,'<',"$instdir/sslrewrite.conf")) {
2906: my $num = 1;
2907: while (<$fh>) {
2908: chomp();
2909: if (/\Q{[[[[HostIP]]]]}\E/) {
2910: s/(\QRewriteCond %{REMOTE_ADDR} {[[[[HostIP]]]]}\E)/RewriteCond %{REMOTE_ADDR} $hostip/;
2911: }
2912: push(@standard,$_);
2913: $rule_by_linenum{$num} = $_;
2914: s/(^\s+|\s+$)//g;
2915: push(@{$rule_by_linetext{$_}},$num);
2916: $num ++;
2917: }
2918: close($fh);
2919: }
2920: }
2921: if (!$nochgstd) {
2922: if ($has_std eq '') {
2923: my $file;
2924: if ($has_int ne '') {
2925: if (open(my $fh,'<',"$targetdir/$has_int")) {
2926: my @saved = <$fh>;
2927: close($fh);
2928: if (open(my $fhout, '>',"$targetdir/$has_int")) {
2929: print $fhout "<VirtualHost *:443>\n".
2930: "ServerName $hostname\n".
2931: join("\n",@standard)."\n".
2932: "</VirtualHost>\n\n".
2933: join('',@saved);
2934: close($fhout);
2935: $new_int = $has_int;
2936: }
2937: }
2938: }
2939: } else {
2940: if ($rewritenum eq '') {
2941: &append_to_vhost($targetdir,$has_std,$hostname,\%rule_by_linenum,'std');
2942: $new_std = $has_std;
2943: } else {
2944: $new_std = &modify_ssl_config($targetdir,$has_std,$hostname,$rewritenum,
2945: \%rule_by_linetext,\%rule_by_linenum,'std');
2946: }
2947: }
2948: }
2949: if (!$nochgint) {
2950: if ($has_int eq '') {
2951: if ($has_std ne '') {
2952: if (open(my $fhout,'>>',"$targetdir/$has_std")) {
2953: print $fhout "\n".join("\n",@internal)."\n";
2954: close($fhout);
2955: $new_int = $has_std;
2956: }
2957: }
2958: } else {
2959: $new_int = &modify_ssl_config($targetdir,$has_int,$hostname,$rewritenum,\%int_by_linetext,\%int_by_linenum,'int');
2960: }
2961: }
2962: if (($has_std eq '') && ($has_int eq '')) {
2963: my ($file,$numfiles) = &get_sslconf_filename($distro,$targetdir,$targetfilesref);
2964: if ($numfiles == 0) {
2965: if (open(my $fhout, '>>', "$targetdir/$file")) {
2966: print $fhout "<VirtualHost *:443>\n".
2967: "ServerName $hostname\n".
2968: join("\n",@standard)."\n".
2969: "</VirtualHost>\n\n".
2970: join("\n",@internal)."\n";
2971: close($fhout);
2972: $new_std = $file;
2973: $new_int = $file;
2974: }
2975: } elsif ($numfiles == 1) {
2976: &append_to_vhost($targetdir,$file,$hostname,\%rule_by_linenum,'std');
2977: if (open(my $fhout, '>>', "$targetdir/$file")) {
2978: print $fhout "\n".join("\n",@internal)."\n";
2979: close($fhout);
2980: $new_std = $file;
2981: $new_int = $file;
2982: }
2983: } elsif ($numfiles == -1) {
2984: print_and_log(&mt('Failed to copy contents of [_1] or [_2] to a file in [_3]',
2985: "'loncapassl.conf'","'sslrewrite.conf'","'$targetdir'")."\n");
2986: }
2987: }
2988: if ($nochgstd) {
2989: print_and_log(&mt('No change required to file: [_1] in [_2], (no difference between [_3] and rewrite block.)',
2990: "'$has_std'","'$targetdir'","'sslrewrite.conf'"));
2991: }
2992: if ($nochgint) {
2993: print_and_log(&mt('No change required to file: [_1] in [_2], (no difference between [_3] and virtualhost block.)',
2994: "'$has_int'","'$targetdir'","'loncapassl.conf'"));
2995: }
2996: if ($new_int) {
2997: print_and_log(&mt('Successfully copied contents of [_1] to [_2].',"'loncapassl.conf'","'$targetdir/$new_int'")."\n");
2998: chmod(0444,"$targetdir/loncapassl.conf");
2999: }
3000: if ($new_std) {
3001: print_and_log(&mt('Successfully copied contents of [_1] to [_2].',"'sslrewrite.conf'","'$targetdir/$new_std'")."\n");
3002: chmod(0444,"$targetdir/loncapassl.conf");
3003: }
3004: return ($new_int,$new_std);
3005: }
3006:
3007: #
3008: # append_to_vhost() is called to add rewrite rules (in a
3009: # <IfModule +mod_rewrite.c> </IfModule> block), provided
3010: # in the sslrewrite.conf configuration file, to an Apache
3011: # SSL configuration file within a VirtualHost for port 443
3012: # (for server's public-facing hostname).
3013: #
3014: sub append_to_vhost {
3015: my ($targetdir,$filename,$hostname,$by_linenum,$type) = @_;
3016: return unless (ref($by_linenum) eq 'HASH');
3017: my ($startvhost,$endvhost);
3018: if (-e "$targetdir/$filename") {
3019: my (@lines,$currname,$virtualhost,$hasname);
3020: if (open(my $fh,'<',"$targetdir/$filename")) {
3021: my $currline = 0;
3022: while (<$fh>) {
3023: $currline ++;
3024: push(@lines,$_);
3025: chomp();
3026: s/(^\s+|\s+$)//g;
3027: if (/^<VirtualHost\s+[^:]*\:443>/) {
3028: $virtualhost = 1;
3029: unless ($endvhost) {
3030: $startvhost = $currline;
1.46 raeburn 3031: }
3032: }
1.47 raeburn 3033: if ($virtualhost) {
3034: if (/^ServerName\s+([^\s]+)\s*$/) {
3035: $currname = $1;
3036: unless ($endvhost) {
3037: if ((($currname eq '') || ($currname eq $hostname)) && ($type eq 'std')) {
3038: $hasname = 1;
3039: }
3040: }
3041: }
3042: if (/^<\/VirtualHost>/) {
3043: $virtualhost = 0;
3044: unless ($endvhost) {
3045: if (((($currname eq '') || ($currname eq $hostname)) && ($type eq 'std')) ||
3046: (($currname eq 'internal-'.$hostname) && ($type eq 'int'))) {
3047: $endvhost = $currline;
3048: } else {
3049: undef($startvhost);
3050: }
3051: }
3052: }
3053: }
3054: }
3055: close($fh);
3056: }
3057: if ($endvhost) {
3058: if (open(my $fout,'>',"$targetdir/$filename")) {
3059: for (my $i=0; $i<@lines; $i++) {
3060: if ($i == $startvhost) {
3061: unless (($hasname) && ($type eq 'std')) {
3062: print $fout "ServerName $hostname\n";
3063: }
3064: }
3065: if ($i == $endvhost-1) {
3066: foreach my $item (sort { $a <=> $b } keys(%{$by_linenum})) {
3067: print $fout $by_linenum->{$item}."\n";
3068: }
3069: }
3070: print $fout $lines[$i];
3071: }
3072: close($fout);
3073: }
3074: }
3075: }
3076: return $endvhost;
3077: }
3078:
3079: #
3080: # get_sslconf_filename() is called when the Apache SSL configuration
3081: # option has been selected and there are no files containing
3082: # VirtualHost definitions containing rewrite blocks,
3083: #
3084: # In this case get_sslconf_filename() is used to chose from the
3085: # available .conf files containing VirtualHosts definitions. If
3086: # there is ambiguity about which file to use, &apacheconf_choice()
3087: # will be called to prompt the user to choose one of the possible
3088: # files.
3089: #
3090:
3091: sub get_sslconf_filename {
3092: my ($distro,$targetdir,$targetfilesref) = @_;
3093: my ($configfile,$numfiles,@possfiles);
3094: if (ref($targetfilesref) eq 'HASH') {
3095: if (keys(%{$targetfilesref}) > 0) {
3096: foreach my $name (sort(keys(%{$targetfilesref}))) {
3097: if (ref($targetfilesref->{$name}) eq 'HASH') {
3098: foreach my $file (sort(keys(%{$targetfilesref->{$name}}))) {
3099: next if ($file eq '');
3100: next if (!-e "$targetdir/$file");
3101: unless (grep(/^\Q$file\E$/,@possfiles)) {
3102: push(@possfiles,$file);
3103: }
3104: }
3105: }
3106: }
3107: }
3108: if (@possfiles == 0) {
3109: $configfile = 'ssl.conf';
3110: if ($distro =~ /^(suse|sles)/) {
3111: $configfile = 'vhost-ssl.conf';
3112: } elsif ($distro =~ /^(debian|ubuntu)/) {
3113: $configfile = 'default-ssl.conf';
3114: }
3115: $numfiles = 0;
3116: print &mt('No configuration files in [_1] contain a <VirtualHost *:443> </VirtualHost> block which can be used to house Apache rewrite rules from https to http.',$targetdir)."\n\n".
3117: &mt('Accordingly, the contents of sslrewrite.conf will be included in a <VirtualHost *:443> </VirtualHost> block which will be added to a file named: [_1].',$configfile)."\n\n";
3118: } elsif (@possfiles == 1) {
3119: $configfile = $possfiles[0];
3120: $numfiles = 1;
3121: print &mt('A single configuration file in [_1] contains a <VirtualHost *:443> </VirtualHost> block.',$targetdir)."\n".
3122: &mt('The contents of sslrewrite.conf will be added to this block.')."\n\n";
3123: } else {
3124: print &mt('More than one Apache config file contains a <VirtualHost *:443> </VirtualHost> block.')."\n\n".&mt('The possible files are:')."\n";
3125: my $counter = 1;
3126: my $max = scalar(@possfiles);
3127: foreach my $file (@possfiles) {
3128: print "$counter. $file\n";
3129: $counter ++;
3130: }
3131: print "\n".&mt('Enter a number between 1 and [_1] to indicate which file should be modified to include the contents of sslrewrite.conf.',$max)."\n";
3132: my $choice = &apacheconf_choice($max);
3133: if (($choice =~ /^\d+$/) && ($choice >= 1) && ($choice <= $max)) {
3134: $configfile = $possfiles[$choice-1];
3135: $numfiles = 1;
1.46 raeburn 3136: } else {
1.47 raeburn 3137: $numfiles = -1;
1.46 raeburn 3138: }
3139: }
3140: }
1.47 raeburn 3141: return ($configfile,$numfiles);
3142: }
3143:
3144: #
3145: # &apacheconf_choice() prompts a user to choose an integer between 1 and the
3146: # maximum number of available of possible Apache SSL config files found
3147: # at the distros standard location for Apache config files containing
3148: # VirtualHost definitions.
3149: #
3150: # This routine is called recursively until the user enters a valid integer.
3151: #
3152:
3153: sub apacheconf_choice {
3154: my ($max) = @_;
3155: my $choice = <STDIN>;
3156: chomp($choice);
3157: $choice =~ s/(^\s+|\s+$)//g;
3158: my $configfile;
3159: if (($choice =~ /^\d+$/) && ($choice >= 1) && ($choice <= $max)) {
3160: $configfile = $choice;
3161: }
3162: while ($configfile eq '') {
3163: print &mt('Invalid choice. Please enter a number between 1 and [_1].',$max)."\n";
3164: $configfile = &apacheconf_choice($max);
3165: }
3166: print "\n";
3167: return $configfile;
3168: }
3169:
3170: #
3171: # &modify_ssl_config() is called to modify the contents of an Apache SSL config
3172: # file so that it has two <VirtualHost *:443> </VirtualHost> blocks containing
3173: # (a) the default VirtualHost with the <IfModule mod_rewrite.c> </IfModule> block
3174: # provided in sslrewrites.conf, and (b) an "internal" VirtualHost with the
3175: # content provided in loncapassl.conf.
3176: #
3177: # This routine will prompted you to agree to insertion of lines present in the
3178: # shipped conf file, but missing from the local config file, and also for
3179: # deletion of lines present in the local config file, but not required in
3180: # the shipped conf file.
3181: #
3182:
3183: sub modify_ssl_config {
3184: my ($targetdir,$filename,$hostname,$rewritenum,$by_linetext,$by_linenum,$type) = @_;
3185: return unless ((ref($by_linetext) eq 'HASH') && (ref($by_linenum) eq 'HASH'));
3186: if (-e "$targetdir/$filename") {
3187: my (@lines,$virtualhost,$currname,$rewrite);
3188: if (open(my $fh,'<',"$targetdir/$filename")) {
3189: my %found;
3190: my %possible;
3191: my $currline = 0;
3192: my $rewritecount = 0;
3193: while (<$fh>) {
3194: $currline ++;
3195: push(@lines,$_);
3196: chomp();
3197: s/(^\s+|\s+$)//g;
3198: if (/^\s*<VirtualHost\s+[^:]*\:443>\s*$/) {
3199: $virtualhost = 1;
3200: }
3201: if ($virtualhost) {
3202: if ((exists($by_linetext->{$_})) && (ref($by_linetext->{$_}) eq 'ARRAY') &&
3203: (@{$by_linetext->{$_}} > 0)) {
3204: $possible{$currline} = shift(@{$by_linetext->{$_}});
3205: }
3206: if (/^\s*<\/VirtualHost>/) {
3207: if ((($currname eq 'internal-'.$hostname) && ($type eq 'int')) ||
3208: ((($currname eq $hostname) || ($currname eq '')) && ($type eq 'std') &&
3209: ($rewritecount == $rewritenum))) {
3210: %found = (%found,%possible);
3211: } else {
3212: foreach my $line (sort {$b <=> $a } keys(%possible)) {
3213: my $num = $possible{$line};
3214: if (ref($by_linetext->{$by_linenum->{$num}}) eq 'ARRAY') {
3215: unshift(@{$by_linetext->{$by_linenum->{$num}}},$num);
3216: }
3217: }
3218: }
3219: undef(%possible);
3220: $virtualhost = 0;
3221: $currname = '';
3222: } elsif (/^\s*ServerName\s+([^\s]+)\s*$/) {
3223: $currname = $1;
3224: } elsif (/^\s*<IfModule\s+mod_rewrite\.c>/) {
3225: $rewrite = 1;
3226: } elsif (/^\s*<\/IfModule>/) {
3227: $rewritecount ++;
3228: $rewrite = 0;
3229: }
3230: }
3231: }
3232: close($fh);
3233: if (open(my $fout,'>',"$targetdir/$filename")) {
3234: my $currline = 0;
3235: my ($lastfound,$done);
3236: my $numfound = 0;
3237: foreach my $line (@lines) {
3238: $currline ++;
3239: if ($done) {
3240: print $fout $line;
3241: } elsif ($lastfound) {
3242: if ($found{$currline}) {
3243: for (my $i=$lastfound+1; $i<$found{$currline}; $i++) {
3244: print &mt('The following line is missing from the current <VirtualHost *:443> </VirtualHost> block:')."\n".
3245: $by_linenum->{$i}."\n".
3246: &mt('Add this line? ~[Y/n~]');
3247: if (&get_user_selection(1)) {
3248: print $fout $by_linenum->{$i}."\n";
3249: }
3250: }
3251: $numfound ++;
3252: $lastfound = $found{$currline};
3253: print $fout $line;
3254: if ($numfound == scalar(keys(%found))) {
3255: $done = 1;
3256: for (my $i=$found{$currline}+1; $i<=scalar(keys(%{$by_linenum})); $i++) {
3257: print &mt('The following line is missing from the current <VirtualHost *:443> </VirtualHost> block:')."\n".
3258: $by_linenum->{$i}."\n".
3259: &mt('Add this line? ~[Y/n~]');
3260: if (&get_user_selection(1)) {
3261: print $fout $by_linenum->{$i}."\n";
3262: }
3263: }
3264: }
3265: } else {
3266: print &mt('The following line found within a <VirtualHost *:443> </VirtualHost> block does not match that expected by LON-CAPA:')."\n".
3267: $line.
3268: &mt('Delete this line? ~[Y/n~]');
3269: if (!&get_user_selection(1)) {
3270: print $fout $line;
3271: }
3272: }
3273: } elsif ($found{$currline}) {
3274: $numfound ++;
3275: $lastfound = $found{$currline};
3276: for (my $i=1; $i<$found{$currline}; $i++) {
3277: print &mt('The following line is missing from the current <VirtualHost *:443> </VirtualHost> block:')."\n".
3278: $by_linenum->{$i}."\n".
3279: &mt('Add this line? ~[Y/n~]');
3280: if (&get_user_selection(1)) {
3281: print $fout $by_linenum->{$i}."\n";
3282: }
3283: }
3284: print $fout $line;
3285: } else {
3286: print $fout $line;
3287: }
3288: }
3289: close($fout);
3290: }
1.46 raeburn 3291: }
3292: }
1.47 raeburn 3293: return $filename;
1.46 raeburn 3294: }
3295:
1.1 raeburn 3296: #########################################################
3297: ##
1.17 raeburn 3298: ## Ubuntu/Debian -- copy our loncapa configuration file to
1.1 raeburn 3299: ## sites-available and set the symlink from sites-enabled.
3300: ##
3301: #########################################################
3302:
3303: sub copy_apache2_debconf {
1.46 raeburn 3304: my ($instdir,$distro,$hostname) = @_;
1.6 raeburn 3305: my $apache2_mods_enabled_dir = '/etc/apache2/mods-enabled';
3306: my $apache2_mods_available_dir = '/etc/apache2/mods-available';
3307: foreach my $module ('headers.load','expires.load') {
3308: unless (-l "$apache2_mods_enabled_dir/$module") {
3309: symlink("$apache2_mods_available_dir/$module","$apache2_mods_enabled_dir/$module");
3310: print_and_log(&mt('Enabling "[_1]" Apache module.',$module)."\n");
3311: }
3312: }
1.28 raeburn 3313: my $apache2_sites_enabled_dir = '/etc/apache2/sites-enabled';
3314: my $apache2_sites_available_dir = '/etc/apache2/sites-available';
3315: my $defaultconfig = "$apache2_sites_enabled_dir/000-default";
1.69 raeburn 3316: my $defaultsite = "$apache2_sites_enabled_dir/loncapa.conf";
1.28 raeburn 3317: my ($distname,$version);
3318: if ($distro =~ /^(debian|ubuntu)(\d+)$/) {
3319: $distname = $1;
3320: $version = $2;
3321: }
3322: if (($distname eq 'ubuntu') && ($version > 12)) {
3323: $defaultconfig = "$apache2_sites_enabled_dir/000-default.conf";
3324: }
1.64 raeburn 3325: my ($skipconf,$skipsite,$skipstatus);
1.28 raeburn 3326: if (($distname eq 'ubuntu') && ($version > 12)) {
3327: my $apache2_conf_enabled_dir = '/etc/apache2/conf-enabled';
3328: my $apache2_conf_available_dir = '/etc/apache2/conf-available';
1.64 raeburn 3329: my $defaultconf = $apache2_conf_enabled_dir.'/loncapa.conf';
3330: if ((-e "$apache2_conf_available_dir/loncapa") && (-e "$instdir/debian-ubuntu/ubuntu14/loncapa_conf")) {
1.67 raeburn 3331: if (open(PIPE, "diff --brief $apache2_conf_available_dir/loncapa $instdir/debian-ubuntu/ubuntu14/loncapa_conf |")) {
1.64 raeburn 3332: my $diffres = <PIPE>;
3333: close(PIPE);
3334: chomp($diffres);
3335: if ($diffres) {
1.69 raeburn 3336: copy("$apache2_conf_available_dir/loncapa","$apache2_conf_available_dir/loncapa.conf.original");
3337: } else {
3338: copy("$apache2_conf_available_dir/loncapa","$apache2_conf_available_dir/loncapa.conf");
1.70 raeburn 3339: chdir($apache2_conf_enabled_dir);
3340: symlink('../conf-available/loncapa.conf','loncapa.conf');
3341: chdir($instdir);
1.64 raeburn 3342: }
3343: if (-l $defaultconf) {
3344: my $linkfname = readlink($defaultconf);
1.70 raeburn 3345: if ($linkfname ne '') {
3346: $linkfname = Cwd::abs_path(File::Spec->rel2abs($linkfname,$apache2_conf_enabled_dir));
3347: }
1.64 raeburn 3348: if ($linkfname eq "$apache2_conf_available_dir/loncapa") {
1.69 raeburn 3349: unlink($defaultconf);
3350: }
3351: }
3352: unlink("$apache2_conf_available_dir/loncapa");
3353: }
3354: }
3355: if ((-e "$apache2_conf_available_dir/loncapa.conf") && (-e "$instdir/debian-ubuntu/ubuntu14/loncapa_conf")) {
3356: if (open(PIPE, "diff --brief $apache2_conf_available_dir/loncapa.conf $instdir/debian-ubuntu/ubuntu14/loncapa_conf |")) {
3357: my $diffres = <PIPE>;
3358: close(PIPE);
3359: chomp($diffres);
3360: if ($diffres) {
3361: copy("$apache2_conf_available_dir/loncapa.conf","$apache2_conf_available_dir/loncapa.conf.original");
3362: }
3363: if (-l $defaultconf) {
3364: my $linkfname = readlink($defaultconf);
1.70 raeburn 3365: if ($linkfname ne '') {
3366: $linkfname = Cwd::abs_path(File::Spec->rel2abs($linkfname,$apache2_conf_enabled_dir));
3367: }
1.69 raeburn 3368: if ($linkfname eq "$apache2_conf_available_dir/loncapa.conf") {
1.64 raeburn 3369: unless ($diffres) {
3370: $skipconf = 1;
3371: }
3372: }
3373: }
3374: }
3375: }
3376: unless ($skipconf) {
3377: 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.69 raeburn 3378: copy("$instdir/debian-ubuntu/ubuntu14/loncapa_conf","$apache2_conf_available_dir/loncapa.conf");
3379: chmod(0444,"$apache2_conf_available_dir/loncapa.conf");
1.64 raeburn 3380: if (-l $defaultconf) {
3381: unlink($defaultconf);
3382: }
1.70 raeburn 3383: chdir($apache2_conf_enabled_dir);
3384: symlink('../conf-available/loncapa.conf','loncapa.conf');
3385: chdir($instdir);
1.64 raeburn 3386: }
3387: my $stdsite = "$instdir/debian-ubuntu/ubuntu14/loncapa_site";
3388: if ((-e $stdsite) && (-e "$apache2_sites_available_dir/loncapa")) {
3389: if (open(PIPE, "diff --brief $stdsite $apache2_sites_available_dir/loncapa |")) {
3390: my $diffres = <PIPE>;
3391: close(PIPE);
3392: chomp($diffres);
3393: if ($diffres) {
1.69 raeburn 3394: copy("$apache2_sites_available_dir/loncapa","$apache2_sites_available_dir/loncapa.conf.original");
3395: } else {
3396: copy("$apache2_sites_available_dir/loncapa","$apache2_sites_available_dir/loncapa.conf");
1.64 raeburn 3397: }
3398: if (-l $defaultconfig) {
3399: my $linkfname = readlink($defaultconfig);
1.70 raeburn 3400: if ($linkfname ne '') {
3401: $linkfname = Cwd::abs_path(File::Spec->rel2abs($linkfname,$apache2_sites_enabled_dir));
3402: }
1.64 raeburn 3403: if ($linkfname eq "$apache2_sites_available_dir/loncapa") {
1.69 raeburn 3404: unlink($defaultconfig);
3405: }
3406: }
3407: unlink("$apache2_sites_available_dir/loncapa");
3408: }
3409: }
3410: if ((-e $stdsite) && (-e "$apache2_sites_available_dir/loncapa.conf")) {
3411: if (open(PIPE, "diff --brief $stdsite $apache2_sites_available_dir/loncapa.conf |")) {
3412: my $diffres = <PIPE>;
3413: close(PIPE);
3414: chomp($diffres);
3415: if ($diffres) {
3416: copy("$apache2_sites_available_dir/loncapa.conf","$apache2_sites_available_dir/loncapa.conf.original");
3417: }
3418: if (-l $defaultsite) {
3419: my $linkfname = readlink($defaultsite);
1.70 raeburn 3420: if ($linkfname ne '') {
3421: $linkfname = Cwd::abs_path(File::Spec->rel2abs($linkfname,$apache2_sites_enabled_dir));
3422: }
3423: if ($linkfname eq "$apache2_sites_available_dir/loncapa.conf") {
1.64 raeburn 3424: unless ($diffres) {
3425: $skipsite = 1;
3426: }
1.65 raeburn 3427: }
1.64 raeburn 3428: }
3429: }
3430: }
3431: unless ($skipsite) {
1.69 raeburn 3432: print_and_log(&mt('Copying loncapa [_1] site file to [_2] and pointing [_3] to it from sites-enabled.',"'apache2'","'/etc/apache2/sites-available'","'loncapa.conf symlink'")."\n");
3433: copy("$instdir/debian-ubuntu/ubuntu14/loncapa_site","$apache2_sites_available_dir/loncapa.conf");
3434: chmod(0444,"$apache2_sites_available_dir/loncapa.conf");
1.70 raeburn 3435: chdir($apache2_sites_enabled_dir);
3436: symlink('../sites-available/loncapa.conf','loncapa.conf');
3437: chdir($instdir);
1.69 raeburn 3438: }
1.70 raeburn 3439: if (-l $defaultconfig) {
1.69 raeburn 3440: my $linkfname = readlink($defaultconfig);
1.70 raeburn 3441: if ($linkfname ne '') {
3442: $linkfname = Cwd::abs_path(File::Spec->rel2abs($linkfname,$apache2_sites_enabled_dir));
3443: }
3444: if ($linkfname eq "$apache2_sites_available_dir/000-default.conf") {
1.69 raeburn 3445: unlink($defaultconfig);
3446: }
1.64 raeburn 3447: }
3448: } else {
3449: if ((-e "$instdir/debian-ubuntu/loncapa") && (-e "$apache2_sites_available_dir/loncapa")) {
3450: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/loncapa $apache2_sites_available_dir/loncapa |")) {
3451: my $diffres = <PIPE>;
3452: close(PIPE);
3453: chomp($diffres);
3454: if ($diffres) {
3455: copy("$apache2_sites_available_dir/loncapa","$apache2_sites_available_dir/loncapa.original");
3456: }
3457: if (-l $defaultconfig) {
3458: my $linkfname = readlink($defaultconfig);
3459: if ($linkfname eq "$apache2_sites_available_dir/loncapa") {
3460: unless ($diffres) {
3461: $skipsite = 1;
3462: }
3463: }
3464: }
3465: }
3466: }
3467: unless ($skipsite) {
3468: if (-l $defaultconfig) {
3469: unlink($defaultconfig);
3470: }
3471: 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");
3472: if (-e "$instdir/debian-ubuntu/loncapa") {
3473: copy("$instdir/debian-ubuntu/loncapa","$apache2_sites_available_dir/loncapa");
3474: chmod(0444,"$apache2_sites_available_dir/loncapa");
3475: symlink("$apache2_sites_available_dir/loncapa","$apache2_sites_enabled_dir/000-default");
3476: }
3477: }
3478: }
3479: if ($distname eq 'ubuntu') {
3480: my $sitestatus = "$apache2_mods_available_dir/status.conf";
3481: my $stdstatus = "$instdir/debian-ubuntu/status.conf";
3482: if ((-e $sitestatus) && (-e $stdstatus)) {
3483: if (open(PIPE, "diff --brief $stdstatus $sitestatus |")) {
3484: my $diffres = <PIPE>;
3485: close(PIPE);
3486: chomp($diffres);
3487: if ($diffres) {
3488: copy("$apache2_mods_available_dir/status.conf","$apache2_mods_available_dir/status.conf.original");
3489: } else {
3490: $skipstatus = 1;
3491: }
3492: }
3493: }
3494: unless ($skipstatus) {
3495: if (-e $stdstatus) {
3496: print_and_log(&mt('Copying loncapa [_1] file to [_2],',"'status.conf'","'/etc/apache2/mods-available/status.conf'")."\n");
3497: copy($stdstatus,$sitestatus);
3498: chmod(0644,$sitestatus);
3499: }
1.28 raeburn 3500: }
3501: }
1.1 raeburn 3502: print_and_log("\n");
3503: }
3504:
3505: ###########################################################
3506: ##
3507: ## openSuSE/SLES Copy apache2 config files:
3508: ## default-server.conf, uid.conf, /etc/sysconfig/apache2
3509: ## and create symlink from /srv/www/conf to /etc/apache2
3510: ##
3511: ###########################################################
3512:
3513: sub copy_apache2_suseconf {
1.49 raeburn 3514: my ($instdir,$hostname,$distro) = @_;
3515: my ($name,$version) = ($distro =~ /^(suse|sles)([\d\.]+)$/);
3516: my $conf_file = "$instdir/sles-suse/default-server.conf";
3517: if (($name eq 'sles') && ($version >= 12)) {
3518: $conf_file = "$instdir/sles-suse/apache2.4/default-server.conf";
3519: }
1.1 raeburn 3520: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
3521: "'default-server.conf'",
3522: "'/etc/apache2/default-server.conf'")."\n");
3523: if (!-e "/etc/apache2/default-server.conf.original") {
3524: copy "/etc/apache2/default-server.conf","/etc/apache2/default-server.conf.original";
3525: }
1.49 raeburn 3526: copy $conf_file,"/etc/apache2/default-server.conf";
1.5 raeburn 3527: chmod(0444,"/etc/apache2/default-server.conf");
1.1 raeburn 3528: # Make symlink for conf directory (included in loncapa_apache.conf)
3529: my $can_symlink = (eval { symlink('/etc/apache2','/srv/www/conf'); }, $@ eq '');
3530: if ($can_symlink) {
3531: &print_and_log(&mt('Symlink created for [_1] to [_2].',
3532: "'/srv/www/conf'","'/etc/apache2'")."\n");
3533: } else {
3534: &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");
3535: }
3536: ©_apache2_conf_files($instdir);
1.49 raeburn 3537: ©_sysconfig_apache2_file($instdir,$name,$version);
1.1 raeburn 3538: print_and_log("\n");
3539: }
3540:
3541: ###############################################
3542: ##
3543: ## Modify uid.conf
3544: ##
3545: ###############################################
3546: sub copy_apache2_conf_files {
3547: my ($instdir) = @_;
3548: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
3549: "'uid.conf'","'/etc/apache2/uid.conf'")."\n");
3550: if (!-e "/etc/apache2/uid.conf.original") {
3551: copy "/etc/apache2/uid.conf","/etc/apache2/uid.conf.original";
3552: }
1.9 raeburn 3553: copy "$instdir/sles-suse/uid.conf","/etc/apache2/uid.conf";
1.5 raeburn 3554: chmod(0444,"/etc/apache2/uid.conf");
1.1 raeburn 3555: }
3556:
3557: ###############################################
3558: ##
3559: ## Modify /etc/sysconfig/apache2
3560: ##
3561: ###############################################
3562: sub copy_sysconfig_apache2_file {
1.49 raeburn 3563: my ($instdir,$name,$version) = @_;
1.1 raeburn 3564: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'sysconfig/apache2'","'/etc/sysconfig/apache2'")."\n");
3565: if (!-e "/etc/sysconfig/apache2.original") {
3566: copy "/etc/sysconfig/apache2","/etc/sysconfig/apache2.original";
3567: }
1.49 raeburn 3568: my $sysconf_file = "$instdir/sles-suse/sysconfig_apache2";
3569: if (($name eq 'sles') && ($version >= 12)) {
3570: $sysconf_file = "$instdir/sles-suse/apache2.4/sysconfig_apache2";
3571: }
1.57 raeburn 3572: copy $sysconf_file,"/etc/sysconfig/apache2";
1.5 raeburn 3573: chmod(0444,"/etc/sysconfig/apache2");
1.1 raeburn 3574: }
3575:
3576: ###############################################
3577: ##
3578: ## Add/Modify /etc/insserv/overrides
3579: ##
3580: ###############################################
3581:
3582: sub update_SuSEfirewall2_setup {
3583: my ($instdir) = @_;
3584: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'SuSEfirewall2_setup'","'/etc/insserv/overrides/SuSEfirewall2_setup'")."\n");
3585: if (!-e "/etc/insserv/overrides/SuSEfirewall2_setup") {
3586: if (!-d "/etc/insserv") {
3587: mkdir("/etc/insserv",0755);
3588: }
3589: if (!-d "/etc/insserv/overrides") {
3590: mkdir("/etc/insserv/overrides",0755);
3591: }
3592: } elsif (!-e "/etc/insserv/overrides/SuSEfirewall2_setup.original") {
3593: copy "/etc/insserv/overrides/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup.original"
3594: }
1.9 raeburn 3595: copy "$instdir/sles-suse/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup";
1.5 raeburn 3596: chmod(0444,"/etc/insserv/overrides/SuSEfirewall2_setup");
3597: }
3598:
3599: sub get_iptables_rules {
3600: my ($distro,$instdir,$apachefw) = @_;
3601: my (@fwchains,@ports);
3602: if (&firewall_is_active()) {
3603: my $iptables = &get_pathto_iptables();
3604: if ($iptables ne '') {
3605: @fwchains = &get_fw_chains($iptables,$distro);
3606: }
3607: }
3608: if (ref($apachefw) eq 'HASH') {
3609: foreach my $service ('http','https') {
3610: unless ($apachefw->{$service}) {
3611: push (@ports,$service);
3612: }
3613: }
3614: } else {
3615: @ports = ('http','https');
3616: }
3617: if (@ports == 0) {
3618: return;
3619: }
3620: my $ask_to_enable;
3621: if (-e "/etc/iptables.loncapa.rules") {
1.9 raeburn 3622: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables.loncapa.rules /etc/iptables.loncapa.rules |")) {
1.5 raeburn 3623: my $diffres = <PIPE>;
3624: close(PIPE);
3625: chomp($diffres);
3626: if ($diffres) {
3627: print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
3628: }
3629: } else {
3630: print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
3631: }
3632: } else {
1.9 raeburn 3633: if (-e "$instdir/debian-ubuntu/iptables.loncapa.rules") {
3634: copy "$instdir/debian-ubuntu/iptables.loncapa.rules","/etc/iptables.loncapa.rules";
1.5 raeburn 3635: chmod(0600,"/etc/iptables.loncapa.rules");
3636: }
3637: }
3638: if (-e "/etc/iptables.loncapa.rules") {
3639: if (-e "/etc/network/if-pre-up.d/iptables") {
1.9 raeburn 3640: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables /etc/network/if-pre-up/iptables |")) {
1.5 raeburn 3641: my $diffres = <PIPE>;
3642: close(PIPE);
3643: chomp($diffres);
3644: if ($diffres) {
3645: print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
3646: }
3647: } else {
3648: print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
3649: }
3650: } else {
1.9 raeburn 3651: copy "$instdir/debian-ubuntu/iptables","/etc/network/if-pre-up.d/iptables";
1.5 raeburn 3652: chmod(0755,"/etc/network/if-pre-up.d/iptables");
3653: 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'));
3654: $ask_to_enable = 1;
3655: }
3656: }
3657: return $ask_to_enable;
1.1 raeburn 3658: }
3659:
3660: sub download_loncapa {
3661: my ($instdir,$lctarball) = @_;
3662: my ($have_tarball,$updateshown);
3663: if (! -e "$instdir/$lctarball") {
3664: print_and_log(&mt('Retrieving LON-CAPA source files from: [_1]',
3665: 'http://install.loncapa.org')."\n");
3666: system("wget http://install.loncapa.org/versions/$lctarball ".
3667: "2>/dev/null 1>/dev/null");
3668: if (! -e "./$lctarball") {
3669: print &mt('Unable to retrieve LON-CAPA source files from: [_1].',
3670: "http://install.loncapa.org/versions/$lctarball")."\n";
3671: } else {
3672: $have_tarball = 1;
3673: }
3674: print_and_log("\n");
3675: } else {
3676: $have_tarball = 1;
3677: print_and_log("
3678: ------------------------------------------------------------------------
3679:
1.77 raeburn 3680: ".&mt('You seem to have a version of [_1] in [_2]',$lctarball,$instdir)."\n".
1.1 raeburn 3681: &mt('This copy will be used and a new version will NOT be downloaded.')."\n".
3682: &mt('If you wish, you may download a new version by executing:')."
3683:
1.77 raeburn 3684: wget http://install.loncapa.org/versions/$lctarball
1.1 raeburn 3685:
3686: ------------------------------------------------------------------------
3687: ");
3688: }
3689:
3690: ##
1.77 raeburn 3691: ## untar loncapa-X.Y.Z.tar.gz
1.1 raeburn 3692: ##
3693: if ($have_tarball) {
1.77 raeburn 3694: my $homedir = '/root';
3695: my ($targetdir,$chdircmd,$updatecmd);
3696: if (($distro =~ /^ubuntu/) && ($instdir ne $homedir)) {
3697: ($homedir) = ($instdir =~ m{^(.*)/[^/]+$});
3698: $updatecmd = 'sudo ./UPDATE';
3699: } else {
3700: $updatecmd = './UPDATE';
3701: }
1.1 raeburn 3702: print_and_log(&mt('Extracting LON-CAPA source files')."\n");
1.77 raeburn 3703: if (-e $homedir) {
3704: writelog(`tar zxf $instdir/$lctarball --directory $homedir`);
3705: $targetdir = $homedir;
3706: } else {
3707: writelog(`tar zxf $instdir/$lctarball`);
3708: $targetdir = $instdir;
3709: }
3710: if ($lctarball =~ /^loncapa\-(\d+\.\d+\.\d+(?:|[^.]+))\.tar\.gz$/) {
3711: $chdircmd = "cd $targetdir/loncapa-".$1;
3712: } else {
3713: $chdircmd = "cd $targetdir/loncapa-X.Y.Z (X.Y.Z should correspond to a version number like '2.11.3')";
3714: }
1.1 raeburn 3715: print_and_log("\n");
3716: print &mt('LON-CAPA source files extracted.')."\n".
1.77 raeburn 3717: &mt('It remains for you to execute the following commands:').
3718: "\n$chdircmd\n$updatecmd\n".
3719: &mt('If you have any trouble, please see [_1] and [_2]',
3720: 'http://install.loncapa.org/','http://help.loncapa.org/')."\n";
1.1 raeburn 3721: $updateshown = 1;
3722: }
3723: return ($have_tarball,$updateshown);
3724: }
3725:
3726: close LOG;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>