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