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