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