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