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