Annotation of doc/install/linux/install.pl, revision 1.42
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;
29: use DBI;
30: use LCLocalization::localize;
31:
32: # ========================================================= The language handle
33:
34: my %languages = (
35: ar => 'Arabic',
36: de => 'German',
37: en => 'English',
38: es => 'Spanish (Castellan)',
39: fa => 'Persian',
40: fr => 'French',
41: he => 'Hebrew',
42: ja => 'Japanese',
43: pt => 'Portuguese',
44: ru => 'Russian',
45: tr => 'Turkish',
46: zh => 'Chinese Simplified'
47: );
48:
49: use vars qw($lh $lang);
50: $lang = 'en';
51: if (@ARGV > 0) {
52: foreach my $poss (keys(%languages)) {
53: if ($ARGV[0] eq $poss) {
54: $lang = $ARGV[0];
55: }
56: }
57: }
58:
59: &get_language_handle($lang);
60:
61: # Check user has root privs
62: if (0 != $<) {
63: print &mt('This script must be run as root.')."\n".
64: &mt('Stopping execution.')."\n";
65: exit;
66: }
67:
68:
69: # Globals: filehandle LOG is global.
70: if (!open(LOG,">>loncapa_install.log")) {
71: print &mt('Unable to open log file.')."\n".
72: &mt('Stopping execution.')."\n";
73: exit;
74: } else {
1.42 ! raeburn 75: print LOG '$Id: install.pl,v 1.41 2017/03/29 22:52:04 raeburn Exp $'."\n";
1.1 raeburn 76: }
77:
78: #
1.2 raeburn 79: # Helper routines and routines to establish recommended actions
1.1 raeburn 80: #
81:
82: sub get_language_handle {
83: my @languages = @_;
84: $lh=LCLocalization::localize->get_handle(@languages);
85: }
86:
87: sub mt (@) {
88: if ($lh) {
89: if ($_[0] eq '') {
90: if (wantarray) {
91: return @_;
92: } else {
93: return $_[0];
94: }
95: } else {
96: return $lh->maketext(@_);
97: }
98: } else {
99: if (wantarray) {
100: return @_;
101: } else {
102: return $_[0];
103: }
104: }
105: }
106:
107: sub texthash {
108: my (%hash) = @_;
109: foreach (keys(%hash)) {
110: $hash{$_}=&mt($hash{$_});
111: }
112: return %hash;
113: }
114:
115:
116: sub skip_if_nonempty {
117: my ($string,$error)=@_;
118: return if (! defined($error));
119: chomp($string);chomp($error);
120: if ($string ne '') {
121: print_and_log("$error\n".&mt('Stopping execution.')."\n");
122: return 1;
123: }
124: return;
125: }
126:
127: sub writelog {
128: while ($_ = shift) {
129: chomp();
130: print LOG "$_\n";
131: }
132: }
133:
134: sub print_and_log {
135: while ($_=shift) {
136: chomp();
137: print "$_\n";
138: print LOG "$_\n";
139: }
140: }
141:
142: sub get_user_selection {
143: my ($defaultrun) = @_;
144: my $do_action = 0;
145: my $choice = <STDIN>;
146: chomp($choice);
147: $choice =~ s/(^\s+|\s+$)//g;
148: my $yes = &mt('y');
149: if ($defaultrun) {
150: if (($choice eq '') || ($choice =~ /^\Q$yes\E/i)) {
151: $do_action = 1;
152: }
153: } else {
154: if ($choice =~ /^\Q$yes\E/i) {
155: $do_action = 1;
156: }
157: }
158: return $do_action;
159: }
160:
161: sub get_distro {
162: my ($distro,$gotprereqs,$updatecmd,$packagecmd,$installnow);
163: $packagecmd = '/bin/rpm -q LONCAPA-prerequisites ';
164: if (-e '/etc/redhat-release') {
165: open(IN,'</etc/redhat-release');
166: my $versionstring=<IN>;
167: chomp($versionstring);
168: close(IN);
169: if ($versionstring =~ /^Red Hat Linux release ([\d\.]+) /) {
170: my $version = $1;
171: if ($version=~/^7\./) {
172: $distro='redhat7';
173: } elsif ($version=~/^8\./) {
174: $distro='redhat8';
175: } elsif ($version=~/^9/) {
176: $distro='redhat9';
177: }
178: } elsif ($versionstring =~ /Fedora( Core)? release ([\d\.]+) /) {
179: my $version=$2;
180: if ($version - int($version) > .9) {
181: $distro = 'fedora'.(int($version)+1);
182: } else {
183: $distro = 'fedora'.int($version);
184: }
185: $updatecmd = 'yum install LONCAPA-prerequisites';
186: $installnow = 'yum -y install LONCAPA-prerequisites';
187: } elsif ($versionstring =~ /Red Hat Enterprise Linux [AE]S release ([\d\.]+) /) {
188: $distro = 'rhes'.$1;
189: $updatecmd = 'up2date -i LONCAPA-prerequisites';
190: } elsif ($versionstring =~ /Red Hat Enterprise Linux Server release (\d+)/) {
191: $distro = 'rhes'.$1;
192: $updatecmd = 'yum install LONCAPA-prerequisites';
193: $installnow = 'yum -y install LONCAPA-prerequisites';
1.21 raeburn 194: } elsif ($versionstring =~ /CentOS(?:| Linux) release (\d+)/) {
1.1 raeburn 195: $distro = 'centos'.$1;
196: $updatecmd = 'yum install LONCAPA-prerequisites';
197: $installnow = 'yum -y install LONCAPA-prerequisites';
1.22 raeburn 198: } elsif ($versionstring =~ /Scientific Linux (?:SL )?release ([\d.]+) /) {
1.1 raeburn 199: my $ver = $1;
200: $ver =~ s/\.\d+$//;
201: $distro = 'scientific'.$ver;
202: $updatecmd = 'yum install LONCAPA-prerequisites';
203: $installnow = 'yum -y install LONCAPA-prerequisites';
204: } else {
205: print &mt('Unable to interpret [_1] to determine system type.',
206: '/etc/redhat-release')."\n";
207: }
208: } elsif (-e '/etc/SuSE-release') {
209: open(IN,'</etc/SuSE-release');
210: my $versionstring=<IN>;
211: chomp($versionstring);
212: close(IN);
213: if ($versionstring =~ /^SUSE LINUX Enterprise Server ([\d\.]+) /i) {
214: $distro='sles'.$1;
215: if ($1 >= 10) {
216: $updatecmd = 'zypper install LONCAPA-prerequisites';
217: } else {
218: $updatecmd = 'yast -i LONCAPA-prerequisites';
219: }
220: } elsif ($versionstring =~ /^SuSE Linux ([\d\.]+) /i) {
221: $distro = 'suse'.$1;
1.12 raeburn 222: $updatecmd = 'yast -i LONCAPA-prerequisites';
1.1 raeburn 223: } elsif ($versionstring =~ /^openSUSE ([\d\.]+) /i) {
224: $distro = 'suse'.$1;
225: if ($1 >= 10.3 ) {
226: $updatecmd = 'zypper install LONCAPA-prerequisites';
227: } else {
228: $updatecmd = 'yast -i LONCAPA-prerequisites';
229: }
230: } else {
231: print &mt('Unable to interpret [_1] to determine system type.',
232: '/etc/SuSE-release')."\n";
233: }
234: } elsif (-e '/etc/issue') {
235: open(IN,'</etc/issue');
236: my $versionstring=<IN>;
237: chomp($versionstring);
238: close(IN);
239: $packagecmd = '/usr/bin/dpkg -l loncapa-prerequisites ';
240: $updatecmd = 'apt-get install loncapa-prerequisites';
241: if ($versionstring =~ /^Ubuntu (\d+)\.\d+/i) {
242: $distro = 'ubuntu'.$1;
243: $updatecmd = 'sudo apt-get install loncapa-prerequisites';
244: } elsif ($versionstring =~ /^Debian\s+GNU\/Linux\s+(\d+)\.\d+/i) {
245: $distro = 'debian'.$1;
246: } elsif (-e '/etc/debian_version') {
247: open(IN,'</etc/debian_version');
248: my $version=<IN>;
249: chomp($version);
250: close(IN);
251: if ($version =~ /^(\d+)\.\d+\.?\d*/) {
252: $distro='debian'.$1;
253: } else {
254: print &mt('Unable to interpret [_1] to determine system type.',
255: '/etc/debian_version')."\n";
256: }
257: } else {
258: print &mt('Unable to interpret [_1] to determine system type.',
259: '/etc/issue')."\n";
260: }
261: } elsif (-e '/etc/debian_version') {
262: open(IN,'</etc/debian_version');
263: my $version=<IN>;
264: chomp($version);
265: close(IN);
266: if ($version =~ /^(\d+)\.\d+\.?\d*/) {
267: $distro='debian'.$1;
268: $packagecmd = '/usr/bin/dpkg -l loncapa-prerequisites ';
269: $updatecmd = 'apt-get install loncapa-prerequisites';
270: } else {
271: print &mt('Unable to interpret [_1] to determine system type.',
272: '/etc/debian_version')."\n";
273: }
274: } else {
275: print &mt('Unknown installation: expecting a debian, ubuntu, suse, sles, redhat, fedora or scientific linux system.')."\n";
276: }
277: return ($distro,$packagecmd,$updatecmd,$installnow);
278: }
279:
280: sub check_prerequisites {
281: my ($packagecmd,$distro) = @_;
282: my $gotprereqs;
283: if ($packagecmd ne '') {
284: if (open(PIPE,"$packagecmd|")) {
285: if ($distro =~ /^(debian|ubuntu)/) {
286: my @lines = <PIPE>;
287: chomp(@lines);
288: foreach my $line (@lines) {
289: if ($line =~ /^ii\s+loncapa-prerequisites\s+([\w\.]+)/) {
290: $gotprereqs = $1;
291: }
292: }
293: } else {
294: my $line = <PIPE>;
295: chomp($line);
1.8 raeburn 296: if ($line =~ /^LONCAPA\-prerequisites\-([\d\-]+)\.(?:[.\w]+)$/) {
1.1 raeburn 297: $gotprereqs = $1;
298: }
299: }
300: close(PIPE);
301: } else {
302: print &mt('Error: could not determine if LONCAPA-prerequisites package is installed')."\n";
303: }
304: }
305: return $gotprereqs;
306: }
307:
1.6 raeburn 308: sub check_locale {
309: my ($distro) = @_;
1.8 raeburn 310: my ($fh,$langvar,$command);
311: $langvar = 'LANG';
1.6 raeburn 312: if ($distro =~ /^(ubuntu|debian)/) {
313: if (!open($fh,"</etc/default/locale")) {
314: print &mt('Failed to open: [_1], default locale not checked.',
315: '/etc/default/locale');
316: }
1.8 raeburn 317: } elsif ($distro =~ /^(suse|sles)/) {
318: if (!open($fh,"</etc/sysconfig/language")) {
319: print &mt('Failed to open: [_1], default locale not checked.',
320: '/etc/sysconfig/language');
321: }
322: $langvar = 'RC_LANG';
1.24 raeburn 323: } elsif ($distro =~ /^fedora(\d+)/) {
324: if ($1 >= 18) {
325: if (!open($fh,"</etc/locale.conf")) {
326: print &mt('Failed to open: [_1], default locale not checked.',
327: '/etc/locale.conf');
328: }
329: } elsif (!open($fh,"</etc/sysconfig/i18n")) {
330: print &mt('Failed to open: [_1], default locale not checked.',
331: '/etc/sysconfig/i18n');
332: }
1.29 raeburn 333: } elsif ($distro =~ /^(?:rhes|centos|scientific)(\d+)/) {
334: if ($1 >= 7) {
335: if (!open($fh,"</etc/locale.conf")) {
336: print &mt('Failed to open: [_1], default locale not checked.',
337: '/etc/locale.conf');
338: }
339: } elsif (!open($fh,"</etc/sysconfig/i18n")) {
340: print &mt('Failed to open: [_1], default locale not checked.',
341: '/etc/sysconfig/i18n');
342: }
1.6 raeburn 343: } else {
344: if (!open($fh,"</etc/sysconfig/i18n")) {
345: print &mt('Failed to open: [_1], default locale not checked.',
346: '/etc/sysconfig/i18n');
347: }
348: }
349: my @data = <$fh>;
350: chomp(@data);
351: foreach my $item (@data) {
1.25 raeburn 352: if ($item =~ /^\Q$langvar\E=\"?([^\"]*)\"?/) {
1.6 raeburn 353: my $default = $1;
354: if ($default ne 'en_US.UTF-8') {
355: if ($distro =~ /^debian/) {
1.25 raeburn 356: $command = 'locale-gen en_US.UTF-8'."\n".
357: 'update-locale LANG=en_US.UTF-8';
1.6 raeburn 358: } elsif ($distro =~ /^ubuntu/) {
1.25 raeburn 359: $command = 'sudo locale-gen en_US.UTF-8'."\n".
360: 'sudo update-locale LANG=en_US.UTF-8';
1.7 raeburn 361: } elsif ($distro =~ /^(suse|sles)/) {
362: $command = 'yast language';
1.6 raeburn 363: } else {
364: $command = 'system-config-language';
365: }
366: }
367: last;
368: }
369: }
370: close($fh);
371: return $command;
372: }
373:
1.1 raeburn 374: sub check_required {
375: my ($instdir,$dsn) = @_;
376: my ($distro,$packagecmd,$updatecmd,$installnow) = &get_distro();
377: if ($distro eq '') {
378: return;
379: }
380: my $gotprereqs = &check_prerequisites($packagecmd,$distro);
381: if ($gotprereqs eq '') {
1.22 raeburn 382: return ($distro,$gotprereqs,'',$packagecmd,$updatecmd);
1.6 raeburn 383: }
384: my $localecmd = &check_locale($distro);
385: unless ($localecmd eq '') {
386: return ($distro,$gotprereqs,$localecmd);
1.1 raeburn 387: }
1.34 raeburn 388: my ($mysqlon,$mysqlsetup,$mysqlrestart,$dbh,$has_pass,$has_lcdb,%recommended,
1.35 raeburn 389: $downloadstatus,$filetouse,$production,$testing,$apachefw,$tostop,$uses_systemctl);
1.1 raeburn 390: my $wwwuid = &uid_of_www();
391: my $wwwgid = getgrnam('www');
392: if (($wwwuid eq '') || ($wwwgid eq '')) {
393: $recommended{'wwwuser'} = 1;
394: }
395: unless( -e "/usr/local/sbin/pwauth") {
396: $recommended{'pwauth'} = 1;
397: }
398: $mysqlon = &check_mysql_running($distro);
399: if ($mysqlon) {
400: my $mysql_has_wwwuser = &check_mysql_wwwuser();
1.34 raeburn 401: ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser) =
402: &check_mysql_setup($instdir,$dsn,$distro,$mysql_has_wwwuser);
403: if ($mysqlsetup eq 'needsrestart') {
404: $mysqlrestart = '';
405: if ($distro eq 'ubuntu') {
406: $mysqlrestart = 'sudo ';
407: }
408: $mysqlrestart .= 'service mysql restart';
409: return ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,$mysqlrestart);
1.1 raeburn 410: } else {
1.34 raeburn 411: if ($mysqlsetup eq 'noroot') {
1.1 raeburn 412: $recommended{'mysqlperms'} = 1;
1.34 raeburn 413: } else {
414: unless ($mysql_has_wwwuser) {
415: $recommended{'mysqlperms'} = 1;
416: }
417: }
418: if ($dbh) {
419: $has_lcdb = &check_loncapa_mysqldb($dbh);
420: }
421: unless ($has_lcdb) {
422: $recommended{'mysql'} = 1;
1.1 raeburn 423: }
424: }
425: }
1.5 raeburn 426: ($recommended{'firewall'},$apachefw) = &chkfirewall($distro);
1.35 raeburn 427: ($recommended{'runlevels'},$tostop,$uses_systemctl) = &chkconfig($distro,$instdir);
1.1 raeburn 428: $recommended{'apache'} = &chkapache($distro,$instdir);
429: $recommended{'stopsrvcs'} = &chksrvcs($distro,$tostop);
430: ($recommended{'download'},$downloadstatus,$filetouse,$production,$testing)
431: = &need_download();
1.6 raeburn 432: return ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,
1.34 raeburn 433: $mysqlrestart,\%recommended,$dbh,$has_pass,$has_lcdb,$downloadstatus,
1.35 raeburn 434: $filetouse,$production,$testing,$apachefw,$uses_systemctl);
1.1 raeburn 435: }
436:
437: sub check_mysql_running {
438: my ($distro) = @_;
1.23 raeburn 439: my $use_systemctl;
1.1 raeburn 440: my $mysqldaemon ='mysqld';
441: if ($distro =~ /^(suse|sles|debian|ubuntu)/) {
442: $mysqldaemon = 'mysql';
443: }
1.6 raeburn 444: my $process = 'mysqld_safe';
445: my $proc_owner = 'root';
446: if ($distro =~ /^ubuntu(\w+)/) {
447: if ($1 >= 10) {
448: $process = 'mysqld';
449: $proc_owner = 'mysql';
450: }
1.35 raeburn 451: } elsif ($distro =~ /^fedora(\d+)/) {
1.23 raeburn 452: if ($1 >= 16) {
453: $process = 'mysqld';
454: $proc_owner = 'mysql';
455: $use_systemctl = 1;
456: }
1.39 raeburn 457: if ($1 >= 19) {
1.37 raeburn 458: $mysqldaemon ='mariadb';
459: }
1.35 raeburn 460: } elsif ($distro =~ /^(?:centos|rhes|scientific)(\d+)/) {
1.29 raeburn 461: if ($1 >= 7) {
462: $mysqldaemon ='mariadb';
463: $process = 'mysqld';
464: $proc_owner = 'mysql';
465: $use_systemctl = 1;
466: }
1.35 raeburn 467: } elsif ($distro =~ /^sles(\d+)/) {
468: if ($1 >= 12) {
469: $use_systemctl = 1;
1.42 ! raeburn 470: $proc_owner = 'mysql';
! 471: $process = 'mysqld';
1.35 raeburn 472: }
473: } elsif ($distro =~ /^suse(\d+)/) {
474: if ($1 >= 13) {
475: $use_systemctl = 1;
476: }
1.29 raeburn 477: }
1.35 raeburn 478: if (open(PIPE,"ps -ef |grep $process |grep ^$proc_owner |grep -v grep 2>&1 |")) {
1.1 raeburn 479: my $status = <PIPE>;
480: close(PIPE);
481: chomp($status);
1.6 raeburn 482: if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
1.1 raeburn 483: print_and_log(&mt('MySQL is running.')."\n");
484: return 1;
485: } else {
1.23 raeburn 486: if ($use_systemctl) {
487: system("/bin/systemctl start $mysqldaemon.service >/dev/null 2>&1 ");
488: } else {
489: system("/etc/init.d/$mysqldaemon start >/dev/null 2>&1 ");
490: }
1.1 raeburn 491: print_and_log(&mt('Waiting for MySQL to start.')."\n");
492: sleep 5;
1.12 raeburn 493: if (open(PIPE,"ps -ef |grep $process |grep -v grep 2>&1 |")) {
494: $status = <PIPE>;
1.1 raeburn 495: close(PIPE);
496: chomp($status);
1.12 raeburn 497: if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
1.1 raeburn 498: print_and_log(&mt('MySQL is running.')."\n");
499: return 1;
500: } else {
1.12 raeburn 501: print_and_log(&mt('Still waiting for MySQL to start.')."\n");
502: sleep 5;
503: if (open(PIPE,"ps -ef |grep $process |grep -v grep 2>&1 |")) {
504: $status = <PIPE>;
505: close(PIPE);
506: chomp($status);
507: if ($status =~ /^\Q$proc_owner\E\s+\d+\s+/) {
508: print_and_log(&mt('MySQL is running.')."\n");
509: return 1;
510: } else {
511: print_and_log(&mt('Given up waiting for MySQL to start.')."\n");
512: }
513: }
1.1 raeburn 514: }
515: }
516: }
517: } else {
518: print &mt('Could not determine if MySQL is running.')."\n";
519: }
520: return;
521: }
522:
523: sub chkconfig {
1.8 raeburn 524: my ($distro,$instdir) = @_;
1.23 raeburn 525: my (%needfix,%tostop,%uses_systemctl);
1.1 raeburn 526: my $checker_bin = '/sbin/chkconfig';
1.23 raeburn 527: my $sysctl_bin = '/bin/systemctl';
1.6 raeburn 528: my %daemon = (
529: mysql => 'mysqld',
530: apache => 'httpd',
531: cups => 'cups',
532: ntp => 'ntpd',
533: memcached => 'memcached',
534: );
1.1 raeburn 535: my @runlevels = qw/3 4 5/;
536: my @norunlevels = qw/0 1 6/;
537: if ($distro =~ /^(suse|sles)/) {
538: @runlevels = qw/3 5/;
539: @norunlevels = qw/0 2 1 6/;
1.6 raeburn 540: $daemon{'mysql'} = 'mysql';
541: $daemon{'apache'} = 'apache2';
1.8 raeburn 542: $daemon{'ntp'} = 'ntp';
1.1 raeburn 543: if ($distro =~ /^(suse|sles)9/) {
1.6 raeburn 544: $daemon{'apache'} = 'apache';
1.1 raeburn 545: }
1.35 raeburn 546: if ($distro =~ /^(suse|sles)([\d\.]+)/) {
547: my $name = $1;
548: my $num = $2;
549: if ($num > 11) {
1.26 raeburn 550: $uses_systemctl{'apache'} = 1;
1.35 raeburn 551: if (($name eq 'sles') || ($name eq 'suse' && $num >= 13.2)) {
552: $uses_systemctl{'mysql'} = 1;
553: $uses_systemctl{'ntp'} = 1;
554: $uses_systemctl{'cups'} = 1;
555: $uses_systemctl{'memcached'} = 1;
556: $daemon{'ntp'} = 'ntpd';
557: }
1.26 raeburn 558: }
559: }
1.6 raeburn 560: } elsif ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
561: my $version = $1;
1.1 raeburn 562: @runlevels = qw/2 3 4 5/;
563: @norunlevels = qw/0 1 6/;
564: $checker_bin = '/usr/sbin/sysv-rc-conf';
1.6 raeburn 565: $daemon{'mysql'} = 'mysql';
566: $daemon{'apache'} = 'apache2';
567: $daemon{'ntp'} = 'ntp';
568: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
569: $daemon{'cups'} = 'cupsys';
570: }
1.26 raeburn 571: } elsif ($distro =~ /^fedora(\d+)/) {
1.23 raeburn 572: my $version = $1;
573: if ($version >= 15) {
574: $uses_systemctl{'ntp'} = 1;
575: }
576: if ($version >= 16) {
577: $uses_systemctl{'mysql'} = 1;
578: $uses_systemctl{'apache'} = 1;
1.35 raeburn 579: $uses_systemctl{'memcached'} = 1;
580: $uses_systemctl{'cups'} = 1;
1.23 raeburn 581: }
1.39 raeburn 582: if ($version >= 19) {
1.37 raeburn 583: $daemon{'mysql'} = 'mariadb';
584: }
1.29 raeburn 585: } elsif ($distro =~ /^(?:centos|rhes|scientific)(\d+)/) {
586: my $version = $1;
587: if ($version >= 7) {
588: $uses_systemctl{'ntp'} = 1;
589: $uses_systemctl{'mysql'} = 1;
590: $uses_systemctl{'apache'} = 1;
1.35 raeburn 591: $uses_systemctl{'memcached'} = 1;
592: $uses_systemctl{'cups'} = 1;
1.30 raeburn 593: $daemon{'mysql'} = 'mariadb';
1.29 raeburn 594: }
1.1 raeburn 595: }
1.23 raeburn 596: my $nocheck;
1.1 raeburn 597: if (! -x $checker_bin) {
1.23 raeburn 598: if ($uses_systemctl{'mysql'} && $uses_systemctl{'apache'}) {
599: if (! -x $sysctl_bin) {
600: $nocheck = 1;
601: }
602: } else {
603: $nocheck = 1;
604: }
605: }
606: if ($nocheck) {
1.6 raeburn 607: print &mt('Could not check runlevel status for MySQL or Apache')."\n";
1.1 raeburn 608: return;
609: }
610: my $rlstr = join('',@runlevels);
611: my $nrlstr = join('',@norunlevels);
1.23 raeburn 612:
1.6 raeburn 613: foreach my $type ('apache','mysql','ntp','cups','memcached') {
614: my $service = $daemon{$type};
1.23 raeburn 615: if ($uses_systemctl{$type}) {
1.35 raeburn 616: if (($type eq 'memcached') || ($type eq 'cups')) {
617: if (-l "/etc/systemd/system/multi-user.target.wants/$service.service") {
618: $tostop{$type} = 1;
619: }
620: } else {
621: if (!-l "/etc/systemd/system/multi-user.target.wants/$service.service") {
622: $needfix{$type} = "systemctl enable $service.service";
623: }
1.23 raeburn 624: }
625: } else {
626: my $command = $checker_bin.' --list '.$service.' 2>/dev/null';
1.35 raeburn 627: if ($type eq 'cups') {
1.23 raeburn 628: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
629: my $version = $1;
630: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
631: $command = $checker_bin.' --list cupsys 2>/dev/null';
1.19 raeburn 632: }
633: }
634: }
1.23 raeburn 635: my $results = `$command`;
636: my $tofix;
637: if ($results eq '') {
638: if (($type eq 'apache') || ($type eq 'mysql') || ($type eq 'ntp')) {
639: if ($distro =~ /^(debian|ubuntu)/) {
640: $tofix = "update-rc.d $type defaults";
641: } else {
642: $tofix = "$checker_bin --add $service\n";
643: }
1.6 raeburn 644: }
1.23 raeburn 645: } else {
646: my %curr_runlevels;
647: for (my $rl=0; $rl<=6; $rl++) {
648: if ($results =~ /$rl:on/) { $curr_runlevels{$rl}++; }
649: }
650: if (($type eq 'apache') || ($type eq 'mysql') || ($type eq 'ntp')) {
651: my $warning;
652: foreach my $rl (@runlevels) {
653: if (!exists($curr_runlevels{$rl})) {
654: $warning = 1;
655: }
656: }
657: if ($warning) {
658: $tofix = "$checker_bin --level $rlstr $service on\n";
659: }
660: } elsif (keys(%curr_runlevels) > 0) {
661: $tostop{$type} = 1;
1.1 raeburn 662: }
663: }
1.23 raeburn 664: if ($tofix) {
665: $needfix{$type} = $tofix;
1.1 raeburn 666: }
1.5 raeburn 667: }
1.1 raeburn 668: }
669: if ($distro =~ /^(suse|sles)([\d\.]+)$/) {
670: my $name = $1;
671: my $version = $2;
672: my ($major,$minor);
673: if ($name eq 'suse') {
674: ($major,$minor) = split(/\./,$version);
675: } else {
676: $major = $version;
677: }
678: if ($major > 10) {
1.8 raeburn 679: if (&check_SuSEfirewall2_setup($instdir)) {
680: $needfix{'insserv'} = 1;
681: }
1.1 raeburn 682: }
683: }
1.35 raeburn 684: return (\%needfix,\%tostop,\%uses_systemctl);
1.1 raeburn 685: }
686:
687: sub chkfirewall {
1.5 raeburn 688: my ($distro) = @_;
1.1 raeburn 689: my $configfirewall = 1;
690: my %ports = (
691: http => 80,
692: https => 443,
693: );
1.5 raeburn 694: my %activefw;
1.1 raeburn 695: if (&firewall_is_active()) {
696: my $iptables = &get_pathto_iptables();
697: if ($iptables eq '') {
698: print &mt('Firewall not checked as path to iptables not determined.')."\n";
699: } else {
1.5 raeburn 700: my @fwchains = &get_fw_chains($iptables,$distro);
1.1 raeburn 701: if (@fwchains) {
702: foreach my $service ('http','https') {
703: foreach my $fwchain (@fwchains) {
704: if (&firewall_is_port_open($iptables,$fwchain,$ports{$service})) {
705: $activefw{$service} = 1;
706: last;
707: }
708: }
709: }
710: if ($activefw{'http'}) {
711: $configfirewall = 0;
712: }
713: } else {
714: print &mt('Firewall not checked as iptables Chains not identified.')."\n";
715: }
716: }
717: } else {
718: print &mt('Firewall not enabled.')."\n";
719: }
1.5 raeburn 720: return ($configfirewall,\%activefw);
1.1 raeburn 721: }
722:
723: sub chkapache {
724: my ($distro,$instdir) = @_;
725: my $fixapache = 1;
1.28 raeburn 726: if ($distro =~ /^(debian|ubuntu)(\d+)$/) {
727: my $distname = $1;
728: my $version = $2;
1.33 raeburn 729: my ($stdconf,$stdsite);
730: if (($distname eq 'ubuntu') && ($version > 12)) {
731: $stdconf = "$instdir/debian-ubuntu/ubuntu14/loncapa_conf";
732: $stdsite = "$instdir/debian-ubuntu/ubuntu14/loncapa_sites";
733: } else {
734: $stdconf = "$instdir/debian-ubuntu/loncapa";
735: }
736: if (!-e $stdconf) {
1.1 raeburn 737: $fixapache = 0;
738: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.28 raeburn 739: } else {
1.33 raeburn 740: my ($configfile,$sitefile);
1.28 raeburn 741: if (($distname eq 'ubuntu') && ($version > 12)) {
1.33 raeburn 742: $sitefile = '/etc/apache2/sites-available/loncapa';
1.28 raeburn 743: $configfile = "/etc/apache2/conf-available/loncapa";
1.33 raeburn 744: } else {
745: $configfile = "/etc/apache2/sites-available/loncapa";
1.28 raeburn 746: }
1.33 raeburn 747: if (($configfile ne '') && (-e $configfile) && (-e $stdconf)) {
748: if (open(PIPE, "diff --brief $stdconf $configfile |")) {
1.28 raeburn 749: my $diffres = <PIPE>;
750: close(PIPE);
751: chomp($diffres);
752: unless ($diffres) {
753: $fixapache = 0;
754: }
1.1 raeburn 755: }
756: }
1.33 raeburn 757: if ((!$fixapache) && ($distname eq 'ubuntu') && ($version > 12)) {
758: if (($sitefile ne '') && (-e $sitefile) && (-e $stdsite)) {
759: if (open(PIPE, "diff --brief $stdsite $sitefile |")) {
760: my $diffres = <PIPE>;
761: close(PIPE);
762: chomp($diffres);
763: unless ($diffres) {
764: $fixapache = 0;
765: }
766: }
767: }
768: }
1.1 raeburn 769: }
1.6 raeburn 770: if (!$fixapache) {
771: foreach my $module ('headers.load','expires.load') {
772: unless (-l "/etc/apache2/mods-enabled/$module") {
773: $fixapache = 1;
774: }
775: }
776: }
1.1 raeburn 777: } elsif ($distro =~ /^(?:suse|sles)([\d\.]+)$/) {
778: my $apache = 'apache';
779: if ($1 >= 10) {
1.8 raeburn 780: $apache = 'apache2';
1.1 raeburn 781: }
1.9 raeburn 782: if (!-e "$instdir/sles-suse/default-server.conf") {
1.1 raeburn 783: $fixapache = 0;
784: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.9 raeburn 785: } elsif ((-e "/etc/$apache/default-server.conf") && (-e "$instdir/sles-suse/default-server.conf")) {
786: if (open(PIPE, "diff --brief $instdir/sles-suse/default-server.conf /etc/$apache/default-server.conf |")) {
787: my $diffres = <PIPE>;
788: close(PIPE);
789: chomp($diffres);
790: unless ($diffres) {
791: $fixapache = 0;
792: }
793: }
794: }
795: } elsif ($distro eq 'rhes4') {
796: if (!-e "$instdir/rhes4/httpd.conf") {
797: $fixapache = 0;
798: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
799: } elsif ((-e "/etc/httpd/conf/httpd.conf") && (-e "$instdir/rhes4/httpd.conf")) {
800: if (open(PIPE, "diff --brief $instdir/rhes4/httpd.conf /etc/httpd/conf/httpd.conf |")) {
1.1 raeburn 801: my $diffres = <PIPE>;
802: close(PIPE);
803: chomp($diffres);
804: unless ($diffres) {
805: $fixapache = 0;
806: }
807: }
808: }
809: } else {
1.14 raeburn 810: my $configfile = 'httpd.conf';
811: if ($distro =~ /^(?:centos|rhes|scientific)(\d+)$/) {
1.29 raeburn 812: if ($1 >= 7) {
813: $configfile = 'apache2.4/httpd.conf';
814: } elsif ($1 > 5) {
1.14 raeburn 815: $configfile = 'new/httpd.conf';
816: }
817: } elsif ($distro =~ /^fedora(\d+)$/) {
1.29 raeburn 818: if ($1 > 17) {
819: $configfile = 'apache2.4/httpd.conf';
820: } elsif ($1 > 10) {
1.15 raeburn 821: $configfile = 'new/httpd.conf';
1.14 raeburn 822: }
823: }
824: if (!-e "$instdir/centos-rhes-fedora-sl/$configfile") {
1.1 raeburn 825: $fixapache = 0;
826: print &mt('Warning: No LON-CAPA Apache configuration file found for installation check.')."\n";
1.14 raeburn 827: } elsif ((-e "/etc/httpd/conf/httpd.conf") && (-e "$instdir/centos-rhes-fedora-sl/$configfile")) {
828: if (open(PIPE, "diff --brief $instdir/centos-rhes-fedora-sl/$configfile /etc/httpd/conf/httpd.conf |")) {
1.1 raeburn 829: my $diffres = <PIPE>;
830: close(PIPE);
831: chomp($diffres);
832: unless ($diffres) {
833: $fixapache = 0;
834: }
835: }
836: }
837: }
838: return $fixapache;
839: }
840:
841: sub chksrvcs {
842: my ($distro,$tostop) = @_;
843: my %stopsrvcs;
844: if (ref($tostop) eq 'HASH') {
845: %stopsrvcs = %{$tostop};
846: }
1.6 raeburn 847: foreach my $service ('cups','memcached') {
1.1 raeburn 848: next if (exists($stopsrvcs{$service}));
849: my $daemon = $service;
850: if ($service eq 'cups') {
851: $daemon = 'cupsd';
852: }
853: my $cmd = "ps -ef |grep '$daemon' |grep -v grep";
854: if (open(PIPE,'-|',$cmd)) {
855: my $daemonrunning = <PIPE>;
856: chomp($daemonrunning);
857: close(PIPE);
858: if ($daemonrunning) {
1.12 raeburn 859: if ($service eq 'memcached') {
1.16 raeburn 860: my $cmd = '/usr/bin/memcached';
861: if ($distro =~ /^(suse|sles)/) {
862: $cmd = '/usr/sbin/memcached';
863: }
1.12 raeburn 864: unless ($daemonrunning =~ m{^www[^/]+\Q$cmd -m 400 -v\E$}) {
1.10 raeburn 865: $stopsrvcs{$service} = 1;
866: }
867: } else {
868: $stopsrvcs{$service} = 1;
869: }
1.1 raeburn 870: }
871: }
1.10 raeburn 872: }
1.1 raeburn 873: return \%stopsrvcs;
874: }
875:
876: sub need_download {
877: my $needs_download = 1;
878: my ($production,$testing,$stdsizes) = &download_versionslist();
879: my ($rootdir,$localcurrent,$localtesting,%tarball,%localsize,%bymodtime,
880: %bysize,$filetouse,$downloadstatus);
881: $rootdir = '/root';
882: if (opendir(my $dir,"$rootdir")) {
883: my (@lcdownloads,$version);
884: foreach my $file (readdir($dir)) {
885: if ($file =~ /^loncapa\-([\w\-.]+)\.tar\.gz$/) {
886: $version = $1;
887: } else {
888: next;
889: }
890: if (ref($stdsizes) eq 'HASH') {
891: if ($version eq 'current') {
892: my @stats = stat("$rootdir/$file");
893: $localcurrent = $stats[7];
1.4 raeburn 894: if ($localcurrent == $stdsizes->{$production}) {
1.1 raeburn 895: $needs_download = 0;
896: $filetouse = $file;
897: }
898: } elsif ($version eq 'testing') {
899: my @stats = stat("$rootdir/$file");
900: $localtesting = $stats[7];
1.4 raeburn 901: if ($localtesting == $stdsizes->{$testing}) {
1.1 raeburn 902: $needs_download = 0;
903: $filetouse = $file;
904: }
905: }
906: }
907: $tarball{$version} = $file;
908: push(@lcdownloads,$version);
909: }
910: if ($needs_download) {
911: if (@lcdownloads > 0) {
912: foreach my $version (@lcdownloads) {
913: my @stats = stat("$rootdir/$tarball{$version}");
914: my $mtime = $stats[9];
915: $localsize{$version} = $stats[7];
916: if ($mtime) {
917: push(@{$bymodtime{$mtime}},$version);
918: }
919: if ($localsize{$version}) {
920: push(@{$bysize{$localsize{$version}}},$version);
921: }
922: }
923: if ($testing) {
924: if (exists($localsize{$testing})) {
925: if ($stdsizes->{$testing} == $localsize{$testing}) {
926: $needs_download = 0;
927: $filetouse = 'loncapa-'.$testing.'.tar.gz';
928: }
929: }
930: }
931: if ($needs_download) {
932: if ($production) {
933: if (exists($localsize{$production})) {
934: if ($stdsizes->{$production} == $localsize{$production}) {
935: $needs_download = 0;
936: $filetouse = 'loncapa-'.$production.'.tar.gz';
937: }
938: }
939: }
940: }
941: if ($needs_download) {
942: my @sorted = sort { $b <=> $a } keys(%bymodtime);
943: my $newest = $sorted[0];
944: if (ref($bymodtime{$newest}) eq 'ARRAY') {
945: $downloadstatus =
946: "Latest LON-CAPA source download in $rootdir is: ".
947: join(',',@{$bymodtime{$newest}})." (downloaded ".
948: localtime($newest).")\n";
949: }
950: } else {
951: $downloadstatus =
952: "The $rootdir directory already contains the latest LON-CAPA version:".
953: "\n".$filetouse."\n"."which can be used for installation.\n";
954: }
955: } else {
956: $downloadstatus = "The $rootdir directory does not appear to contain any downloaded LON-CAPA source code files which can be used for installation.\n";
957: }
958: }
959: } else {
960: $downloadstatus = "Could not open $rootdir directory to look for existing downloads of LON-CAPA source code.\n";
961: }
962: return ($needs_download,$downloadstatus,$filetouse,$production,$testing);
963: }
964:
965: sub check_mysql_setup {
1.34 raeburn 966: my ($instdir,$dsn,$distro,$mysql_has_wwwuser) = @_;
1.1 raeburn 967: my ($mysqlsetup,$has_pass);
968: my $dbh = DBI->connect($dsn,'root','',{'PrintError'=>0});
969: if ($dbh) {
970: $mysqlsetup = 'noroot';
971: } elsif ($DBI::err =~ /1045/) {
972: $has_pass = 1;
1.34 raeburn 973: } elsif ($distro =~ /^ubuntu(\d+)$/) {
974: my $version = $1;
975: if ($1 > 12) {
976: print_and_log(&mt('Restarting mysql, please be patient')."\n");
977: if (open (PIPE, "service mysql restart 2>&1 |")) {
978: while (<PIPE>) {
979: print $_;
980: }
981: close(PIPE);
982: }
983: unless ($mysql_has_wwwuser) {
984: $mysql_has_wwwuser = &check_mysql_wwwuser();
985: }
986: $dbh = DBI->connect($dsn,'root','',{'PrintError'=>0});
987: if ($dbh) {
988: $mysqlsetup = 'noroot';
989: } elsif ($DBI::err =~ /1045/) {
990: $has_pass = 1;
991: } else {
992: $mysqlsetup = 'needsrestart';
993: return ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser);
994: }
995: }
1.1 raeburn 996: }
997: if ($has_pass) {
998: print &mt('You have already set a root password for the MySQL database.')."\n";
999: my $currpass = &get_mysql_password(&mt('Please enter the password now'));
1000: $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
1001: if ($dbh) {
1002: $mysqlsetup = 'rootok';
1003: print_and_log(&mt('Password accepted.')."\n");
1004: } else {
1005: $mysqlsetup = 'rootfail';
1006: print_and_log(&mt('Problem accessing MySQL.')."\n");
1007: if ($DBI::err =~ /1045/) {
1008: print_and_log(&mt('Perhaps the password was incorrect?')."\n");
1009: print &mt('Try again?').' ';
1010: $currpass = &get_mysql_password(&mt('Re-enter password now'));
1011: $dbh = DBI->connect($dsn,'root',$currpass,{'PrintError'=>0});
1012: if ($dbh) {
1013: $mysqlsetup = 'rootok';
1014: print_and_log(&mt('Password accepted.')."\n");
1015: } else {
1016: if ($DBI::err =~ /1045/) {
1017: print_and_log(&mt('Incorrect password.')."\n");
1018: }
1019: }
1020: }
1021: }
1.34 raeburn 1022: } elsif ($mysqlsetup ne 'noroot') {
1.1 raeburn 1023: print_and_log(&mt('Problem accessing MySQL.')."\n");
1024: $mysqlsetup = 'rootfail';
1025: }
1.34 raeburn 1026: return ($mysqlsetup,$has_pass,$dbh,$mysql_has_wwwuser);
1.1 raeburn 1027: }
1028:
1029: sub check_mysql_wwwuser {
1030: my $mysql_wwwuser;
1.12 raeburn 1031: my $dbhn = DBI->connect("DBI:mysql:database=information_schema",'www','localhostkey',
1032: {PrintError => +0}) || return;
1.1 raeburn 1033: if ($dbhn) {
1034: $mysql_wwwuser = 1;
1035: $dbhn->disconnect;
1036: }
1037: return $mysql_wwwuser;
1038: }
1039:
1040: sub check_loncapa_mysqldb {
1041: my ($dbh) = @_;
1042: my $has_lcdb;
1043: if (ref($dbh)) {
1044: my $sth = $dbh->prepare("SHOW DATABASES");
1045: $sth->execute();
1046: while (my $dbname = $sth->fetchrow_array) {
1047: if ($dbname eq 'loncapa') {
1048: $has_lcdb = 1;
1049: last;
1050: }
1051: }
1052: $sth->finish();
1053: }
1054: return $has_lcdb;
1055: }
1056:
1057: sub get_pathto_iptables {
1058: my $iptables;
1059: if (-e '/sbin/iptables') {
1060: $iptables = '/sbin/iptables';
1061: } elsif (-e '/usr/sbin/iptables') {
1062: $iptables = '/usr/sbin/iptables';
1063: } else {
1064: print &mt('Unable to find iptables command.')."\n";
1065: }
1066: return $iptables;
1067: }
1068:
1069: sub firewall_is_active {
1070: if (-e '/proc/net/ip_tables_names') {
1071: return 1;
1072: } else {
1073: return 0;
1074: }
1075: }
1076:
1077: sub get_fw_chains {
1.5 raeburn 1078: my ($iptables,$distro) = @_;
1.1 raeburn 1079: my @fw_chains;
1080: my $suse_config = "/etc/sysconfig/SuSEfirewall2";
1081: my $ubuntu_config = "/etc/ufw/ufw.conf";
1082: if (-e $suse_config) {
1083: push(@fw_chains,'input_ext');
1084: } else {
1085: my @posschains;
1086: if (-e $ubuntu_config) {
1087: @posschains = ('ufw-user-input','INPUT');
1.5 raeburn 1088: } elsif ($distro =~ /^debian5/) {
1089: @posschains = ('INPUT');
1.1 raeburn 1090: } else {
1091: @posschains = ('RH-Firewall-1-INPUT','INPUT');
1092: if (!-e '/etc/sysconfig/iptables') {
1093: if (!-e '/var/lib/iptables') {
1094: print &mt('Unable to find iptables file containing static definitions.')."\n";
1095: }
1096: push(@fw_chains,'RH-Firewall-1-INPUT');
1097: }
1098: }
1099: if ($iptables eq '') {
1100: $iptables = &get_pathto_iptables();
1101: }
1102: my %counts;
1103: if (open(PIPE,"$iptables -L -n |")) {
1104: while(<PIPE>) {
1105: foreach my $chain (@posschains) {
1106: if (/(\Q$chain\E)/) {
1107: $counts{$1} ++;
1108: }
1109: }
1110: }
1111: close(PIPE);
1112: }
1113: foreach my $fw_chain (@posschains) {
1114: if ($counts{$fw_chain}) {
1115: unless(grep(/^\Q$fw_chain\E$/,@fw_chains)) {
1116: push(@fw_chains,$fw_chain);
1117: }
1118: }
1119: }
1120: }
1121: return @fw_chains;
1122: }
1123:
1124: sub firewall_is_port_open {
1125: my ($iptables,$fw_chain,$port) = @_;
1126: # returns 1 if the firewall port is open, 0 if not.
1127: #
1128: # check if firewall is active or installed
1129: return if (! &firewall_is_active());
1130: my $count = 0;
1131: if (open(PIPE,"$iptables -L $fw_chain -n |")) {
1132: while(<PIPE>) {
1133: if (/tcp dpt\:\Q$port\E/) {
1134: $count ++;
1135: last;
1136: }
1137: }
1138: close(PIPE);
1139: } else {
1140: print &mt('Firewall status not checked: unable to run [_1].','iptables -L')."\n";
1141: }
1142: return $count;
1143: }
1144:
1145: sub get_mysql_password {
1146: my ($prompt) = @_;
1147: local $| = 1;
1148: print $prompt.': ';
1149: my $newpasswd = '';
1150: ReadMode 'raw';
1151: my $key;
1152: while(ord($key = ReadKey(0)) != 10) {
1153: if(ord($key) == 127 || ord($key) == 8) {
1154: chop($newpasswd);
1155: print "\b \b";
1156: } elsif(!ord($key) < 32) {
1157: $newpasswd .= $key;
1158: print '*';
1159: }
1160: }
1161: ReadMode 'normal';
1162: print "\n";
1163: return $newpasswd;
1164: }
1165:
1166: sub check_SuSEfirewall2_setup {
1167: my ($instdir) = @_;
1168: my $need_override = 1;
1.9 raeburn 1169: if ((-e "/etc/insserv/overrides/SuSEfirewall2_setup") && (-e "$instdir/sles-suse/SuSEfirewall2_setup")) {
1170: if (open(PIPE, "diff --brief $instdir/sles-suse/SuSEfirewall2_setup /etc/insserv/overrides/SuSEfirewall2_setup |")) {
1.1 raeburn 1171: my $diffres = <PIPE>;
1172: close(PIPE);
1173: chomp($diffres);
1174: unless ($diffres) {
1175: $need_override = 0;
1176: }
1177: }
1178: }
1179: return $need_override;
1180: }
1181:
1182: sub download_versionslist {
1183: my ($production,$testing,%sizes);
1184: if (-e "latest.txt") {
1185: unlink("latest.txt");
1186: }
1187: my $rtncode = system("wget http://install.loncapa.org/versions/latest.txt ".
1188: "> /dev/null 2>&1");
1189: if (!$rtncode) {
1190: if (open(my $fh,"<latest.txt")) {
1191: my @info = <$fh>;
1192: close($fh);
1193: foreach my $line (@info) {
1194: chomp();
1195: if ($line =~ /^\QLATEST-IS: \E([\w\-.]+):(\d+)$/) {
1196: $production = $1;
1197: $sizes{$1} = $2;
1198: } elsif ($line =~ /^LATEST-TESTING-IS: \E([\w\-.]+):(\d+)$/) {
1199: $testing = $1;
1200: $sizes{$1} = $2;
1201: }
1202: }
1203: }
1204: }
1205: return ($production,$testing,\%sizes);
1206: }
1207:
1208: #
1209: # End helper routines.
1210: # Main script starts here
1211: #
1212:
1213: print "
1214: ********************************************************************
1215:
1216: ".&mt('Welcome to LON-CAPA')."
1217:
1218: ".&mt('This script will configure your system for installation of LON-CAPA.')."
1219:
1220: ********************************************************************
1221:
1222: ".&mt('The following actions are available:')."
1223:
1.4 raeburn 1224: ".&mt('1.')." ".&mt('Create the www user/group.')."
1.1 raeburn 1225: ".&mt('This is the user/group ownership under which Apache child processes run.')."
1226: ".&mt('It also owns most directories within the /home/httpd directory.')."
1227: ".&mt('This directory is where most LON-CAPA files and directories are stored.')."
1.4 raeburn 1228: ".&mt('2.')." ".&mt('Install the package LON-CAPA uses to authenticate users.')."
1229: ".&mt('3.')." ".&mt('Set-up the MySQL database.')."
1230: ".&mt('4.')." ".&mt('Set-up MySQL permissions.')."
1231: ".&mt('5.')." ".&mt('Configure Apache web server.')."
1232: ".&mt('6.')." ".&mt('Configure start-up of services.')."
1233: ".&mt('7.')." ".&mt('Check firewall settings.')."
1234: ".&mt('8.')." ".&mt('Stop services not used by LON-CAPA,')."
1.1 raeburn 1235: ".&mt('i.e., services for a print server: [_1] daemon.',"'cups'")."
1.4 raeburn 1236: ".&mt('9.')." ".&mt('Download LON-CAPA source code in readiness for installation.')."
1.1 raeburn 1237:
1238: ".&mt('Typically, you will run this script only once, when you first install LON-CAPA.')."
1239:
1240: ".&mt('The script will analyze your system to determine which actions are recommended.')."
1241: ".&mt('The script will then prompt you to choose the actions you would like taken.')."
1242:
1243: ".&mt('For each the recommended action will be selected if you hit Enter/Return.')."
1244: ".&mt('To override the default, type the lower case option from the two options listed.')."
1245: ".&mt('So, if the default is "yes", ~[Y/n~] will be shown -- type n to override.')."
1246: ".&mt('Whereas if the default is "no", ~[y/N~] will be shown -- type y to override.')."
1247:
1248: ".&mt('To accept the default, simply hit Enter/Return on your keyboard.')."
1249: ".&mt('Otherwise type: y or n then hit the Enter/Return key.')."
1250:
1251: ".&mt('Once a choice has been entered for all nine actions, required changes will be made.')."
1252: ".&mt('Feedback will be displayed on screen, and also stored in: [_1].','loncapa_install.log')."
1253:
1254: ".&mt('Continue? ~[Y/n~] ');
1255:
1256: my $go_on = &get_user_selection(1);
1257: if (!$go_on) {
1258: exit;
1259: }
1260:
1261: my $instdir = `pwd`;
1262: chomp($instdir);
1263:
1264: my %callsub;
1265: my @actions = ('wwwuser','pwauth','mysql','mysqlperms','apache',
1266: 'runlevels','firewall','stopsrvcs','download');
1267: my %prompts = &texthash(
1268: wwwuser => "Create the 'www' user?",
1269: pwauth => 'Install the package LON-CAPA uses to authenticate users?',
1270: mysql => 'Set-up the MySQL database?',
1271: mysqlperms => 'Set-up MySQL permissions?',
1272: apache => 'Configure Apache web server?',
1273: runlevels => 'Set overrides for start-up order of services?',
1274: firewall => 'Configure firewall settings for Apache',
1275: stopsrvcs => 'Stop extra services not required on a LON-CAPA server?',
1276: download => 'Download LON-CAPA source code in readiness for installation?',
1277: );
1278:
1279: print "\n".&mt('Checking system status ...')."\n";
1280:
1281: my $dsn = "DBI:mysql:database=mysql";
1.34 raeburn 1282: my ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,$mysqlrestart,
1283: $recommended,$dbh,$has_pass,$has_lcdb,$downloadstatus,$filetouse,$production,
1.35 raeburn 1284: $testing,$apachefw,$uses_systemctl) = &check_required($instdir,$dsn);
1.1 raeburn 1285: if ($distro eq '') {
1286: print "\n".&mt('Linux distribution could not be verified as a supported distribution.')."\n".
1287: &mt('The following are supported: [_1].',
1288: 'CentOS, RedHat Enterprise, Fedora, Scientific Linux, '.
1289: 'openSuSE, SLES, Ubuntu LTS, Debian')."\n\n".
1290: &mt('Stopping execution.')."\n";
1291: exit;
1292: }
1.34 raeburn 1293: if ($mysqlrestart) {
1294: print "\n".&mt('The mysql daemon needs to be restarted using the following command:')."\n".
1295: $mysqlrestart."\n\n".
1296: &mt('Stopping execution of install.pl script.')."\n".
1297: &mt('Please run the install.pl script again, once you have restarted mysql.')."\n";
1298: exit;
1299: }
1.6 raeburn 1300: if ($localecmd ne '') {
1301: 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";
1302: 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".
1303: $localecmd."\n\n".
1304: &mt('Stopping execution.')."\n";
1305: exit;
1306: }
1.1 raeburn 1307: if (!$gotprereqs) {
1.12 raeburn 1308: print "\n".&mt('The LONCAPA-prerequisites package is not installed.')."\n".
1.1 raeburn 1309: &mt('The following command can be used to install the package (and dependencies):')."\n\n".
1310: $updatecmd."\n\n";
1311: if ($installnow eq '') {
1312: print &mt('Stopping execution.')."\n";
1313: exit;
1314: } else {
1315: print &mt('Run command? ~[Y/n~]');
1316: my $install_prereq = &get_user_selection(1);
1317: if ($install_prereq) {
1318: if (open(PIPE,'|-',$installnow)) {
1319: close(PIPE);
1320: $gotprereqs = &check_prerequisites($packagecmd,$distro);
1321: if (!$gotprereqs) {
1.12 raeburn 1322: print &mt('The LONCAPA-prerequisites package is not installed.')."\n".
1.1 raeburn 1323: &mt('Stopping execution.')."\n";
1324: exit;
1325: } else {
1.6 raeburn 1326: ($distro,$gotprereqs,$localecmd,$packagecmd,$updatecmd,$installnow,
1.34 raeburn 1327: $mysqlrestart,$recommended,$dbh,$has_pass,$has_lcdb,$downloadstatus,
1.35 raeburn 1328: $filetouse,$production,$testing,$apachefw,$uses_systemctl) =
1.5 raeburn 1329: &check_required($instdir,$dsn);
1.1 raeburn 1330: }
1331: } else {
1.12 raeburn 1332: print &mt('Failed to run command to install LONCAPA-prerequisites')."\n";
1.1 raeburn 1333: exit;
1334: }
1335: } else {
1336: print &mt('Stopping execution.')."\n";
1337: exit;
1338: }
1339: }
1340: }
1341: unless (ref($recommended) eq 'HASH') {
1342: print "\n".&mt('An error occurred determining which actions are recommended.')."\n\n".
1343: &mt('Stopping execution.')."\n";
1344: exit;
1345: }
1346:
1347: print "\n";
1348: my $num = 0;
1349: foreach my $action (@actions) {
1350: $num ++;
1351: my ($yesno,$defaultrun);
1352: if (ref($recommended) eq 'HASH') {
1.4 raeburn 1353: if (($action eq 'runlevels') || ($action eq 'stopsrvcs')) {
1.1 raeburn 1354: $yesno = '[y/N]';
1355: if (ref($recommended->{$action}) eq 'HASH') {
1356: if (keys(%{$recommended->{$action}}) > 0) {
1357: $yesno = &mt('~[Y/n~]');
1358: $defaultrun = 1;
1359: }
1360: }
1361: } else {
1362: if ($action eq 'download') {
1363: if ($downloadstatus) {
1364: print "\n$downloadstatus\n";
1365: }
1366: }
1367: if ($recommended->{$action}) {
1368: $yesno = mt('~[Y/n~]');
1369: $defaultrun = 1;
1370: } else {
1371: $yesno = &mt('~[y/N~]');
1372: }
1373: }
1374: print $num.'. '.$prompts{$action}." $yesno ";
1375: $callsub{$action} = &get_user_selection($defaultrun);
1376: }
1377: }
1378:
1379: my $lctarball = 'loncapa-current.tar.gz';
1380: my $sourcetarball = $lctarball;
1381: if ($callsub{'download'}) {
1382: my ($production,$testing,$sizes) = &download_versionslist();
1383: if ($production && $testing) {
1384: if ($production ne $testing) {
1385: print &mt('Two recent LON-CAPA releases are available: ')."\n".
1.3 raeburn 1386: &mt('1.').' '.&mt('A production release - version: [_1].',$production)."\n".
1387: &mt('2.').' '.&mt('A testing release - version: [_1].',$testing)."\n\n".
1.1 raeburn 1388: &mt('Download the production release? ~[Y/n~]');
1389: if (&get_user_selection(1)) {
1.4 raeburn 1390: $sourcetarball = 'loncapa-'.$production.'.tar.gz';
1.1 raeburn 1391: } else {
1392: print "\n".&mt('Download the testing release? ~[Y/n~]');
1393: if (&get_user_selection(1)) {
1.4 raeburn 1394: $sourcetarball = 'loncapa-'.$testing.'.tar.gz';
1.1 raeburn 1395: }
1396: }
1397: }
1398: } elsif ($production) {
1399: print &mt('The most recent LON-CAPA release is version: [_1].',$production)."\n".
1400: &mt('Download the production release? ~[Y/n~]');
1401: if (&get_user_selection(1)) {
1.20 raeburn 1402: $sourcetarball = 'loncapa-'.$production.'.tar.gz';
1.1 raeburn 1403: }
1404: }
1405: } elsif ($filetouse ne '') {
1406: $sourcetarball = $filetouse;
1407: }
1408:
1409: print_and_log("\n");
1410:
1411: # Each action: report if skipping, or perform action and provide feedback.
1412: if ($callsub{'wwwuser'}) {
1413: &setup_www();
1414: } else {
1415: &print_and_log(&mt('Skipping creation of user [_1].',"'www'")."\n");
1416: }
1417:
1418: if ($callsub{'pwauth'}) {
1.4 raeburn 1419: &build_and_install_mod_auth_external($instdir);
1.1 raeburn 1420: } else {
1421: &print_and_log(&mt('Skipping [_1] installation.',"'pwauth'")."\n");
1422: }
1423:
1424: if ($callsub{'mysql'}) {
1425: if ($dbh) {
1426: &setup_mysql($callsub{'mysqlperms'},$distro,$dbh,$has_pass,$has_lcdb);
1427: } else {
1428: print &mt('Unable to configure MySQL because access is denied.')."\n";
1429: }
1430: } else {
1431: &print_and_log(&mt('Skipping configuration of MySQL.')."\n");
1432: if ($callsub{'mysqlperms'}) {
1433: if ($dbh) {
1434: &setup_mysql_permissions($dbh,$has_pass);
1435: } else {
1436: print &mt('Unable to configure MySQL because access is denied.')."\n";
1437: }
1438: } else {
1439: &print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
1440: }
1441: }
1442:
1443: if ($dbh) {
1444: if (!$dbh->disconnect) {
1445: &print_and_log(&mt('Failed to disconnect from MySQL:')."\n".
1446: $dbh->errstr);
1447: }
1448: }
1449:
1450: if ($callsub{'apache'}) {
1451: if ($distro =~ /^(suse|sles)/) {
1452: ©_apache2_suseconf($instdir);
1453: } elsif ($distro =~ /^(debian|ubuntu)/) {
1.28 raeburn 1454: ©_apache2_debconf($instdir,$distro);
1.1 raeburn 1455: } else {
1.14 raeburn 1456: ©_httpd_conf($instdir,$distro);
1.1 raeburn 1457: }
1458: } else {
1459: print_and_log(&mt('Skipping configuration of Apache web server.')."\n");
1460: }
1461:
1462: if ($callsub{'runlevels'}) {
1463: my $count = 0;
1464: if (ref($recommended) eq 'HASH') {
1465: if (ref($recommended->{'runlevels'}) eq 'HASH') {
1466: foreach my $type (keys(%{$recommended->{'runlevels'}})) {
1467: next if ($type eq 'insserv');
1468: $count ++;
1469: my $command = $recommended->{'runlevels'}{$type};
1470: if ($command ne '') {
1471: print_and_log(&mt('Runlevel update command run: [_1].',$command)."\n");
1472: system($command);
1473: }
1474: }
1475: if (!$count) {
1476: print_and_log(&mt('No runlevel updates required.')."\n");
1477: }
1478: }
1479: }
1.11 raeburn 1480: if ($distro =~ /^(suse|sles)/) {
1481: &update_SuSEfirewall2_setup($instdir);
1482: }
1.1 raeburn 1483: } else {
1484: &print_and_log(&mt('Skipping setting override for start-up order of services.')."\n");
1485: }
1486:
1487: if ($callsub{'firewall'}) {
1488: if ($distro =~ /^(suse|sles)/) {
1.5 raeburn 1489: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1490: 'yast -- Security and Users -> Firewall -> Interfaces',
1491: 'ssh, http, https')."\n";
1492: } elsif ($distro =~ /^(debian|ubuntu)(\d+)/) {
1493: if (($1 eq 'ubuntu') || ($2 > 5)) {
1494: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1495: 'ufw','ssh, http, https')."\n";
1496: } else {
1497: my $fwadded = &get_iptables_rules($distro,$instdir,$apachefw);
1498: if ($fwadded) {
1499: print &mt('Enable firewall? ~[Y/n~]');
1500: my $enable_iptables = &get_user_selection(1);
1501: if ($enable_iptables) {
1502: system('/etc/network/if-pre-up.d/iptables');
1503: print &mt('Firewall enabled using rules defined in [_1].',
1504: '/etc/iptables.loncapa.rules');
1505: }
1506: }
1507: }
1.11 raeburn 1508: } elsif ($distro =~ /^scientific/) {
1509: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1510: 'system-config-firewall-tui -- Customize',
1511: 'ssh, http')."\n";
1.1 raeburn 1512: } else {
1.5 raeburn 1513: print &mt('Use [_1] to configure the firewall to allow access for [_2].',
1.11 raeburn 1514: 'setup -- Firewall configuration -> Customize',
1.5 raeburn 1515: 'ssh, http, https')."\n";
1.1 raeburn 1516: }
1517: } else {
1.5 raeburn 1518: &print_and_log(&mt('Skipping Firewall configuration.')."\n");
1.1 raeburn 1519: }
1520:
1521: if ($callsub{'stopsrvcs'}) {
1522: &kill_extra_services($distro,$recommended->{'stopsrvcs'});
1523: } else {
1.10 raeburn 1524: &print_and_log(&mt('Skipping stopping unnecessary service ([_1] daemons).',"'cups','memcached'")."\n");
1.1 raeburn 1525: }
1526:
1527: my ($have_tarball,$updateshown);
1528: if ($callsub{'download'}) {
1529: ($have_tarball,$updateshown) = &download_loncapa($instdir,$sourcetarball);
1530: } else {
1531: print_and_log(&mt('Skipping download of LON-CAPA tar file.')."\n\n");
1532: print &mt('LON-CAPA is available for download from: [_1]',
1533: 'http://install.loncapa.org/')."\n";
1534: if (!-e '/etc/loncapa-release') {
1535: &print_and_log(&mt('LON-CAPA is not yet installed on your system.').
1536: "\n\n".
1537: &mt('You may retrieve the source for LON-CAPA by executing:')."\n".
1538: "wget http://install.loncapa.org/versions/$lctarball\n");
1539: } else {
1540: my $currentversion;
1541: if (open(my $fh,"</etc/loncapa-release")) {
1542: my $version = <$fh>;
1543: chomp($version);
1544: if ($version =~ /^\QLON-CAPA release \E([\w\-.]+)$/) {
1545: $currentversion = $1;
1546: }
1547: }
1548: if ($currentversion ne '') {
1549: print &mt('Version of LON-CAPA currently installed on this server is: [_1].',
1550: $currentversion),"\n";
1551: if ($production) {
1552: print &mt('The latest production release of LON-CAPA is [_1].',$production)."\n";
1553: }
1554: if ($testing) {
1555: print &mt('The latest testing release of LON-CAPA is [_1].',$testing)."\n";
1556: }
1557: }
1558: }
1559: if ($filetouse ne '') {
1560: $have_tarball = 1;
1561: }
1562: }
1563:
1564: print "\n".&mt('Requested configuration complete.')."\n\n";
1565: my $apachename;
1566: if ($have_tarball && !$updateshown) {
1567: my ($lcdir) = ($sourcetarball =~ /^([\w.\-]+)\.tar.gz$/);
1568: if (!-e '/etc/loncapa-release') {
1569: print &mt('If you are now ready to install LON-CAPA, enter the following commands:')."\n\n";
1570: } else {
1571: print &mt('If you are now ready to update LON-CAPA, enter the following commands:')."\n\n".
1572: "/etc/init.d/loncontrol stop\n";
1573: if ($distro =~ /^(suse|sles|debian|ubuntu)([\d.]+)/) {
1574: if (($1 eq 'suse') && ($2 < 10)) {
1575: $apachename = 'apache';
1576: } else {
1577: $apachename = 'apache2';
1578: }
1579: } else {
1580: $apachename = 'httpd';
1581: }
1582: print "/etc/init.d/$apachename stop\n";
1583: }
1584: print "cd /root\n".
1585: "tar zxf $sourcetarball\n".
1586: "cd $lcdir\n".
1587: "./UPDATE\n";
1588: if (-e '/etc/loncapa-release') {
1589: print "/etc/init.d/loncontrol start\n";
1590: print "/etc/init.d/$apachename start\n";
1591: }
1592: }
1593: exit;
1594:
1595: #
1596: # End main script
1597: #
1598:
1599: #
1600: # Routines for the actions
1601: #
1602:
1603: sub setup_www {
1604: ##
1605: ## Set up www
1606: ##
1607: print_and_log(&mt('Creating user [_1]',"'www'")."\n");
1608: # -- Add group
1609:
1610: my $status = `/usr/sbin/groupadd www`;
1611: if ($status =~ /\QGroup `www' already exists.\E/) {
1612: print &mt('Group [_1] already exists.',"'www'")."\n";
1613: } elsif ($status ne '') {
1614: print &mt('Unable to add group [_1].',"'www'")."\n";
1615: }
1616:
1617: my $gid = getgrnam('www');
1618:
1619: if (open (PIPE, "/usr/sbin/useradd -c LONCAPA -g $gid www 2>&1 |")) {
1620: $status = <PIPE>;
1621: close(PIPE);
1622: chomp($status);
1623: if ($status =~ /\QAccount `www' already exists.\E/) {
1624: print &mt('Account [_1] already exists.',"'www'")."\n";
1625: } elsif ($status ne '') {
1626: print &mt('Unable to add user [_1].',"'www'")."\n";
1627: }
1628: } else {
1629: print &mt('Unable to run command to add user [_1].',"'www'")."\n";
1630: }
1631:
1632: my $uid = &uid_of_www();
1633: if (($gid ne '') && ($uid ne '')) {
1634: if (!-e '/home/www') {
1635: mkdir('/home/www',0755);
1636: system('chown www:www /home/www');
1637: }
1638: }
1639: writelog ($status);
1640: }
1641:
1642: sub uid_of_www {
1643: my ($num) = (getpwnam('www'))[2];
1644: return $num;
1645: }
1646:
1647: sub build_and_install_mod_auth_external {
1648: my ($instdir) = @_;
1649: my $num = &uid_of_www();
1650: # Patch pwauth
1651: print_and_log(&mt('Building authentication system for LON-CAPA users.')."\n");
1652: my $patch = <<"ENDPATCH";
1653: 148c148
1654: < #define SERVER_UIDS 99 /* user "nobody" */
1655: ---
1656: > #define SERVER_UIDS $num /* user "www" */
1657: ENDPATCH
1658:
1659: if (! -e "/usr/bin/patch") {
1660: print_and_log(&mt('You must install the software development tools package: [_1], when installing Linux.',"'patch'")."\n");
1661: print_and_log(&mt('Authentication installation not completed.')."\n");
1662: return;
1663: }
1664: if (&skip_if_nonempty(`cd /tmp; tar zxf $instdir/pwauth-2.2.8.tar.gz`,
1665: &mt('Unable to extract pwauth')."\n")) {
1666: return;
1667: }
1668: my $dir = "/tmp/pwauth-2.2.8";
1669: if (open(PATCH,"| patch $dir/config.h")) {
1670: print PATCH $patch;
1671: close(PATCH);
1672: print_and_log("\n");
1673: ##
1674: ## Compile patched pwauth
1675: ##
1676: print_and_log(&mt('Compiling pwauth')."\n");
1.12 raeburn 1677: my $result = `cd $dir/; make 2>/dev/null `;
1.1 raeburn 1678: my $expected = <<"END";
1679: gcc -g -c -o pwauth.o pwauth.c
1680: gcc -o pwauth -g pwauth.o -lcrypt
1681: END
1682: if ($result eq $expected) {
1683: print_and_log(&mt('Apparent success compiling pwauth:').
1684: "\n".$result );
1685: # Install patched pwauth
1686: print_and_log(&mt('Copying pwauth to [_1]',' /usr/local/sbin')."\n");
1687: if (copy "$dir/pwauth","/usr/local/sbin/pwauth") {
1.5 raeburn 1688: if (chmod(06755, "/usr/local/sbin/pwauth")) {
1.1 raeburn 1689: print_and_log(&mt('[_1] copied successfully',"'pwauth'").
1690: "\n");
1691: } else {
1692: print &mt('Unable to set permissions on [_1].'.
1693: "/usr/local/sbin/pwauth")."\n";
1694: }
1695: } else {
1696: print &mt('Unable to copy [_1] to [_2]',
1697: "'$dir/pwauth'","/usr/local/sbin/pwauth")."\n$!\n";
1698: }
1699: } else {
1700: print &mt('Unable to compile patched [_1].'."'pwauth'")."\n";
1701: }
1702: } else {
1703: print &mt('Unable to start patch for [_1]',"'pwauth'")."\n";
1704: }
1705: print_and_log("\n");
1706: }
1707:
1708: sub kill_extra_services {
1709: my ($distro,$stopsrvcs) = @_;
1710: if (ref($stopsrvcs) eq 'HASH') {
1711: my @stopping = sort(keys(%{$stopsrvcs}));
1712: if (@stopping) {
1.6 raeburn 1713: my $kill_list = join("', '",@stopping);
1.1 raeburn 1714: if ($kill_list) {
1715: $kill_list = "'".$kill_list."'";
1.6 raeburn 1716: &print_and_log("\n".&mt('Killing unnecessary services ([_1] daemon(s)).',$kill_list)."\n");
1717: foreach my $service (@stopping) {
1718: my $daemon = $service;
1719: if ($service eq 'cups') {
1720: $daemon = 'cupsd';
1721: if ($distro =~ /^(?:debian|ubuntu)(\d+)/) {
1722: my $version = $1;
1723: if (($distro =~ /^ubuntu/) && ($version <= 8)) {
1724: $daemon = 'cupsys';
1725: }
1.12 raeburn 1726: } else {
1.8 raeburn 1727: $daemon = 'cups';
1.6 raeburn 1728: }
1729: }
1.12 raeburn 1730: my $cmd = "ps -ef |grep '$daemon' |grep -v grep";
1731: if (open(PIPE,'-|',$cmd)) {
1732: my $daemonrunning = <PIPE>;
1733: chomp($daemonrunning);
1734: close(PIPE);
1735: if ($daemonrunning) {
1736: &print_and_log(`/etc/init.d/$daemon stop`);
1737: }
1738: }
1.1 raeburn 1739: &print_and_log(&mt('Removing [_1] from startup.',$service)."\n");
1.4 raeburn 1740: if ($distro =~ /^(debian|ubuntu)/) {
1.6 raeburn 1741: &print_and_log(`update-rc.d -f $daemon remove`);
1.1 raeburn 1742: } else {
1.35 raeburn 1743: if (ref($uses_systemctl) eq 'HASH') {
1744: if ($uses_systemctl->{$service}) {
1745: if (`systemctl is-enabled $service`) {
1746: &print_and_log(`systemctl disable $service`);
1747: }
1748: } else {
1749: &print_and_log(`/sbin/chkconfig --del $service`);
1750: }
1751: } else {
1752: &print_and_log(`/sbin/chkconfig --del $service`);
1753: }
1.1 raeburn 1754: }
1755: }
1756: }
1757: }
1758: }
1759: return;
1760: }
1761:
1762: sub setup_mysql {
1763: my ($setup_mysql_permissions,$distro,$dbh,$has_pass,$has_lcdb) = @_;
1.4 raeburn 1764: my @mysql_lc_commands;
1.1 raeburn 1765: unless ($has_lcdb) {
1.4 raeburn 1766: push(@mysql_lc_commands,"CREATE DATABASE loncapa");
1.1 raeburn 1767: }
1.4 raeburn 1768: push(@mysql_lc_commands,"USE loncapa");
1769: push(@mysql_lc_commands,qq{
1.18 raeburn 1770: 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 1771: });
1.1 raeburn 1772: if ($setup_mysql_permissions) {
1.4 raeburn 1773: &setup_mysql_permissions($dbh,$has_pass,@mysql_lc_commands);
1.1 raeburn 1774: } else {
1775: print_and_log(&mt('Skipping MySQL permissions setup.')."\n");
1776: if ($dbh) {
1.4 raeburn 1777: if (@mysql_lc_commands) {
1778: foreach my $lccmd (@mysql_lc_commands) {
1779: $dbh->do($lccmd) || print $dbh->errstr."\n";
1780: }
1781: }
1.1 raeburn 1782: print_and_log(&mt('MySQL database set up complete.')."\n");
1783: } else {
1784: print_and_log(&mt('Problem accessing MySQL.')."\n");
1785: }
1786: }
1787: }
1788:
1789: sub setup_mysql_permissions {
1.4 raeburn 1790: my ($dbh,$has_pass,@mysql_lc_commands) = @_;
1.38 raeburn 1791: my ($mysqlversion,$mysqlsubver,$mysqlname) = &get_mysql_version();
1.42 ! raeburn 1792: my ($usesauth,$hasauthcol,@mysql_commands);
1.38 raeburn 1793: if ($mysqlname =~ /^MariaDB/i) {
1794: if ($mysqlversion >= 10.2) {
1795: $usesauth = 1;
1.42 ! raeburn 1796: } elsif ($mysqlversion >= 5.5) {
! 1797: $hasauthcol = 1;
1.38 raeburn 1798: }
1799: } else {
1800: if (($mysqlversion > 5.7) || (($mysqlversion == 5.7) && ($mysqlsubver > 5))) {
1801: $usesauth = 1;
1.42 ! raeburn 1802: } elsif (($mysqlversion >= 5.6) || (($mysqlversion == 5.5) && ($mysqlsubver >= 7))) {
! 1803: $hasauthcol = 1;
1.38 raeburn 1804: }
1805: }
1806: if ($usesauth) {
1.36 raeburn 1807: @mysql_commands = ("INSERT user (Host, User, ssl_cipher, x509_issuer, x509_subject) VALUES('localhost','www','','','')",
1.38 raeburn 1808: "ALTER USER 'www'\@'localhost' IDENTIFIED BY 'localhostkey'");
1.42 ! raeburn 1809: } elsif ($hasauthcol) {
! 1810: @mysql_commands = ("INSERT user (Host, User, Password, ssl_cipher, x509_issuer, x509_subject, authentication_string) VALUES('localhost','www',password('localhostkey'),'','','','');");
1.36 raeburn 1811: } else {
1.42 ! raeburn 1812: @mysql_commands = ("INSERT user (Host, User, Password, ssl_cipher, x509_issuer, x509_subject) VALUES('localhost','www',password('localhostkey'),'','','');");
1.36 raeburn 1813: }
1.1 raeburn 1814: if ($mysqlversion < 4) {
1.4 raeburn 1815: push (@mysql_commands,"
1816: 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')");
1817: } else {
1818: push (@mysql_commands,"
1819: 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 1820: }
1.4 raeburn 1821: push(@mysql_commands,"DELETE FROM user WHERE host<>'localhost'");
1.1 raeburn 1822: if ($has_pass) {
1823: if ($dbh) {
1.4 raeburn 1824: push(@mysql_commands,"FLUSH PRIVILEGES");
1825: if (@mysql_commands) {
1826: foreach my $cmd (@mysql_commands) {
1827: $dbh->do($cmd) || print $dbh->errstr."\n";
1828: }
1829: }
1830: if (@mysql_lc_commands) {
1831: foreach my $lccmd (@mysql_lc_commands) {
1832: $dbh->do($lccmd) || print $dbh->errstr."\n";
1833: }
1834: }
1.1 raeburn 1835: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1]',"'www'")."\n");
1836: } else {
1837: print_and_log(&mt('Problem accessing MySQL.')."\n".
1838: &mt('Permissions not set.')."\n");
1839: }
1840: } else {
1841: my ($firstpass,$secondpass,$got_passwd,$newmysqlpass);
1842: print &mt('Please enter a root password for the mysql database.')."\n".
1843: &mt('It does not have to match your root account password, but you will need to remember it.')."\n";
1844: my $maxtries = 10;
1845: my $trial = 0;
1846: while ((!$got_passwd) && ($trial < $maxtries)) {
1847: $firstpass = &get_mysql_password(&mt('Enter password'));
1848: if (length($firstpass) > 5) {
1849: $secondpass = &get_mysql_password(&mt('Enter password a second time'));
1850: if ($firstpass eq $secondpass) {
1851: $got_passwd = 1;
1852: $newmysqlpass = $firstpass;
1853: } else {
1854: print(&mt('Passwords did not match. Please try again.')."\n");
1855: }
1856: $trial ++;
1857: } else {
1858: print(&mt('Password too short.')."\n".
1859: &mt('Please choose a password with at least six characters.')."\n");
1860: }
1861: }
1862: if ($got_passwd) {
1.4 raeburn 1863: my (@newpass_cmds) = &new_mysql_rootpasswd($newmysqlpass);
1864: push(@mysql_commands,@newpass_cmds);
1.1 raeburn 1865: } else {
1866: print_and_log(&mt('Failed to get MySQL root password from user input.')."\n");
1867: }
1868: if ($dbh) {
1.4 raeburn 1869: if (@mysql_commands) {
1870: foreach my $cmd (@mysql_commands) {
1871: $dbh->do($cmd) || print $dbh->errstr."\n";
1872:
1873: }
1874: }
1875: if (@mysql_lc_commands) {
1876: foreach my $lccmd (@mysql_lc_commands) {
1877: $dbh->do($lccmd) || print $dbh->errstr."\n";
1878: }
1879: }
1.1 raeburn 1880: if ($got_passwd) {
1881: print_and_log(&mt('MySQL root password stored.')."\n".
1882: &mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
1883: } else {
1884: print_and_log(&mt('Permissions set for LON-CAPA MySQL user: [_1].',"'www'")."\n");
1885: }
1886: } else {
1887: print_and_log(&mt('Problem accessing MySQL.')."\n".
1888: &mt('Permissions not set.')."\n");
1889: }
1890: }
1891: }
1892:
1893: sub new_mysql_rootpasswd {
1.36 raeburn 1894: my ($currmysqlpass,$usesauth) = @_;
1895: if ($usesauth) {
1896: return ("ALTER USER 'root'\@'localhost' IDENTIFIED BY '$currmysqlpass'",
1897: "FLUSH PRIVILEGES;");
1898: } else {
1899: return ("SET PASSWORD FOR 'root'\@'localhost'=PASSWORD('$currmysqlpass')",
1900: "FLUSH PRIVILEGES;");
1901: }
1.1 raeburn 1902: }
1903:
1904: sub get_mysql_version {
1.38 raeburn 1905: my ($version,$subversion,$name);
1.1 raeburn 1906: if (open(PIPE," mysql -V |")) {
1907: my $info = <PIPE>;
1908: chomp($info);
1909: close(PIPE);
1.38 raeburn 1910: ($version,$subversion,$name) = ($info =~ /(\d+\.\d+)\.(\d+)\-?(\w*),/);
1.1 raeburn 1911: } else {
1912: print &mt('Could not determine which version of MySQL is installed.').
1913: "\n";
1914: }
1.38 raeburn 1915: return ($version,$subversion,$name);
1.1 raeburn 1916: }
1917:
1918: ###########################################################
1919: ##
1920: ## RHEL/CentOS/Fedora/Scientific Linux
1921: ## Copy LON-CAPA httpd.conf to /etc/httpd/conf
1922: ##
1923: ###########################################################
1924:
1925: sub copy_httpd_conf {
1.14 raeburn 1926: my ($instdir,$distro) = @_;
1927: my $configfile = 'httpd.conf';
1928: if ($distro =~ /^(?:centos|rhes|scientific)(\d+)$/) {
1.29 raeburn 1929: if ($1 >= 7) {
1930: $configfile = 'apache2.4/httpd.conf';
1931: } elsif ($1 > 5) {
1.14 raeburn 1932: $configfile = 'new/httpd.conf';
1933: }
1934: } elsif ($distro =~ /^fedora(\d+)$/) {
1.29 raeburn 1935: if ($1 > 17) {
1936: $configfile = 'apache2.4/httpd.conf';
1937: } elsif ($1 > 10) {
1.14 raeburn 1938: $configfile = 'new/httpd.conf';
1939: }
1940: }
1.1 raeburn 1941: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'httpd.conf'",
1942: "'/etc/httpd/conf/httpd.conf'")."\n");
1943: copy "/etc/httpd/conf/httpd.conf","/etc/httpd/conf/httpd.conf.original";
1.14 raeburn 1944: copy "$instdir/centos-rhes-fedora-sl/$configfile","/etc/httpd/conf/httpd.conf";
1.5 raeburn 1945: chmod(0444,"/etc/httpd/conf/httpd.conf");
1.1 raeburn 1946: print_and_log("\n");
1947: }
1948:
1949: #########################################################
1950: ##
1.17 raeburn 1951: ## Ubuntu/Debian -- copy our loncapa configuration file to
1.1 raeburn 1952: ## sites-available and set the symlink from sites-enabled.
1953: ##
1954: #########################################################
1955:
1956: sub copy_apache2_debconf {
1.28 raeburn 1957: my ($instdir,$distro) = @_;
1.6 raeburn 1958: my $apache2_mods_enabled_dir = '/etc/apache2/mods-enabled';
1959: my $apache2_mods_available_dir = '/etc/apache2/mods-available';
1960: foreach my $module ('headers.load','expires.load') {
1961: unless (-l "$apache2_mods_enabled_dir/$module") {
1962: symlink("$apache2_mods_available_dir/$module","$apache2_mods_enabled_dir/$module");
1963: print_and_log(&mt('Enabling "[_1]" Apache module.',$module)."\n");
1964: }
1965: }
1.28 raeburn 1966: my $apache2_sites_enabled_dir = '/etc/apache2/sites-enabled';
1967: my $apache2_sites_available_dir = '/etc/apache2/sites-available';
1968: my $defaultconfig = "$apache2_sites_enabled_dir/000-default";
1969: my ($distname,$version);
1970: if ($distro =~ /^(debian|ubuntu)(\d+)$/) {
1971: $distname = $1;
1972: $version = $2;
1973: }
1974: if (($distname eq 'ubuntu') && ($version > 12)) {
1975: $defaultconfig = "$apache2_sites_enabled_dir/000-default.conf";
1976: }
1977: if (-l $defaultconfig) {
1978: unlink($defaultconfig);
1979: }
1980: if (($distname eq 'ubuntu') && ($version > 12)) {
1.32 raeburn 1981: 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 1982: my $apache2_conf_enabled_dir = '/etc/apache2/conf-enabled';
1983: my $apache2_conf_available_dir = '/etc/apache2/conf-available';
1984: if (-e "$apache2_conf_available_dir/loncapa") {
1985: copy("$apache2_conf_available_dir/loncapa","$apache2_conf_available_dir/loncapa.original");
1986: }
1.33 raeburn 1987: my $defaultconf = $apache2_conf_enabled_dir.'/loncapa.conf';
1.32 raeburn 1988: copy("$instdir/debian-ubuntu/ubuntu14/loncapa_conf","$apache2_conf_available_dir/loncapa");
1.28 raeburn 1989: chmod(0444,"$apache2_conf_available_dir/loncapa");
1.32 raeburn 1990: if (-l $defaultconf) {
1991: unlink($defaultconf);
1992: }
1993: symlink("$apache2_conf_available_dir/loncapa","$defaultconf");
1994: 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");
1995: copy("$instdir/debian-ubuntu/ubuntu14/loncapa_site","$apache2_sites_available_dir/loncapa");
1996: chmod(0444,"$apache2_sites_available_dir/loncapa");
1997: symlink("$apache2_sites_available_dir/loncapa","$defaultconfig");
1.28 raeburn 1998: } else {
1999: 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");
2000: if (-e "$apache2_sites_available_dir/loncapa") {
2001: copy("$apache2_sites_available_dir/loncapa","$apache2_sites_available_dir/loncapa.original");
2002: }
2003: copy("$instdir/debian-ubuntu/loncapa","$apache2_sites_available_dir/loncapa");
2004: chmod(0444,"$apache2_sites_available_dir/loncapa");
2005: symlink("$apache2_sites_available_dir/loncapa","$apache2_sites_enabled_dir/000-default");
2006: }
1.1 raeburn 2007: print_and_log("\n");
2008: }
2009:
2010: ###########################################################
2011: ##
2012: ## openSuSE/SLES Copy apache2 config files:
2013: ## default-server.conf, uid.conf, /etc/sysconfig/apache2
2014: ## and create symlink from /srv/www/conf to /etc/apache2
2015: ##
2016: ###########################################################
2017:
2018: sub copy_apache2_suseconf {
2019: my ($instdir) = @_;
2020: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
2021: "'default-server.conf'",
2022: "'/etc/apache2/default-server.conf'")."\n");
2023: if (!-e "/etc/apache2/default-server.conf.original") {
2024: copy "/etc/apache2/default-server.conf","/etc/apache2/default-server.conf.original";
2025: }
1.9 raeburn 2026: copy "$instdir/sles-suse/default-server.conf","/etc/apache2/default-server.conf";
1.5 raeburn 2027: chmod(0444,"/etc/apache2/default-server.conf");
1.1 raeburn 2028: # Make symlink for conf directory (included in loncapa_apache.conf)
2029: my $can_symlink = (eval { symlink('/etc/apache2','/srv/www/conf'); }, $@ eq '');
2030: if ($can_symlink) {
2031: &print_and_log(&mt('Symlink created for [_1] to [_2].',
2032: "'/srv/www/conf'","'/etc/apache2'")."\n");
2033: } else {
2034: &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");
2035: }
2036: ©_apache2_conf_files($instdir);
2037: ©_sysconfig_apache2_file($instdir);
2038: print_and_log("\n");
2039: }
2040:
2041: ###############################################
2042: ##
2043: ## Modify uid.conf
2044: ##
2045: ###############################################
2046: sub copy_apache2_conf_files {
2047: my ($instdir) = @_;
2048: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',
2049: "'uid.conf'","'/etc/apache2/uid.conf'")."\n");
2050: if (!-e "/etc/apache2/uid.conf.original") {
2051: copy "/etc/apache2/uid.conf","/etc/apache2/uid.conf.original";
2052: }
1.9 raeburn 2053: copy "$instdir/sles-suse/uid.conf","/etc/apache2/uid.conf";
1.5 raeburn 2054: chmod(0444,"/etc/apache2/uid.conf");
1.1 raeburn 2055: }
2056:
2057: ###############################################
2058: ##
2059: ## Modify /etc/sysconfig/apache2
2060: ##
2061: ###############################################
2062: sub copy_sysconfig_apache2_file {
2063: my ($instdir) = @_;
2064: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'sysconfig/apache2'","'/etc/sysconfig/apache2'")."\n");
2065: if (!-e "/etc/sysconfig/apache2.original") {
2066: copy "/etc/sysconfig/apache2","/etc/sysconfig/apache2.original";
2067: }
1.9 raeburn 2068: copy "$instdir/sles-suse/sysconfig_apache2","/etc/sysconfig/apache2";
1.5 raeburn 2069: chmod(0444,"/etc/sysconfig/apache2");
1.1 raeburn 2070: }
2071:
2072: ###############################################
2073: ##
2074: ## Add/Modify /etc/insserv/overrides
2075: ##
2076: ###############################################
2077:
2078: sub update_SuSEfirewall2_setup {
2079: my ($instdir) = @_;
2080: print_and_log(&mt('Copying the LON-CAPA [_1] to [_2].',"'SuSEfirewall2_setup'","'/etc/insserv/overrides/SuSEfirewall2_setup'")."\n");
2081: if (!-e "/etc/insserv/overrides/SuSEfirewall2_setup") {
2082: if (!-d "/etc/insserv") {
2083: mkdir("/etc/insserv",0755);
2084: }
2085: if (!-d "/etc/insserv/overrides") {
2086: mkdir("/etc/insserv/overrides",0755);
2087: }
2088: } elsif (!-e "/etc/insserv/overrides/SuSEfirewall2_setup.original") {
2089: copy "/etc/insserv/overrides/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup.original"
2090: }
1.9 raeburn 2091: copy "$instdir/sles-suse/SuSEfirewall2_setup","/etc/insserv/overrides/SuSEfirewall2_setup";
1.5 raeburn 2092: chmod(0444,"/etc/insserv/overrides/SuSEfirewall2_setup");
2093: }
2094:
2095: sub get_iptables_rules {
2096: my ($distro,$instdir,$apachefw) = @_;
2097: my (@fwchains,@ports);
2098: if (&firewall_is_active()) {
2099: my $iptables = &get_pathto_iptables();
2100: if ($iptables ne '') {
2101: @fwchains = &get_fw_chains($iptables,$distro);
2102: }
2103: }
2104: if (ref($apachefw) eq 'HASH') {
2105: foreach my $service ('http','https') {
2106: unless ($apachefw->{$service}) {
2107: push (@ports,$service);
2108: }
2109: }
2110: } else {
2111: @ports = ('http','https');
2112: }
2113: if (@ports == 0) {
2114: return;
2115: }
2116: my $ask_to_enable;
2117: if (-e "/etc/iptables.loncapa.rules") {
1.9 raeburn 2118: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables.loncapa.rules /etc/iptables.loncapa.rules |")) {
1.5 raeburn 2119: my $diffres = <PIPE>;
2120: close(PIPE);
2121: chomp($diffres);
2122: if ($diffres) {
2123: print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
2124: }
2125: } else {
2126: print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/iptables.loncapa.rules')."\n";
2127: }
2128: } else {
1.9 raeburn 2129: if (-e "$instdir/debian-ubuntu/iptables.loncapa.rules") {
2130: copy "$instdir/debian-ubuntu/iptables.loncapa.rules","/etc/iptables.loncapa.rules";
1.5 raeburn 2131: chmod(0600,"/etc/iptables.loncapa.rules");
2132: }
2133: }
2134: if (-e "/etc/iptables.loncapa.rules") {
2135: if (-e "/etc/network/if-pre-up.d/iptables") {
1.9 raeburn 2136: if (open(PIPE, "diff --brief $instdir/debian-ubuntu/iptables /etc/network/if-pre-up/iptables |")) {
1.5 raeburn 2137: my $diffres = <PIPE>;
2138: close(PIPE);
2139: chomp($diffres);
2140: if ($diffres) {
2141: print &mt('Warning: [_1] exists but differs from LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
2142: }
2143: } else {
2144: print &mt('Error: unable to open [_1] to compare contents with LON-CAPA supplied file.','/etc/network/if-pre-up.d/iptables')."\n";
2145: }
2146: } else {
1.9 raeburn 2147: copy "$instdir/debian-ubuntu/iptables","/etc/network/if-pre-up.d/iptables";
1.5 raeburn 2148: chmod(0755,"/etc/network/if-pre-up.d/iptables");
2149: 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'));
2150: $ask_to_enable = 1;
2151: }
2152: }
2153: return $ask_to_enable;
1.1 raeburn 2154: }
2155:
2156: sub download_loncapa {
2157: my ($instdir,$lctarball) = @_;
2158: my ($have_tarball,$updateshown);
2159: if (! -e "$instdir/$lctarball") {
2160: print_and_log(&mt('Retrieving LON-CAPA source files from: [_1]',
2161: 'http://install.loncapa.org')."\n");
2162: system("wget http://install.loncapa.org/versions/$lctarball ".
2163: "2>/dev/null 1>/dev/null");
2164: if (! -e "./$lctarball") {
2165: print &mt('Unable to retrieve LON-CAPA source files from: [_1].',
2166: "http://install.loncapa.org/versions/$lctarball")."\n";
2167: } else {
2168: $have_tarball = 1;
2169: }
2170: print_and_log("\n");
2171: } else {
2172: $have_tarball = 1;
2173: print_and_log("
2174: ------------------------------------------------------------------------
2175:
2176: ".&mt('You seem to have a version of loncapa-current.tar.gz in [_1]',$instdir)."\n".
2177: &mt('This copy will be used and a new version will NOT be downloaded.')."\n".
2178: &mt('If you wish, you may download a new version by executing:')."
2179:
1.2 raeburn 2180: wget http://install.loncapa.org/versions/loncapa-current.tar.gz
1.1 raeburn 2181:
2182: ------------------------------------------------------------------------
2183: ");
2184: }
2185:
2186: ##
2187: ## untar loncapa.tar.gz
2188: ##
2189: if ($have_tarball) {
2190: print_and_log(&mt('Extracting LON-CAPA source files')."\n");
2191: writelog(`cd ~root; tar zxf $instdir/$lctarball`);
2192: print_and_log("\n");
2193: print &mt('LON-CAPA source files extracted.')."\n".
2194: &mt('It remains for you to execute the following commands:')."
2195:
2196: cd /root/loncapa-N.N (N.N should correspond to a version number like '0.4')
2197: ./UPDATE
2198:
2199: ".&mt('If you have any trouble, please see [_1] and [_2]',
2200: 'http://install.loncapa.org/','http://help.loncapa.org/')."\n";
2201: $updateshown = 1;
2202: }
2203: return ($have_tarball,$updateshown);
2204: }
2205:
2206: close LOG;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>